use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testCheckSourceRootExistence1.
/**
* Test the case when the source root is null.
*/
@Test
public void testCheckSourceRootExistence1() {
assertThrows(FileNotFoundException.class, () -> {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig cfg = PageConfig.get(req);
String path = RuntimeEnvironment.getInstance().getSourceRootPath();
System.out.println(path);
RuntimeEnvironment.getInstance().setSourceRoot(null);
try {
cfg.checkSourceRootExistence();
} finally {
RuntimeEnvironment.getInstance().setSourceRoot(path);
PageConfig.cleanup(req);
}
});
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testCheckSourceRootExistence4.
/**
* Test the case when source root can not be read.
* @throws IOException I/O exception
*/
@Test
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
public void testCheckSourceRootExistence4() throws IOException {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig cfg = PageConfig.get(req);
String path = RuntimeEnvironment.getInstance().getSourceRootPath();
File temp = File.createTempFile("opengrok", "-test-file.tmp");
Files.delete(temp.toPath());
Files.createDirectories(temp.toPath());
// skip the test if the implementation does not permit setting permissions
assumeTrue(temp.setReadable(false));
RuntimeEnvironment.getInstance().setSourceRoot(temp.getAbsolutePath());
assertThrows(IOException.class, () -> cfg.checkSourceRootExistence(), "This should throw an exception when the file is not readable");
RuntimeEnvironment.getInstance().setSourceRoot(path);
PageConfig.cleanup(req);
temp.deleteOnExit();
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testGetLatestRevisionNotValid.
@Test
public void testGetLatestRevisionNotValid() {
DummyHttpServletRequest req2 = new DummyHttpServletRequest() {
@Override
public String getPathInfo() {
return "/git/nonexistent_file";
}
};
PageConfig cfg = PageConfig.get(req2);
String rev = cfg.getLatestRevision();
assertNull(rev);
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testCheckSourceRootExistence3.
/**
* Test the case when source root does not exist.
* @throws IOException I/O exception
*/
@Test
public void testCheckSourceRootExistence3() throws IOException {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig cfg = PageConfig.get(req);
String path = RuntimeEnvironment.getInstance().getSourceRootPath();
File temp = File.createTempFile("opengrok", "-test-file.tmp");
Files.delete(temp.toPath());
RuntimeEnvironment.getInstance().setSourceRoot(temp.getAbsolutePath());
assertThrows(IOException.class, () -> cfg.checkSourceRootExistence(), "This should throw an exception when the file does not exist");
RuntimeEnvironment.getInstance().setSourceRoot(path);
PageConfig.cleanup(req);
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testGetRevisionLocation.
@Test
public void testGetRevisionLocation() {
DummyHttpServletRequest req1 = new DummyHttpServletRequest() {
@Override
public String getPathInfo() {
return "/git/main.c";
}
@Override
public String getContextPath() {
return "source";
}
@Override
public String getQueryString() {
return "a=true";
}
};
PageConfig cfg = PageConfig.get(req1);
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
assertNotNull(location);
assertEquals("source/xref/git/main.c?r=aa35c258&a=true", location);
}
Aggregations