1818 */
1919
2020/*
21- * Copyright (c) 2014, 2021 , Oracle and/or its affiliates. All rights reserved.
21+ * Copyright (c) 2014, 2022 , Oracle and/or its affiliates. All rights reserved.
2222 * Portions Copyright (c) 2017, 2019, Chris Fraire <cfraire@me.com>.
2323 */
2424package org .opengrok .indexer .index ;
4343import org .junit .jupiter .api .AfterEach ;
4444import org .junit .jupiter .api .BeforeEach ;
4545import org .junit .jupiter .api .Test ;
46+ import org .junit .jupiter .params .ParameterizedTest ;
47+ import org .junit .jupiter .params .provider .ValueSource ;
4648import org .opengrok .indexer .condition .EnabledForRepository ;
4749import org .opengrok .indexer .configuration .Project ;
4850import org .opengrok .indexer .configuration .RuntimeEnvironment ;
5759 * Test indexer w.r.t. repositories.
5860 * @author Vladimir Kotal
5961 */
60- public class IndexerRepoTest {
62+ class IndexerRepoTest {
6163
6264 private TestRepository repository ;
6365
@@ -73,25 +75,10 @@ public void tearDown() {
7375 repository .destroy ();
7476 }
7577
76- /**
77- * Test it is possible to disable history per project.
78- */
79- @ Test
8078 @ EnabledForRepository (MERCURIAL )
81- public void testPerProjectHistoryGlobalOn () throws IndexerException , IOException , HistoryException {
82- testPerProjectHistory (true );
83- }
84-
85- /**
86- * Test it is possible to enable history per project.
87- */
88- @ Test
89- @ EnabledForRepository (MERCURIAL )
90- public void testPerProjectHistoryGlobalOff () throws IndexerException , IOException , HistoryException {
91- testPerProjectHistory (false );
92- }
93-
94- private void testPerProjectHistory (boolean globalOn ) throws IndexerException , IOException , HistoryException {
79+ @ ParameterizedTest
80+ @ ValueSource (booleans = {false , true })
81+ void testPerProjectHistory (boolean globalOn ) throws IndexerException , IOException , HistoryException {
9582 RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
9683
9784 // Make sure we start from scratch.
@@ -100,19 +87,25 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
10087 env .setProjectsEnabled (true );
10188 env .setHistoryEnabled (globalOn );
10289
90+ // The projects have to be added first so that prepareIndexer() can use their configuration.
10391 Project proj = new Project ("mercurial" , "/mercurial" );
10492 proj .setHistoryEnabled (!globalOn );
10593 env .getProjects ().clear ();
10694 env .getProjects ().put ("mercurial" , proj );
95+ proj = new Project ("git" , "/git" );
96+ env .getProjects ().put ("git" , proj );
10797
98+ HistoryGuru .getInstance ().clear ();
10899 Indexer .getInstance ().prepareIndexer (
109100 env ,
110101 true , // search for repositories
111102 true , // scan and add projects
112103 false , // don't create dictionary
113104 null , // subFiles - not needed since we don't list files
114105 null ); // repositories - not needed when not refreshing history
106+ env .generateProjectRepositoriesMap ();
115107
108+ // The repositories of the git project should follow the global history setting.
116109 File repoRoot = new File (env .getSourceRootFile (), "git" );
117110 File fileInRepo = new File (repoRoot , "main.c" );
118111 assertTrue (fileInRepo .exists ());
@@ -122,6 +115,7 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
122115 assertNull (HistoryGuru .getInstance ().getHistory (fileInRepo ));
123116 }
124117
118+ // The repositories of the mercurial project should be opposite to the global history setting.
125119 repoRoot = new File (env .getSourceRootFile (), "mercurial" );
126120 fileInRepo = new File (repoRoot , "main.c" );
127121 assertTrue (fileInRepo .exists ());
@@ -140,7 +134,7 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
140134 */
141135 @ EnabledForRepository (MERCURIAL )
142136 @ Test
143- public void testSymlinks () throws IndexerException , IOException {
137+ void testSymlinks () throws IndexerException , IOException {
144138
145139 final String SYMLINK = "symlink" ;
146140 RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
0 commit comments