Search in sources :

Example 11 with ConditionalRun

use of org.opensolaris.opengrok.condition.ConditionalRun in project OpenGrok by OpenGrok.

the class HistoryContextTest method testGetContext_4args.

@Test
@ConditionalRun(condition = RepositoryInstalled.MercurialInstalled.class)
public void testGetContext_4args() throws Exception {
    String path = "/mercurial/Makefile";
    File file = new File(repositories.getSourceRoot() + path);
    String parent = file.getParent();
    String base = file.getName();
    // Construct a query equivalent to hist:dummy
    TermQuery q1 = new TermQuery(new Term("hist", "dummy"));
    StringWriter sw = new StringWriter();
    assertTrue(new HistoryContext(q1).getContext(parent, base, path, sw, null));
    assertTrue(sw.toString().contains("Created a small <b>dummy</b> program"));
    // Construct a query equivalent to hist:"dummy program"
    PhraseQuery.Builder q2 = new PhraseQuery.Builder();
    q2.add(new Term("hist", "dummy"));
    q2.add(new Term("hist", "program"));
    sw = new StringWriter();
    assertTrue(new HistoryContext(q2.build()).getContext(parent, base, path, sw, null));
    assertTrue(sw.toString().contains("Created a small <b>dummy program</b>"));
    // Search for a term that doesn't exist
    TermQuery q3 = new TermQuery(new Term("hist", "term_does_not_exist"));
    sw = new StringWriter();
    assertFalse(new HistoryContext(q3).getContext(parent, base, path, sw, null));
    assertEquals("", sw.toString());
    // Search for term with multiple hits - hist:small OR hist:target
    BooleanQuery.Builder q4 = new BooleanQuery.Builder();
    q4.add(new TermQuery(new Term("hist", "small")), Occur.SHOULD);
    q4.add(new TermQuery(new Term("hist", "target")), Occur.SHOULD);
    sw = new StringWriter();
    assertTrue(new HistoryContext(q4.build()).getContext(parent, base, path, sw, null));
    String result = sw.toString();
    assertTrue(result.contains("Add lint make <b>target</b> and fix lint warnings"));
    assertTrue(result.contains("Created a <b>small</b> dummy program"));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) StringWriter(java.io.StringWriter) PhraseQuery(org.apache.lucene.search.PhraseQuery) Term(org.apache.lucene.index.Term) File(java.io.File) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Test(org.junit.Test)

Example 12 with ConditionalRun

use of org.opensolaris.opengrok.condition.ConditionalRun in project OpenGrok by OpenGrok.

the class PageConfigTest method testGetAnnotation.

@Test
@ConditionalRun(condition = RepositoryInstalled.GitInstalled.class)
public void testGetAnnotation() {
    final String[] revisions = { "aa35c258", "bb74b7e8" };
    for (int i = 0; i < revisions.length; i++) {
        final int index = i;
        HttpServletRequest req = new DummyHttpServletRequest() {

            @Override
            public String getContextPath() {
                return "/source";
            }

            @Override
            public String getServletPath() {
                return "/history";
            }

            @Override
            public String getPathInfo() {
                return "/git/main.c";
            }

            @Override
            public String getParameter(String name) {
                switch(name) {
                    case "r":
                        return revisions[index];
                    case "a":
                        return "true";
                }
                return null;
            }
        };
        PageConfig cfg = PageConfig.get(req);
        Annotation annotation = cfg.getAnnotation();
        assertNotNull(annotation);
        assertEquals("main.c", annotation.getFilename());
        assertEquals(revisions.length - i, annotation.getFileVersionsCount());
        for (int j = 1; j <= annotation.size(); j++) {
            String tmp = annotation.getRevision(j);
            assertTrue(Arrays.asList(revisions).contains(tmp));
        }
        assertEquals("The version should be reflected through the revision", revisions.length - i, annotation.getFileVersion(revisions[i]));
        PageConfig.cleanup(req);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Annotation(org.opensolaris.opengrok.history.Annotation) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 ConditionalRun (org.opensolaris.opengrok.condition.ConditionalRun)12 File (java.io.File)9 TestRepository (org.opensolaris.opengrok.util.TestRepository)6 Date (java.util.Date)3 LinkedList (java.util.LinkedList)3 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)3 ArrayList (java.util.ArrayList)2 Term (org.apache.lucene.index.Term)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 MercurialRepositoryTest (org.opensolaris.opengrok.history.MercurialRepositoryTest)2 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 StringWriter (java.io.StringWriter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Project (org.opensolaris.opengrok.configuration.Project)1 Annotation (org.opensolaris.opengrok.history.Annotation)1 HistoryGuru (org.opensolaris.opengrok.history.HistoryGuru)1