|
31 | 31 | import java.net.URISyntaxException;
|
32 | 32 | import java.net.URL;
|
33 | 33 | import java.nio.charset.StandardCharsets;
|
| 34 | +import java.nio.file.Files; |
| 35 | +import java.nio.file.Path; |
34 | 36 | import java.util.List;
|
35 | 37 | import java.util.Locale;
|
36 | 38 | import java.util.Map;
|
|
44 | 46 | import org.junit.jupiter.api.Test;
|
45 | 47 | import org.junit.jupiter.api.condition.EnabledOnOs;
|
46 | 48 | import org.junit.jupiter.api.condition.OS;
|
| 49 | +import org.opengrok.indexer.condition.EnabledForRepository; |
| 50 | +import org.opengrok.indexer.configuration.Project; |
| 51 | +import org.opengrok.indexer.configuration.RuntimeEnvironment; |
| 52 | +import org.opengrok.indexer.history.HistoryGuru; |
| 53 | +import org.opengrok.indexer.index.Indexer; |
| 54 | +import org.opengrok.indexer.util.TestRepository; |
47 | 55 |
|
48 | 56 | import static org.hamcrest.MatcherAssert.assertThat;
|
49 | 57 | import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
|
52 | 60 | import static org.junit.jupiter.api.Assertions.assertNull;
|
53 | 61 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
54 | 62 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
| 63 | +import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL; |
55 | 64 |
|
56 | 65 | /**
|
57 | 66 | * Test of the methods in <code>org.opengrok.indexer.web.Util</code>.
|
@@ -632,4 +641,58 @@ void testWriteHADNonexistentFile() throws Exception {
|
632 | 641 | assertEquals("<td class=\"q\"><a href=\"/source/download/nonexistent/file.c\" title=\"Download\">D</a></td>",
|
633 | 642 | output);
|
634 | 643 | }
|
| 644 | + |
| 645 | + /** |
| 646 | + * Test {@link Util#writeHAD(Writer, String, String)} for a file paths that correspond to a repository |
| 647 | + * with history enabled and disabled. |
| 648 | + * @throws Exception on error |
| 649 | + */ |
| 650 | + @EnabledForRepository(MERCURIAL) |
| 651 | + @Test |
| 652 | + void testWriteHAD() throws Exception { |
| 653 | + TestRepository repository = new TestRepository(); |
| 654 | + repository.create(UtilTest.class.getResource("/repositories")); |
| 655 | + |
| 656 | + RuntimeEnvironment env = RuntimeEnvironment.getInstance(); |
| 657 | + |
| 658 | + env.setSourceRoot(repository.getSourceRoot()); |
| 659 | + env.setDataRoot(repository.getDataRoot()); |
| 660 | + env.setProjectsEnabled(true); |
| 661 | + env.setHistoryEnabled(true); |
| 662 | + |
| 663 | + // The projects have to be added first so that prepareIndexer() can use their configuration. |
| 664 | + Project proj = new Project("mercurial", "/mercurial"); |
| 665 | + proj.setHistoryEnabled(false); |
| 666 | + env.getProjects().clear(); |
| 667 | + env.getProjects().put("mercurial", proj); |
| 668 | + proj = new Project("git", "/git"); |
| 669 | + env.getProjects().put("git", proj); |
| 670 | + |
| 671 | + HistoryGuru.getInstance().clear(); |
| 672 | + Indexer.getInstance().prepareIndexer( |
| 673 | + env, |
| 674 | + true, // search for repositories |
| 675 | + true, // scan and add projects |
| 676 | + false, // don't create dictionary |
| 677 | + null, // subFiles - not needed since we don't list files |
| 678 | + null); // repositories - not needed when not refreshing history |
| 679 | + env.generateProjectRepositoriesMap(); |
| 680 | + |
| 681 | + StringWriter writer = new StringWriter(); |
| 682 | + String filePath = "/git/main.c"; |
| 683 | + Util.writeHAD(writer, "/source", filePath); |
| 684 | + String output = writer.toString(); |
| 685 | + assertEquals("<td class=\"q\"><a href=\"/source/history/git/main.c\" title=\"History\">H</a> " + |
| 686 | + "<a href=\"/source/xref/git/main.c?a=true\" title=\"Annotate\">A</a> " + |
| 687 | + "<a href=\"/source/download/git/main.c\" title=\"Download\">D</a></td>", |
| 688 | + output); |
| 689 | + |
| 690 | + writer = new StringWriter(); |
| 691 | + filePath = "/mercurial/main.c"; |
| 692 | + Util.writeHAD(writer, "/source", filePath); |
| 693 | + output = writer.toString(); |
| 694 | + assertEquals("<td class=\"q\"> <a href=\"/source/xref/mercurial/main.c?a=true\" title=\"Annotate\">A</a> " + |
| 695 | + "<a href=\"/source/download/mercurial/main.c\" title=\"Download\">D</a></td>", |
| 696 | + output); |
| 697 | + } |
635 | 698 | }
|
0 commit comments