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"));
}
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);
}
}
Aggregations