|
| 1 | +package reposense.model; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.Assertions; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +import reposense.model.reportconfig.ReportAuthorDetails; |
| 10 | +import reposense.model.reportconfig.ReportBranchData; |
| 11 | +import reposense.model.reportconfig.ReportConfiguration; |
| 12 | +import reposense.model.reportconfig.ReportGroupNameAndGlobs; |
| 13 | +import reposense.model.reportconfig.ReportRepoConfiguration; |
| 14 | +import reposense.parser.exceptions.InvalidLocationException; |
| 15 | + |
| 16 | +class OneStopConfigRunConfigurationTest { |
| 17 | + |
| 18 | + private static CliArguments testCliArguments; |
| 19 | + private static List<RepoConfiguration> expectedRepoConfigurations; |
| 20 | + |
| 21 | + public static void setUpTestCliArguments() { |
| 22 | + CliArguments.Builder testCliBuilder = new CliArguments.Builder(); |
| 23 | + |
| 24 | + List<String> globPatterns = List.of("**.java"); |
| 25 | + List<ReportGroupNameAndGlobs> groups = List.of(new ReportGroupNameAndGlobs("code", globPatterns)); |
| 26 | + |
| 27 | + List< String> emailList = List. of( "[email protected]"); |
| 28 | + ReportAuthorDetails author = new ReportAuthorDetails(emailList, "FH-30", |
| 29 | + "Francis Hodianto", "Francis Hodianto"); |
| 30 | + |
| 31 | + List<ReportAuthorDetails> authorList = List.of(author); |
| 32 | + List<String> ignoreGlobList = List.of("**.md"); |
| 33 | + List<String> ignoreAuthorList = List.of("bot"); |
| 34 | + ReportBranchData branch = new ReportBranchData("master", "My project", authorList, |
| 35 | + ignoreGlobList, ignoreAuthorList, 2000000L); |
| 36 | + |
| 37 | + List<ReportBranchData> branches = List.of(branch); |
| 38 | + ReportRepoConfiguration repo = new ReportRepoConfiguration("https://github.com/reposense/testrepo-Delta.git", |
| 39 | + groups, branches); |
| 40 | + |
| 41 | + List<ReportRepoConfiguration> repos = List.of(repo); |
| 42 | + ReportConfiguration expectedReportConfig = new ReportConfiguration("Test RepoSense Report", repos); |
| 43 | + testCliBuilder.reportConfiguration(expectedReportConfig); |
| 44 | + testCliArguments = testCliBuilder.build(); |
| 45 | + } |
| 46 | + |
| 47 | + public static void setUpExpectedRepoConfigurations() throws InvalidLocationException { |
| 48 | + expectedRepoConfigurations = new ArrayList<>(); |
| 49 | + RepoLocation expectedRepoLocation = new RepoLocation("https://github.com/reposense/testrepo-Delta.git"); |
| 50 | + List<AuthorConfiguration> authorConfigs = new ArrayList<>(); |
| 51 | + List<GroupConfiguration> groupConfigs = new ArrayList<>(); |
| 52 | + |
| 53 | + RepoConfiguration.Builder builder = new RepoConfiguration.Builder() |
| 54 | + .location(expectedRepoLocation) |
| 55 | + .branch("master") |
| 56 | + .ignoreGlobList(List.of("**.md")) |
| 57 | + .ignoredAuthorsList(List.of("bot")) |
| 58 | + .fileSizeLimit(2000000L) |
| 59 | + // Needs to be removed this when we deprecate the standalone config |
| 60 | + .isStandaloneConfigIgnored(true); |
| 61 | + |
| 62 | + expectedRepoConfigurations.add(builder.build()); |
| 63 | + |
| 64 | + GroupConfiguration groupConfiguration = new GroupConfiguration(expectedRepoLocation); |
| 65 | + groupConfiguration.addGroup(new FileType("code", List.of("**.java"))); |
| 66 | + |
| 67 | + groupConfigs.add(groupConfiguration); |
| 68 | + |
| 69 | + Author author = new Author("FH-30"); |
| 70 | + author. setEmails( List. of( "[email protected]")); |
| 71 | + author.setDisplayName("Francis Hodianto"); |
| 72 | + author.setAuthorAliases(List.of("Francis Hodianto")); |
| 73 | + |
| 74 | + AuthorConfiguration authorConfiguration = new AuthorConfiguration(expectedRepoLocation, "master"); |
| 75 | + authorConfiguration.addAuthor(author); |
| 76 | + authorConfigs.add(authorConfiguration); |
| 77 | + |
| 78 | + RepoConfiguration.merge(expectedRepoConfigurations, authorConfigs); |
| 79 | + RepoConfiguration.setGroupConfigsToRepos(expectedRepoConfigurations, groupConfigs); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void getRepoConfigurations_withValidInputs_returnsRepoConfigurations() throws InvalidLocationException { |
| 84 | + setUpTestCliArguments(); |
| 85 | + setUpExpectedRepoConfigurations(); |
| 86 | + |
| 87 | + OneStopConfigRunConfiguration config = new OneStopConfigRunConfiguration(testCliArguments); |
| 88 | + List<RepoConfiguration> actualRepoConfigurations = config.getRepoConfigurations(); |
| 89 | + Assertions.assertEquals(expectedRepoConfigurations, actualRepoConfigurations); |
| 90 | + } |
| 91 | +} |
0 commit comments