23
23
package org .opengrok .indexer .history ;
24
24
25
25
import java .io .File ;
26
+ import java .io .IOException ;
26
27
import java .lang .reflect .InvocationTargetException ;
27
28
import org .junit .AfterClass ;
28
29
import static org .junit .Assert .assertFalse ;
30
+ import static org .junit .Assert .assertNull ;
31
+
29
32
import org .junit .BeforeClass ;
30
33
import org .junit .Test ;
34
+ import org .opengrok .indexer .condition .ConditionalRun ;
35
+ import org .opengrok .indexer .condition .RepositoryInstalled ;
36
+ import org .opengrok .indexer .configuration .RuntimeEnvironment ;
37
+ import org .opengrok .indexer .util .ForbiddenSymlinkException ;
31
38
import org .opengrok .indexer .util .TestRepository ;
32
39
33
40
/**
@@ -51,16 +58,31 @@ public static void tearDown() {
51
58
repository = null ;
52
59
}
53
60
}
54
-
61
+
62
+ @ ConditionalRun (RepositoryInstalled .MercurialInstalled .class )
63
+ @ Test
64
+ public void testRepositoryMatchingSourceRoot () throws IllegalAccessException , InvocationTargetException ,
65
+ ForbiddenSymlinkException , InstantiationException , NoSuchMethodException , IOException {
66
+
67
+ File root = new File (repository .getSourceRoot (), "mercurial" );
68
+ RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
69
+ env .setSourceRoot (root .getAbsolutePath ());
70
+ env .setProjectsEnabled (true );
71
+ assertNull (RepositoryFactory .getRepository (root ));
72
+ }
73
+
55
74
/*
56
- * There is no conditonal run based on whether given repository is installed because
75
+ * There is no conditional run based on whether given repository is installed because
57
76
* this test is not supposed to have working Mercurial anyway.
58
77
*/
59
- private void testNotWorkingRepository (String repoPath , String propName )
60
- throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException {
61
-
78
+ private void testNotWorkingRepository (String repoPath , String propName )
79
+ throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException ,
80
+ IOException , ForbiddenSymlinkException {
81
+
82
+ RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
62
83
String origPropValue = System .setProperty (propName , "/foo/bar/nonexistent" );
63
84
File root = new File (repository .getSourceRoot (), repoPath );
85
+ env .setSourceRoot (repository .getSourceRoot ());
64
86
Repository repo = RepositoryFactory .getRepository (root );
65
87
if (origPropValue != null ) {
66
88
System .setProperty (propName , origPropValue );
@@ -69,14 +91,16 @@ private void testNotWorkingRepository(String repoPath, String propName)
69
91
}
70
92
71
93
@ Test
72
- public void testNotWorkingMercurialRepository ()
73
- throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException {
94
+ public void testNotWorkingMercurialRepository ()
95
+ throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException ,
96
+ IOException , ForbiddenSymlinkException {
74
97
testNotWorkingRepository ("mercurial" , MercurialRepository .CMD_PROPERTY_KEY );
75
98
}
76
99
77
100
@ Test
78
- public void testNotWorkingBitkeeperRepository ()
79
- throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException {
101
+ public void testNotWorkingBitkeeperRepository ()
102
+ throws InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException ,
103
+ IOException , ForbiddenSymlinkException {
80
104
testNotWorkingRepository ("bitkeeper" , BitKeeperRepository .CMD_PROPERTY_KEY );
81
105
}
82
106
}
0 commit comments