|
23 | 23 | */
|
24 | 24 | package org.opengrok.indexer.configuration;
|
25 | 25 |
|
| 26 | +import static org.junit.Assert.assertEquals; |
| 27 | +import static org.junit.Assert.assertFalse; |
| 28 | +import static org.junit.Assert.assertNotNull; |
| 29 | +import static org.junit.Assert.assertNull; |
| 30 | +import static org.junit.Assert.assertSame; |
| 31 | +import static org.junit.Assert.assertTrue; |
| 32 | +import static org.junit.Assert.fail; |
| 33 | +import static org.opengrok.indexer.util.StatisticsUtils.loadStatistics; |
| 34 | +import static org.opengrok.indexer.util.StatisticsUtils.saveStatistics; |
| 35 | + |
26 | 36 | import java.io.ByteArrayOutputStream;
|
27 | 37 | import java.io.File;
|
28 | 38 | import java.io.IOException;
|
|
37 | 47 | import java.util.List;
|
38 | 48 | import java.util.Map;
|
39 | 49 | import java.util.TreeMap;
|
40 |
| - |
| 50 | +import java.util.TreeSet; |
41 | 51 | import org.apache.tools.ant.filters.StringInputStream;
|
42 | 52 | import org.json.simple.parser.ParseException;
|
43 | 53 | import org.junit.AfterClass;
|
|
50 | 60 | import org.opengrok.indexer.authorization.AuthorizationPlugin;
|
51 | 61 | import org.opengrok.indexer.authorization.AuthorizationStack;
|
52 | 62 | import org.opengrok.indexer.history.RepositoryInfo;
|
53 |
| -import org.opengrok.indexer.web.Statistics; |
54 |
| - |
55 |
| -import static org.junit.Assert.assertEquals; |
56 |
| -import static org.junit.Assert.assertFalse; |
57 |
| -import static org.junit.Assert.assertNotNull; |
58 |
| -import static org.junit.Assert.assertNull; |
59 |
| -import static org.junit.Assert.assertSame; |
60 |
| -import static org.junit.Assert.assertTrue; |
61 |
| -import static org.junit.Assert.fail; |
62 |
| -import static org.opengrok.indexer.util.StatisticsUtils.loadStatistics; |
63 |
| -import static org.opengrok.indexer.util.StatisticsUtils.saveStatistics; |
64 |
| - |
65 | 63 | import org.opengrok.indexer.util.ForbiddenSymlinkException;
|
66 | 64 | import org.opengrok.indexer.util.IOUtils;
|
| 65 | +import org.opengrok.indexer.web.Statistics; |
67 | 66 |
|
68 | 67 | /**
|
69 | 68 | * Test the RuntimeEnvironment class
|
@@ -1057,4 +1056,61 @@ public void testGetPathRelativeToSourceRoot() throws IOException,
|
1057 | 1056 | IOUtils.removeRecursive(sourceRoot.toPath());
|
1058 | 1057 | IOUtils.removeRecursive(realDir);
|
1059 | 1058 | }
|
| 1059 | + |
| 1060 | + @Test |
| 1061 | + public void testPopulateGroupsMultipleTimes() { |
| 1062 | + // create a structure with two repositories |
| 1063 | + final RuntimeEnvironment env = RuntimeEnvironment.getInstance(); |
| 1064 | + Project project1 = new Project("bar", "/bar"); |
| 1065 | + env.getProjects().put(project1.getName(), project1); |
| 1066 | + Project project2 = new Project("barfoo", "/barfoo"); |
| 1067 | + env.getProjects().put(project2.getName(), project2); |
| 1068 | + final Group group1 = new Group("group1", "bar"); |
| 1069 | + env.getGroups().add(group1); |
| 1070 | + final Group group2 = new Group("group2", "bar.*"); |
| 1071 | + env.getGroups().add(group2); |
| 1072 | + |
| 1073 | + final RepositoryInfo repository1 = new RepositoryInfo(); |
| 1074 | + repository1.setDirectoryNameRelative("/bar"); |
| 1075 | + env.getRepositories().add(repository1); |
| 1076 | + final RepositoryInfo repo2 = new RepositoryInfo(); |
| 1077 | + repository1.setDirectoryNameRelative("/barfoo"); |
| 1078 | + env.getRepositories().add(repo2); |
| 1079 | + env.getProjectRepositoriesMap().put(project1, Arrays.asList(repository1)); |
| 1080 | + env.getProjectRepositoriesMap().put(project2, Arrays.asList(repo2)); |
| 1081 | + |
| 1082 | + Assert.assertEquals(2, env.getProjects().size()); |
| 1083 | + Assert.assertEquals(2, env.getRepositories().size()); |
| 1084 | + Assert.assertEquals(2, env.getProjectRepositoriesMap().size()); |
| 1085 | + Assert.assertEquals(2, env.getGroups().size()); |
| 1086 | + |
| 1087 | + // populate groups for the first time |
| 1088 | + env.populateGroups(env.getGroups(), new TreeSet<>(env.getProjects().values())); |
| 1089 | + |
| 1090 | + Assert.assertEquals(2, env.getProjects().size()); |
| 1091 | + Assert.assertEquals(2, env.getRepositories().size()); |
| 1092 | + Assert.assertEquals(2, env.getProjectRepositoriesMap().size()); |
| 1093 | + Assert.assertEquals(2, env.getGroups().size()); |
| 1094 | + |
| 1095 | + Assert.assertEquals(0, group1.getProjects().size()); |
| 1096 | + Assert.assertEquals(1, group1.getRepositories().size()); |
| 1097 | + Assert.assertEquals(0, group2.getProjects().size()); |
| 1098 | + Assert.assertEquals(2, group2.getRepositories().size()); |
| 1099 | + |
| 1100 | + // remove a single repository object => project1 will become a simple project |
| 1101 | + env.getProjectRepositoriesMap().remove(project1); |
| 1102 | + env.getRepositories().remove(repository1); |
| 1103 | + |
| 1104 | + // populate groups for the second time |
| 1105 | + env.populateGroups(env.getGroups(), new TreeSet<>(env.getProjects().values())); |
| 1106 | + |
| 1107 | + Assert.assertEquals(2, env.getProjects().size()); |
| 1108 | + Assert.assertEquals(1, env.getRepositories().size()); |
| 1109 | + Assert.assertEquals(1, env.getProjectRepositoriesMap().size()); |
| 1110 | + Assert.assertEquals(2, env.getGroups().size()); |
| 1111 | + Assert.assertEquals(1, group1.getProjects().size()); |
| 1112 | + Assert.assertEquals(0, group1.getRepositories().size()); |
| 1113 | + Assert.assertEquals(1, group2.getProjects().size()); |
| 1114 | + Assert.assertEquals(1, group2.getRepositories().size()); |
| 1115 | + } |
1060 | 1116 | }
|
0 commit comments