use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.
the class SearchHandlerTestCase method testInvalidYqlQuery.
@Test
public void testInvalidYqlQuery() throws Exception {
IOUtils.copyDirectory(new File(testDir, "config_yql"), new File(tempDir), 1);
generateComponentsConfigForActive();
configurer.reloadConfig();
SearchHandler newSearchHandler = fetchSearchHandler(configurer);
assertTrue("Have a new instance of the search handler", searchHandler != newSearchHandler);
try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(newSearchHandler)) {
RequestHandlerTestDriver.MockResponseHandler responseHandler = newDriver.sendRequest("http://localhost/search/?yql=select%20*%20from%20foo%20where%20bar%20%3E%201453501295%27%3B");
responseHandler.readAll();
assertThat(responseHandler.getStatus(), is(400));
}
}
use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.
the class SearchHandlerTestCase method testWorkingReconfiguration.
@Test
public synchronized void testWorkingReconfiguration() throws Exception {
assertJsonResult("http://localhost?query=abc", driver);
// reconfiguration
IOUtils.copyDirectory(new File(testDir, "handlers2"), new File(tempDir), 1);
generateComponentsConfigForActive();
configurer.reloadConfig();
// ...and check the resulting config
SearchHandler newSearchHandler = fetchSearchHandler(configurer);
assertTrue("Have a new instance of the search handler", searchHandler != newSearchHandler);
assertNotNull("Have the new search chain", fetchSearchHandler(configurer).getSearchChainRegistry().getChain("hello"));
assertNull("Don't have the new search chain", fetchSearchHandler(configurer).getSearchChainRegistry().getChain("classLoadingError"));
try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(searchHandler)) {
assertJsonResult("http://localhost?query=abc", newDriver);
}
}
use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.
the class SearchHandlerTestCase method testInvalidQueryParam.
private void testInvalidQueryParam(final RequestHandlerTestDriver testDriver) {
RequestHandlerTestDriver.MockResponseHandler responseHandler = testDriver.sendRequest("http://localhost/search/?query=status_code%3A0&hits=20&offset=-20");
String response = responseHandler.readAll();
assertThat(responseHandler.getStatus(), is(400));
assertThat(response, containsString("offset"));
assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.INVALID_QUERY_PARAMETER.code));
}
use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.
the class SearchHandlerTestCase method testFailedReconfiguration.
@Test
// TODO: Must be done at the ConfiguredApplication level, not handlers configurer? Also, this must be rewritten as the above
@Ignore
public synchronized void testFailedReconfiguration() throws Exception {
assertXmlResult(driver);
// attempt reconfiguration
IOUtils.copyDirectory(new File(testDir, "handlersInvalid"), new File(tempDir), 1);
generateComponentsConfigForActive();
configurer.reloadConfig();
SearchHandler newSearchHandler = fetchSearchHandler(configurer);
RequestHandler newMockHandler = configurer.getRequestHandlerRegistry().getComponent("com.yahoo.search.handler.test.MockHandler");
assertTrue("Reconfiguration failed: Kept the existing instance of the search handler", searchHandler == newSearchHandler);
assertNull("Reconfiguration failed: No mock handler", newMockHandler);
try (RequestHandlerTestDriver newDriver = new RequestHandlerTestDriver(searchHandler)) {
assertXmlResult(newDriver);
}
}
use of com.yahoo.container.jdisc.RequestHandlerTestDriver in project vespa by vespa-engine.
the class SearchHandlerTestCase method startUp.
@Before
public void startUp() throws IOException {
File cfgDir = tempfolder.newFolder("SearchHandlerTestCase");
tempDir = cfgDir.getAbsolutePath();
configId = "dir:" + tempDir;
// make configs active
IOUtils.copyDirectory(new File(testDir), cfgDir, 1);
generateComponentsConfigForActive();
configurer = new HandlersConfigurerTestWrapper(new Container(), configId);
searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
driver = new RequestHandlerTestDriver(searchHandler);
}
Aggregations