diff --git a/docs/ug/configFiles.md b/docs/ug/configFiles.md index 790fe2da65..8c949af50c 100644 --- a/docs/ug/configFiles.md +++ b/docs/ug/configFiles.md @@ -93,10 +93,20 @@ e.g.: `example.java` in `example-repo` can either be in the `test` group or the ## `report-config.json` -You can optionally use `report-config.json` to customize report generation by providing the following information. ([example](report-config.csv)) +You can optionally use `report-config.json` to customize report generation by providing the following information. ([example](report-config.json)) **Fields to provide**: * `title`: Title of the generated report, which is also the title of the deployed dashboard. Default: "RepoSense Report" +* `sinceDate`: The first day of the period to be analyzed, in the format `DD/MM/YYYY`. Default: One month before the current date. +* `untilDate`: The last day of the period to be analyzed, in the format `DD/MM/YYYY`. Default: Current date. +* `period`: The period of the analysis window, in the format `nd` (for `n` days) or `nw` (for `n` weeks). It is used to calculate end date if only start date is specified, or calculate end date if only start date is specified. + + + +* `sinceDate`, `untilDate` and `period` cannot be declared together and will be ignored if all 3 configuration settings are present in the report configuration. +* CLI arguments takes precedence over the values provided in this report configuration. If the same configuration is set as a CLI argument as well as in the report configuration, the value in the report configuration is ignored. +* Likewise, if there is a conflict, such as `sinceDate`, `untilDate` and `period` being declared together even though some of them were declared in the report configuration, only the CLI arguments will be taken and the report configuration will be completely ignored. + diff --git a/docs/ug/report-config.json b/docs/ug/report-config.json index 8165c98ac4..321aeaee2f 100644 --- a/docs/ug/report-config.json +++ b/docs/ug/report-config.json @@ -1,3 +1,6 @@ { - "title": "CS2103 RepoSense Report" + "title": "CS2103 RepoSense Report", + "sinceDate": "23/01/2021", + "untilDate": "23/03/2021", + "period": "30d" } diff --git a/src/main/java/reposense/model/ReportConfiguration.java b/src/main/java/reposense/model/ReportConfiguration.java index c9dd25d9d9..6b5ee2ab35 100644 --- a/src/main/java/reposense/model/ReportConfiguration.java +++ b/src/main/java/reposense/model/ReportConfiguration.java @@ -1,17 +1,85 @@ package reposense.model; +import java.util.Date; +import java.util.Optional; +import java.util.logging.Logger; + +import reposense.parser.ParseException; +import reposense.parser.PeriodArgumentType; +import reposense.parser.SinceDateArgumentType; +import reposense.system.LogsManager; +import reposense.util.TimeUtil; + /** * Represents configuration information from JSON config file for generated report. */ public class ReportConfiguration { + private static final Logger logger = LogsManager.getLogger(ReportConfiguration.class); private static final String DEFAULT_TITLE = "RepoSense Report"; + private static final String MESSAGE_INVALID_DATE_PROVIDED = "Invalid date provided in report config: %s."; + private static final String MESSAGE_IGNORING_REPORT_CONFIG = "Ignoring the report config provided."; private String title; + private String sinceDate; + private String untilDate; + private String period; public String getTitle() { - if (title == null) { + if (this.title == null) { return DEFAULT_TITLE; } - return title; + return this.title; + } + + public Optional getSinceDate() { + if (SinceDateArgumentType.FIRST_COMMIT_DATE_SHORTHAND.equals(this.sinceDate)) { + return Optional.of(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE); + } + + return this.getDate(this.sinceDate, "00:00:00"); + } + + public Optional getUntilDate() { + return this.getDate(this.untilDate, "23:59:59"); + } + + public Optional getPeriod() { + if (this.period == null) { + return Optional.empty(); + } + + try { + return PeriodArgumentType.parse(this.period); + } catch (ParseException pe) { + logger.warning(pe.getMessage() + " " + MESSAGE_IGNORING_REPORT_CONFIG); + return Optional.empty(); + } + } + + /** + * This function resets the values of the {@code sinceDate}, {@code untilDate} and {@code period} to null, such that + * RepoSense ignores the configuration provided in the report config provided. + */ + public void ignoreSinceUntilDateAndPeriod() { + this.sinceDate = null; + this.untilDate = null; + this.period = null; + } + + /** + * This function parses the given {@code date} String into a Date object. + */ + private Optional getDate(String date, String time) { + if (date == null) { + return Optional.empty(); + } + + try { + String value = TimeUtil.extractDate(date); + return Optional.of(TimeUtil.parseDate(value + " " + time)); + } catch (java.text.ParseException pe) { + logger.warning(String.format(MESSAGE_INVALID_DATE_PROVIDED, date) + " " + MESSAGE_IGNORING_REPORT_CONFIG); + return Optional.empty(); + } } } diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index db6f97c12d..23afc51f4c 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -66,10 +66,6 @@ public class ArgsParser { private static final String PROGRAM_DESCRIPTION = "RepoSense is a contribution analysis tool for Git repositories."; private static final String MESSAGE_HEADER_MUTEX = "mutual exclusive arguments"; - private static final String MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE = - "\"Since Date\" cannot be later than \"Until Date\"."; - private static final String MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE = - "\"Since Date\" must not be later than today's date."; private static final String MESSAGE_HAVE_SINCE_DATE_UNTIL_DATE_AND_PERIOD = "\"Since Date\", \"Until Date\", and \"Period\" cannot be applied together."; private static final String MESSAGE_USING_DEFAULT_CONFIG_PATH = @@ -243,6 +239,9 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars Namespace results = parser.parseArgs(args); Date sinceDate; Date untilDate; + Optional tempSinceDate = Optional.empty(); + Optional tempUntilDate = Optional.empty(); + Optional tempPeriod = Optional.empty(); Path configFolderPath = results.get(CONFIG_FLAGS[0]); Path reportFolderPath = results.get(VIEW_FLAGS[0]); @@ -274,30 +273,67 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars } } - boolean isSinceDateProvided = cliSinceDate.isPresent(); - boolean isUntilDateProvided = cliUntilDate.isPresent(); - boolean isPeriodProvided = cliPeriod.isPresent(); - if (isSinceDateProvided && isUntilDateProvided && isPeriodProvided) { + // CLI arguments are treated with the highest priority and will throw an Exception if a conflict occurs + if (cliSinceDate.isPresent() && cliUntilDate.isPresent() && cliPeriod.isPresent()) { throw new ParseException(MESSAGE_HAVE_SINCE_DATE_UNTIL_DATE_AND_PERIOD); } int numCloningThreads = results.get(CLONING_THREADS_FLAG[0]); int numAnalysisThreads = results.get(ANALYSIS_THREADS_FLAG[0]); + boolean isSinceDateProvided = cliSinceDate.isPresent() || reportConfig.getSinceDate().isPresent(); + boolean isUntilDateProvided = cliUntilDate.isPresent() || reportConfig.getUntilDate().isPresent(); + boolean isPeriodProvided = cliPeriod.isPresent() || reportConfig.getPeriod().isPresent(); + + // Report config is treated with less priority and will be ignored if there is a conflict + if (isSinceDateProvided && isUntilDateProvided && isPeriodProvided) { + logger.warning(MESSAGE_IGNORING_REPORT_SINCE_DATE_UNTIL_DATE_AND_PERIOD); + reportConfig.ignoreSinceUntilDateAndPeriod(); + isSinceDateProvided = cliSinceDate.isPresent(); + isUntilDateProvided = cliUntilDate.isPresent(); + isPeriodProvided = cliPeriod.isPresent(); + } + if (cliSinceDate.isPresent() && reportConfig.getSinceDate().isPresent()) { + logger.warning(MESSAGE_IGNORING_REPORT_CONFIG_SINCE_DATE); + } + if (cliUntilDate.isPresent() && reportConfig.getUntilDate().isPresent()) { + logger.warning(MESSAGE_IGNORING_REPORT_CONFIG_UNTIL_DATE); + } + if (cliPeriod.isPresent() && reportConfig.getPeriod().isPresent()) { + logger.warning(MESSAGE_IGNORING_REPORT_CONFIG_PERIOD); + } + + // Set the values to those provided by the CLI arguments first, otherwise take from report config + if (cliPeriod.isPresent()) { + tempPeriod = cliPeriod; + } else if (reportConfig.getPeriod().isPresent()) { + tempPeriod = reportConfig.getPeriod(); + } + if (cliSinceDate.isPresent()) { + tempSinceDate = cliSinceDate; + } else if (reportConfig.getSinceDate().isPresent()) { + tempSinceDate = reportConfig.getSinceDate(); + } + if (cliUntilDate.isPresent()) { + tempUntilDate = cliUntilDate; + } else if (reportConfig.getUntilDate().isPresent()) { + tempUntilDate = reportConfig.getUntilDate(); + } + Date currentDate = TimeUtil.getCurrentDate(zoneId); if (isSinceDateProvided) { - sinceDate = TimeUtil.getZonedSinceDate(cliSinceDate.get(), zoneId); + sinceDate = TimeUtil.getZonedSinceDate(tempSinceDate.get(), zoneId); } else { sinceDate = isPeriodProvided - ? TimeUtil.getDateMinusNDays(cliUntilDate, zoneId, cliPeriod.get()) - : TimeUtil.getDateMinusAMonth(cliUntilDate, zoneId); + ? TimeUtil.getDateMinusNDays(tempUntilDate, zoneId, tempPeriod.get()) + : TimeUtil.getDateMinusAMonth(tempUntilDate, zoneId); } if (isUntilDateProvided) { - untilDate = TimeUtil.getZonedUntilDate(cliUntilDate.get(), zoneId); + untilDate = TimeUtil.getZonedUntilDate(tempUntilDate.get(), zoneId); } else { untilDate = (isSinceDateProvided && isPeriodProvided) - ? TimeUtil.getDatePlusNDays(cliSinceDate, zoneId, cliPeriod.get()) + ? TimeUtil.getDatePlusNDays(tempSinceDate, zoneId, tempPeriod.get()) : currentDate; } diff --git a/src/test/java/reposense/parser/ArgsParserTest.java b/src/test/java/reposense/parser/ArgsParserTest.java index 509d2878e0..76c5d8ed5c 100644 --- a/src/test/java/reposense/parser/ArgsParserTest.java +++ b/src/test/java/reposense/parser/ArgsParserTest.java @@ -49,6 +49,13 @@ public class ArgsParserTest { CONFIG_FOLDER_ABSOLUTE.resolve(AuthorConfigCsvParser.AUTHOR_CONFIG_FILENAME); private static final String NONEXISTENT_DIRECTORY = "some_non_existent_dir/"; + private static final Path REPORT_CONFIG_FOLDER_ABSOLUTE_ONE = loadResource(ArgsParserTest.class, + "report_config_test/one"); + private static final Path REPORT_CONFIG_FOLDER_ABSOLUTE_TWO = loadResource(ArgsParserTest.class, + "report_config_test/two"); + private static final Path REPORT_CONFIG_FOLDER_ABSOLUTE_THREE = loadResource(ArgsParserTest.class, + "report_config_test/three"); + private static final InputBuilder DEFAULT_INPUT_BUILDER = new InputBuilder(); private static final String TEST_REPO_REPOSENSE = "https://github.com/reposense/RepoSense.git"; @@ -740,6 +747,160 @@ public void parse_withDatesAndTimezone_success() throws Exception { Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); } + @Test + public void parse_reportConfigFolderOnly_success() throws Exception { + String input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_ONE) + .addTimezone(DEFAULT_TIMEZONE) + .build(); + CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); + Date expectedSinceDate = TestUtil.getSinceDate(2019, Calendar.MAY, 20); + Date expectedUntilDate = TestUtil.getUntilDate(2020, Calendar.NOVEMBER, 20); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_TWO) + .addTimezone(DEFAULT_TIMEZONE) + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2019, Calendar.MAY, 20); + expectedUntilDate = TestUtil.getUntilDate(2019, Calendar.JUNE, 9); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_THREE) + .addTimezone(DEFAULT_TIMEZONE) + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2020, Calendar.OCTOBER, 20); + expectedUntilDate = TestUtil.getUntilDate(2020, Calendar.NOVEMBER, 20); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + } + + @Test + public void parse_reportConfigAndCliNonConflict_success() throws Exception { + String input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_TWO) + .addTimezone(DEFAULT_TIMEZONE) + .addPeriod("5d") + .build(); + CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); + Date expectedSinceDate = TestUtil.getSinceDate(2019, Calendar.MAY, 20); + Date expectedUntilDate = TestUtil.getUntilDate(2019, Calendar.MAY, 24); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_THREE) + .addTimezone(DEFAULT_TIMEZONE) + .addSinceDate("30/07/2018") + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2018, Calendar.JULY, 30); + expectedUntilDate = TestUtil.getUntilDate(2020, Calendar.NOVEMBER, 20); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + } + + @Test + public void parse_reportConfigAndCliConflict_ignoreReportConfig() throws Exception { + String input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_ONE) + .addTimezone(DEFAULT_TIMEZONE) + .addSinceDate("16/06/2018") + .build(); + CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); + Date expectedSinceDate = TestUtil.getSinceDate(2018, Calendar.JUNE, 16); + Date expectedUntilDate = TestUtil.getUntilDate(2020, Calendar.NOVEMBER, 20); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_TWO) + .addTimezone(DEFAULT_TIMEZONE) + .addPeriod("2w") + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2019, Calendar.MAY, 20); + expectedUntilDate = TestUtil.getUntilDate(2019, Calendar.JUNE, 2); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_THREE) + .addTimezone(DEFAULT_TIMEZONE) + .addSinceDate("08/05/2018") + .addUntilDate("07/08/2018") + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2018, Calendar.MAY, 8); + expectedUntilDate = TestUtil.getUntilDate(2018, Calendar.AUGUST, 7); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + } + + @Test + public void parse_reportConfigAndCliHaveSinceUntilDateAndPeriod_ignoreReportConfig() throws Exception { + String input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_ONE) + .addTimezone(DEFAULT_TIMEZONE) + .addPeriod("2w") + .addUntilDate("12/01/2019") + .build(); + CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); + Date expectedSinceDate = TestUtil.getSinceDate(2018, Calendar.DECEMBER, 30); + Date expectedUntilDate = TestUtil.getUntilDate(2019, Calendar.JANUARY, 12); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_TWO) + .addTimezone(DEFAULT_TIMEZONE) + .addUntilDate("23/04/2019") + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2019, Calendar.MARCH, 23); + expectedUntilDate = TestUtil.getUntilDate(2019, Calendar.APRIL, 23); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + + input = new InputBuilder() + .addConfig(REPORT_CONFIG_FOLDER_ABSOLUTE_THREE) + .addTimezone(DEFAULT_TIMEZONE) + .addPeriod("5d") + .addUntilDate("16/02/2019") + .build(); + cliArguments = ArgsParser.parse(translateCommandline(input)); + expectedSinceDate = TestUtil.getSinceDate(2019, Calendar.FEBRUARY, 12); + expectedUntilDate = TestUtil.getUntilDate(2019, Calendar.FEBRUARY, 16); + + Assert.assertTrue(cliArguments instanceof ConfigCliArguments); + Assert.assertEquals(expectedSinceDate, cliArguments.getSinceDate()); + Assert.assertEquals(expectedUntilDate, cliArguments.getUntilDate()); + } + @Test public void parse_shallowCloning_success() throws Exception { String input = new InputBuilder().addConfig(CONFIG_FOLDER_ABSOLUTE) diff --git a/src/test/java/reposense/parser/ReportConfigJsonParserTest.java b/src/test/java/reposense/parser/ReportConfigJsonParserTest.java index 4394d5bc88..4a57c69d7c 100644 --- a/src/test/java/reposense/parser/ReportConfigJsonParserTest.java +++ b/src/test/java/reposense/parser/ReportConfigJsonParserTest.java @@ -3,36 +3,112 @@ import static reposense.util.TestUtil.loadResource; import java.nio.file.Path; +import java.util.Calendar; +import java.util.Date; +import java.util.Optional; import org.junit.Assert; import org.junit.Test; import reposense.model.ReportConfiguration; +import reposense.util.TestUtil; public class ReportConfigJsonParserTest { - private static final Path VALID_REPORT_CONFIG = loadResource( - ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-valid.json"); + private static final Path VALID_TITLE_REPORT_CONFIG = loadResource( + ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-validTitle.json"); private static final Path INVALID_REPORT_CONFIG = loadResource( ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-invalid.json"); private static final Path EMPTY_REPORT_CONFIG = loadResource( ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-empty.json"); + private static final Path VALID_SINCE_DATE_REPORT_CONFIG = loadResource( + ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-sinceDate.json"); + private static final Path VALID_UNTIL_DATE_REPORT_CONFIG = loadResource( + ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-untilDate.json"); + private static final Path VALID_PERIOD_DAYS_REPORT_CONFIG = loadResource( + ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-periodDays.json"); + private static final Path VALID_PERIOD_WEEKS_REPORT_CONFIG = loadResource( + ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-periodWeeks.json"); + private static final Path VALID_FIRST_COMMIT_DATE_REPORT_CONFIG = loadResource( + ReportConfigJsonParserTest.class, "ReportConfigJsonParserTest/report-config-firstCommit.json"); private static final String DEFAULT_TITLE = "RepoSense Report"; @Test public void reportConfig_parseEmptyJsonFile_getDefaultTitle() throws Exception { ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(EMPTY_REPORT_CONFIG); Assert.assertEquals(reportConfig.getTitle(), DEFAULT_TITLE); + Assert.assertEquals(reportConfig.getSinceDate(), Optional.empty()); + Assert.assertEquals(reportConfig.getUntilDate(), Optional.empty()); + Assert.assertEquals(reportConfig.getPeriod(), Optional.empty()); } @Test public void reportConfig_parseInvalidJsonFile_getDefaultTitle() throws Exception { ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(INVALID_REPORT_CONFIG); Assert.assertEquals(reportConfig.getTitle(), DEFAULT_TITLE); + Assert.assertEquals(reportConfig.getSinceDate(), Optional.empty()); + Assert.assertEquals(reportConfig.getUntilDate(), Optional.empty()); + Assert.assertEquals(reportConfig.getPeriod(), Optional.empty()); } @Test - public void reportConfig_parseValidJsonFile_getCustomTitle() throws Exception { - ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_REPORT_CONFIG); + public void reportConfig_parseValidTitleJsonFile_getCustomTitle() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_TITLE_REPORT_CONFIG); Assert.assertNotEquals(reportConfig.getTitle(), DEFAULT_TITLE); } + + @Test + public void reportConfig_parseValidSinceDateJsonFile_getCustomStartDate() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_SINCE_DATE_REPORT_CONFIG); + Optional expectedDate = Optional.of(TestUtil.getLocalSinceDate(2019, Calendar.MAY, 20)); + Assert.assertEquals(expectedDate, reportConfig.getSinceDate()); + } + + @Test + public void reportConfig_parseValidUntilDateJsonFile_getCustomEndDate() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_UNTIL_DATE_REPORT_CONFIG); + Optional expectedDate = Optional.of(TestUtil.getLocalUntilDate(2020, Calendar.JULY, 9)); + Assert.assertEquals(expectedDate, reportConfig.getUntilDate()); + } + + @Test + public void reportConfig_parseValidPeriodDaysJsonFile_getCustomPeriod() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_PERIOD_DAYS_REPORT_CONFIG); + Optional expectedPeriod = Optional.of(15); + Assert.assertEquals(expectedPeriod, reportConfig.getPeriod()); + } + + @Test + public void reportConfig_parseValidPeriodWeeksJsonFile_getCustomPeriod() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_PERIOD_WEEKS_REPORT_CONFIG); + Optional expectedPeriod = Optional.of(3 * 7); + Assert.assertEquals(expectedPeriod, reportConfig.getPeriod()); + } + + @Test + public void reportConfig_parseFirstCommitDateJsonFile_getFirstCommitDate() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_FIRST_COMMIT_DATE_REPORT_CONFIG); + Optional expectedDate = Optional.of(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE); + Assert.assertEquals(expectedDate, reportConfig.getSinceDate()); + } + + @Test + public void reportConfig_ignoreSinceDate_success() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_SINCE_DATE_REPORT_CONFIG); + reportConfig.ignoreSinceUntilDateAndPeriod(); + Assert.assertEquals(Optional.empty(), reportConfig.getSinceDate()); + } + + @Test + public void reportConfig_ignoreUntilDate_success() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_UNTIL_DATE_REPORT_CONFIG); + reportConfig.ignoreSinceUntilDateAndPeriod(); + Assert.assertEquals(Optional.empty(), reportConfig.getUntilDate()); + } + + @Test + public void reportConfig_ignorePeriod_success() throws Exception { + ReportConfiguration reportConfig = new ReportConfigJsonParser().parse(VALID_PERIOD_DAYS_REPORT_CONFIG); + reportConfig.ignoreSinceUntilDateAndPeriod(); + Assert.assertEquals(Optional.empty(), reportConfig.getPeriod()); + } } diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-firstCommit.json b/src/test/resources/ReportConfigJsonParserTest/report-config-firstCommit.json new file mode 100644 index 0000000000..b9d06a49d6 --- /dev/null +++ b/src/test/resources/ReportConfigJsonParserTest/report-config-firstCommit.json @@ -0,0 +1,3 @@ +{ + "sinceDate": "d1" +} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json b/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json index fd26202fa2..1674af5ea9 100644 --- a/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json +++ b/src/test/resources/ReportConfigJsonParserTest/report-config-invalid.json @@ -1,3 +1,5 @@ { - "ti": "!@#$%^&*()<>:" + "ti": "!@#$%^&*()<>:", + "start": "32/82/3281", + "end": "32/81/3282" } diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-periodDays.json b/src/test/resources/ReportConfigJsonParserTest/report-config-periodDays.json new file mode 100644 index 0000000000..148d046b04 --- /dev/null +++ b/src/test/resources/ReportConfigJsonParserTest/report-config-periodDays.json @@ -0,0 +1,3 @@ +{ + "period": "15d" +} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-periodWeeks.json b/src/test/resources/ReportConfigJsonParserTest/report-config-periodWeeks.json new file mode 100644 index 0000000000..e16e0d37be --- /dev/null +++ b/src/test/resources/ReportConfigJsonParserTest/report-config-periodWeeks.json @@ -0,0 +1,3 @@ +{ + "period": "3w" +} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-sinceDate.json b/src/test/resources/ReportConfigJsonParserTest/report-config-sinceDate.json new file mode 100644 index 0000000000..692e79b433 --- /dev/null +++ b/src/test/resources/ReportConfigJsonParserTest/report-config-sinceDate.json @@ -0,0 +1,3 @@ +{ + "sinceDate": "20/05/2019" +} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-untilDate.json b/src/test/resources/ReportConfigJsonParserTest/report-config-untilDate.json new file mode 100644 index 0000000000..e7510e13f7 --- /dev/null +++ b/src/test/resources/ReportConfigJsonParserTest/report-config-untilDate.json @@ -0,0 +1,3 @@ +{ + "untilDate": "09/07/2020" +} diff --git a/src/test/resources/ReportConfigJsonParserTest/report-config-valid.json b/src/test/resources/ReportConfigJsonParserTest/report-config-validTitle.json similarity index 100% rename from src/test/resources/ReportConfigJsonParserTest/report-config-valid.json rename to src/test/resources/ReportConfigJsonParserTest/report-config-validTitle.json diff --git a/src/test/resources/report_config_test/one/repo-config.csv b/src/test/resources/report_config_test/one/repo-config.csv new file mode 100644 index 0000000000..23dcd597f8 --- /dev/null +++ b/src/test/resources/report_config_test/one/repo-config.csv @@ -0,0 +1,4 @@ +Repository's Location,Branch,File formats,Ignore Glob List,Ignore standalone config,Ignore Commits List,Ignore Authors List +https://github.com/reposense/testrepo-Beta.git,,,,,, +https://github.com/reposense/testrepo-Charlie.git,,,,,, +https://github.com/reposense/testrepo-Delta.git,,,,,, diff --git a/src/test/resources/report_config_test/one/report-config.json b/src/test/resources/report_config_test/one/report-config.json new file mode 100644 index 0000000000..bb62ffbfab --- /dev/null +++ b/src/test/resources/report_config_test/one/report-config.json @@ -0,0 +1,4 @@ +{ + "sinceDate": "20/05/2019", + "untilDate": "20/11/2020" +} diff --git a/src/test/resources/report_config_test/three/repo-config.csv b/src/test/resources/report_config_test/three/repo-config.csv new file mode 100644 index 0000000000..23dcd597f8 --- /dev/null +++ b/src/test/resources/report_config_test/three/repo-config.csv @@ -0,0 +1,4 @@ +Repository's Location,Branch,File formats,Ignore Glob List,Ignore standalone config,Ignore Commits List,Ignore Authors List +https://github.com/reposense/testrepo-Beta.git,,,,,, +https://github.com/reposense/testrepo-Charlie.git,,,,,, +https://github.com/reposense/testrepo-Delta.git,,,,,, diff --git a/src/test/resources/report_config_test/three/report-config.json b/src/test/resources/report_config_test/three/report-config.json new file mode 100644 index 0000000000..9124beeee0 --- /dev/null +++ b/src/test/resources/report_config_test/three/report-config.json @@ -0,0 +1,3 @@ +{ + "untilDate": "20/11/2020" +} diff --git a/src/test/resources/report_config_test/two/repo-config.csv b/src/test/resources/report_config_test/two/repo-config.csv new file mode 100644 index 0000000000..23dcd597f8 --- /dev/null +++ b/src/test/resources/report_config_test/two/repo-config.csv @@ -0,0 +1,4 @@ +Repository's Location,Branch,File formats,Ignore Glob List,Ignore standalone config,Ignore Commits List,Ignore Authors List +https://github.com/reposense/testrepo-Beta.git,,,,,, +https://github.com/reposense/testrepo-Charlie.git,,,,,, +https://github.com/reposense/testrepo-Delta.git,,,,,, diff --git a/src/test/resources/report_config_test/two/report-config.json b/src/test/resources/report_config_test/two/report-config.json new file mode 100644 index 0000000000..d19d2508ea --- /dev/null +++ b/src/test/resources/report_config_test/two/report-config.json @@ -0,0 +1,4 @@ +{ + "sinceDate": "20/05/2019", + "period": "3w" +}