Skip to content

Commit 0535f17

Browse files
committed
add basic test for parsing history log of a directory
1 parent 86a371d commit 0535f17

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/history/CVSHistoryParserTest.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,51 @@
2525
import org.junit.jupiter.api.AfterEach;
2626
import org.junit.jupiter.api.BeforeEach;
2727
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;
2832

33+
import java.io.File;
34+
import java.io.IOException;
35+
import java.io.InputStream;
36+
import java.net.URISyntaxException;
2937
import java.util.Map;
3038

3139
import static org.junit.jupiter.api.Assertions.assertEquals;
3240
import static org.junit.jupiter.api.Assertions.assertNotNull;
3341
import static org.junit.jupiter.api.Assertions.assertTrue;
42+
import static org.opengrok.indexer.history.CVSRepositoryTest.runCvsCommand;
3443

3544
/**
36-
*
45+
* Test {@code cvs log} output parsing in {@link CVSHistoryParser}.
3746
* @author austvik
3847
*/
3948
class CVSHistoryParserTest {
4049

4150
CVSHistoryParser instance;
4251

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+
4373
@BeforeEach
4474
public void setUp() {
4575
instance = new CVSHistoryParser();
@@ -48,6 +78,11 @@ public void setUp() {
4878
@AfterEach
4979
public void tearDown() {
5080
instance = null;
81+
82+
if (repository != null) {
83+
repository.destroy();
84+
repository = null;
85+
}
5186
}
5287

5388
/**
@@ -126,4 +161,21 @@ void parseALaW3C() throws Exception {
126161

127162
assertEquals(Map.of(revId2, tag1), result.getTags());
128163
}
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+
}
129181
}

0 commit comments

Comments
 (0)