18
18
*/
19
19
20
20
/*
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.
22
22
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opengrok .indexer .index ;
43
43
import org .junit .jupiter .api .AfterEach ;
44
44
import org .junit .jupiter .api .BeforeEach ;
45
45
import org .junit .jupiter .api .Test ;
46
+ import org .junit .jupiter .params .ParameterizedTest ;
47
+ import org .junit .jupiter .params .provider .ValueSource ;
46
48
import org .opengrok .indexer .condition .EnabledForRepository ;
47
49
import org .opengrok .indexer .configuration .Project ;
48
50
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
57
59
* Test indexer w.r.t. repositories.
58
60
* @author Vladimir Kotal
59
61
*/
60
- public class IndexerRepoTest {
62
+ class IndexerRepoTest {
61
63
62
64
private TestRepository repository ;
63
65
@@ -73,25 +75,10 @@ public void tearDown() {
73
75
repository .destroy ();
74
76
}
75
77
76
- /**
77
- * Test it is possible to disable history per project.
78
- */
79
- @ Test
80
78
@ 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 {
95
82
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
96
83
97
84
// Make sure we start from scratch.
@@ -100,19 +87,25 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
100
87
env .setProjectsEnabled (true );
101
88
env .setHistoryEnabled (globalOn );
102
89
90
+ // The projects have to be added first so that prepareIndexer() can use their configuration.
103
91
Project proj = new Project ("mercurial" , "/mercurial" );
104
92
proj .setHistoryEnabled (!globalOn );
105
93
env .getProjects ().clear ();
106
94
env .getProjects ().put ("mercurial" , proj );
95
+ proj = new Project ("git" , "/git" );
96
+ env .getProjects ().put ("git" , proj );
107
97
98
+ HistoryGuru .getInstance ().clear ();
108
99
Indexer .getInstance ().prepareIndexer (
109
100
env ,
110
101
true , // search for repositories
111
102
true , // scan and add projects
112
103
false , // don't create dictionary
113
104
null , // subFiles - not needed since we don't list files
114
105
null ); // repositories - not needed when not refreshing history
106
+ env .generateProjectRepositoriesMap ();
115
107
108
+ // The repositories of the git project should follow the global history setting.
116
109
File repoRoot = new File (env .getSourceRootFile (), "git" );
117
110
File fileInRepo = new File (repoRoot , "main.c" );
118
111
assertTrue (fileInRepo .exists ());
@@ -122,6 +115,7 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
122
115
assertNull (HistoryGuru .getInstance ().getHistory (fileInRepo ));
123
116
}
124
117
118
+ // The repositories of the mercurial project should be opposite to the global history setting.
125
119
repoRoot = new File (env .getSourceRootFile (), "mercurial" );
126
120
fileInRepo = new File (repoRoot , "main.c" );
127
121
assertTrue (fileInRepo .exists ());
@@ -140,7 +134,7 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
140
134
*/
141
135
@ EnabledForRepository (MERCURIAL )
142
136
@ Test
143
- public void testSymlinks () throws IndexerException , IOException {
137
+ void testSymlinks () throws IndexerException , IOException {
144
138
145
139
final String SYMLINK = "symlink" ;
146
140
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
0 commit comments