25
25
import org .junit .jupiter .api .AfterEach ;
26
26
import org .junit .jupiter .api .BeforeEach ;
27
27
import org .junit .jupiter .api .Test ;
28
+ import org .opengrok .indexer .condition .EnabledForRepository ;
29
+ import org .opengrok .indexer .condition .RepositoryInstalled ;
30
+ import org .opengrok .indexer .util .IOUtils ;
31
+ import org .opengrok .indexer .util .TestRepository ;
28
32
33
+ import java .io .File ;
34
+ import java .io .IOException ;
35
+ import java .io .InputStream ;
36
+ import java .net .URISyntaxException ;
29
37
import java .util .Map ;
30
38
31
39
import static org .junit .jupiter .api .Assertions .assertEquals ;
32
40
import static org .junit .jupiter .api .Assertions .assertNotNull ;
33
41
import static org .junit .jupiter .api .Assertions .assertTrue ;
42
+ import static org .opengrok .indexer .history .CVSRepositoryTest .runCvsCommand ;
34
43
35
44
/**
36
- *
45
+ * Test {@code cvs log} output parsing in {@link CVSHistoryParser}.
37
46
* @author austvik
38
47
*/
39
48
class CVSHistoryParserTest {
40
49
41
50
CVSHistoryParser instance ;
42
51
52
+ private TestRepository repository ;
53
+
54
+ /**
55
+ * Set up a test repository. Should be called by the tests that need it. The
56
+ * test repository will be destroyed automatically when the test finishes.
57
+ */
58
+ private File setUpTestRepository () throws IOException , URISyntaxException {
59
+ repository = new TestRepository ();
60
+ repository .create (getClass ().getResource ("/repositories" ));
61
+
62
+ // Checkout cvsrepo anew in order to get the CVS/Root files point to
63
+ // the temporary directory rather than the OpenGrok workspace directory
64
+ // it was created from. This is necessary for the 'cvs log' command to work correctly.
65
+ File root = new File (repository .getSourceRoot (), "cvs_test" );
66
+ File cvsrepodir = new File (root , "cvsrepo" );
67
+ IOUtils .removeRecursive (cvsrepodir .toPath ());
68
+ File cvsroot = new File (root , "cvsroot" );
69
+ runCvsCommand (root , "-d" , cvsroot .getAbsolutePath (), "checkout" , "cvsrepo" );
70
+ return cvsrepodir ;
71
+ }
72
+
43
73
@ BeforeEach
44
74
public void setUp () {
45
75
instance = new CVSHistoryParser ();
@@ -48,6 +78,11 @@ public void setUp() {
48
78
@ AfterEach
49
79
public void tearDown () {
50
80
instance = null ;
81
+
82
+ if (repository != null ) {
83
+ repository .destroy ();
84
+ repository = null ;
85
+ }
51
86
}
52
87
53
88
/**
@@ -126,4 +161,21 @@ void parseALaW3C() throws Exception {
126
161
127
162
assertEquals (Map .of (revId2 , tag1 ), result .getTags ());
128
163
}
164
+
165
+ /**
166
+ * Check that history can be retrieved for a directory. This is needed for the web application to operate
167
+ * correctly. Specifically, this tests the state transitions in {@link CVSHistoryParser#processStream(InputStream)}.
168
+ */
169
+ @ EnabledForRepository (RepositoryInstalled .Type .CVS )
170
+ @ Test
171
+ void testHistoryForDirectory () throws Exception {
172
+ File repoRoot = setUpTestRepository ();
173
+ assertTrue (repoRoot .exists ());
174
+ CVSRepository repository = (CVSRepository ) RepositoryFactory .getRepository (repoRoot );
175
+ assertNotNull (repository );
176
+ History history = repository .getHistory (repoRoot );
177
+ assertNotNull (history );
178
+ assertNotNull (history .getHistoryEntries ());
179
+ assertEquals (3 , history .getHistoryEntries ().size ());
180
+ }
129
181
}
0 commit comments