use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class UserWhiteListPluginTest method shouldAllowWhitelistedUserForAnyProject.
@ParameterizedTest
@MethodSource("parameters")
public void shouldAllowWhitelistedUserForAnyProject(String param) {
init(param);
plugin.load(validPluginParameters);
DummyHttpServletRequest req = new DummyHttpServletRequest();
User user;
if (param.equals(UserWhiteListPlugin.USERNAME_FIELD)) {
user = new User(OK_USER);
} else {
user = new User("blurb", OK_ID);
}
req.setAttribute(UserPlugin.REQUEST_ATTR, user);
Project randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
boolean projectAllowed = plugin.isAllowed(req, randomProject);
assertTrue(projectAllowed, "should allow OK entity for random project 1");
randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
projectAllowed = plugin.isAllowed(req, randomProject);
assertTrue(projectAllowed, "should allow OK entity for random project 2");
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testRequestAttributes.
@Test
public void testRequestAttributes() {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig cfg = PageConfig.get(req);
String[] attrs = { "a", "b", "c", "d" };
Object[] values = { "some object", new DummyHttpServletRequest(), 1, this };
assertEquals(attrs.length, values.length);
for (int i = 0; i < attrs.length; i++) {
cfg.setRequestAttribute(attrs[i], values[i]);
Object attribute = req.getAttribute(attrs[i]);
assertNotNull(attribute);
assertEquals(values[i], attribute);
attribute = cfg.getRequestAttribute(attrs[i]);
assertNotNull(attribute);
assertEquals(values[i], attribute);
}
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testCheckSourceRootExistence2.
/**
* Test the case when source root is empty.
*/
@Test
public void testCheckSourceRootExistence2() {
assertThrows(FileNotFoundException.class, () -> {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig cfg = PageConfig.get(req);
String path = RuntimeEnvironment.getInstance().getSourceRootPath();
RuntimeEnvironment.getInstance().setSourceRoot("");
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 testGetRevisionLocationNullQuery.
@Test
public void testGetRevisionLocationNullQuery() {
DummyHttpServletRequest req1 = new DummyHttpServletRequest() {
@Override
public String getPathInfo() {
return "/git/main.c";
}
@Override
public String getContextPath() {
return "source";
}
@Override
public String getQueryString() {
return null;
}
};
PageConfig cfg = PageConfig.get(req1);
String location = cfg.getRevisionLocation(cfg.getLatestRevision());
assertNotNull(location);
assertEquals("source/xref/git/main.c?r=aa35c258", location);
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testGetAnnotation.
@Test
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(revisions.length - i, annotation.getFileVersion(revisions[i]), "The version should be reflected through the revision");
PageConfig.cleanup(req);
}
}
Aggregations