use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class ConfigurationControllerTest method testConfigValueSetVsThread.
@Test
void testConfigValueSetVsThread() throws InterruptedException {
int origValue = env.getHitsPerPage();
final int[] threadValue = new int[1];
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(1);
Thread thread = new Thread(() -> {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig pageConfig = PageConfig.get(req);
RuntimeEnvironment e = pageConfig.getEnv();
startLatch.countDown();
// Wait for hint of termination, save the value and exit.
try {
endLatch.await();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
threadValue[0] = e.getHitsPerPage();
});
thread.start();
startLatch.await();
// Set brand-new configuration.
int newValue = origValue + 42;
Configuration config = new Configuration();
config.setHitsPerPage(newValue);
String configStr = config.getXMLRepresentationAsString();
Response response = target("configuration").request().put(Entity.xml(configStr));
waitForTask(response);
// Unblock the thread.
endLatch.countDown();
thread.join();
// Check thread's view of the variable.
assertEquals(newValue, threadValue[0]);
// Revert the value back to the default.
env.setHitsPerPage(origValue);
}
use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.
the class PageConfigTest method testGetIntParam.
@Test
public void testGetIntParam() {
String[] attrs = { "a", "b", "c", "d", "e", "f", "g", "h" };
int[] values = { 1, 100, -1, 2, 200, 3000, -200, 3000 };
DummyHttpServletRequest req = new DummyHttpServletRequest() {
@Override
public String getParameter(String name) {
switch(name) {
case "a":
return "1";
case "b":
return "100";
case "c":
return null;
case "d":
return "2";
case "e":
return "200";
case "f":
return "3000";
case "g":
return null;
case "h":
return "abcdef";
}
return null;
}
};
PageConfig cfg = PageConfig.get(req);
assertEquals(attrs.length, values.length);
for (int i = 0; i < attrs.length; i++) {
assertEquals(values[i], cfg.getIntParam(attrs[i], values[i]));
}
}
Aggregations