Application implements AutoCloseable { @Beta public static Application fromBuilder(Builder builder) throws Exception { return builder.build(); } Application(Path path, Networking networking, boolean deletePathWhenClosing); @Beta static Application fromBuilder(Builder builder); static Application fromServicesXml(String xml, Networking networking); static Application fromApplicationPackage(Path path, Networking networking); static Application fromApplicationPackage(File file, Networking networking); JDisc getJDisc(String id); @Override void close(); static final String vespaLocalProperty; }
@Test public void empty_container() throws Exception { try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container())))) { try { app.process(new DocumentRemove(null)); fail("expected exception"); } catch (Exception ignore) { } try { app.process(new Processing()); fail("expected exception"); } catch (Exception ignore) { } try { app.search(new Query("?foo")); fail("expected exception"); } catch (Exception ignore) { } } }
@Test public void config() throws Exception { try ( ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .documentProcessor("docproc", "default", MockDocproc.class) .config(new MockApplicationConfig(new MockApplicationConfig.Builder() .mystruct(new MockApplicationConfig.Mystruct.Builder().id("structid").value("structvalue")) .mystructlist(new MockApplicationConfig.Mystructlist.Builder().id("listid1").value("listvalue1")) .mystructlist(new MockApplicationConfig.Mystructlist.Builder().id("listid2").value("listvalue2")) .mylist("item1") .mylist("item2") .mymap("key1", "value1") .mymap("key2", "value2") .mymapstruct("key1", new MockApplicationConfig.Mymapstruct.Builder().id("mapid1").value("mapvalue1")) .mymapstruct("key2", new MockApplicationConfig.Mymapstruct.Builder().id("mapid2").value("mapvalue2"))))))) ) { MockDocproc docproc = (MockDocproc) app.getComponentById("docproc@default"); assertNotNull(docproc); assertEquals(docproc.getConfig().mystruct().id(), "structid"); assertEquals(docproc.getConfig().mystruct().value(), "structvalue"); assertEquals(docproc.getConfig().mystructlist().size(), 2); assertEquals(docproc.getConfig().mystructlist().get(0).id(), "listid1"); assertEquals(docproc.getConfig().mystructlist().get(0).value(), "listvalue1"); assertEquals(docproc.getConfig().mystructlist().get(1).id(), "listid2"); assertEquals(docproc.getConfig().mystructlist().get(1).value(), "listvalue2"); assertEquals(docproc.getConfig().mylist().size(), 2); assertEquals(docproc.getConfig().mylist().get(0), "item1"); assertEquals(docproc.getConfig().mylist().get(1), "item2"); assertEquals(docproc.getConfig().mymap().size(), 2); assertTrue(docproc.getConfig().mymap().containsKey("key1")); assertEquals(docproc.getConfig().mymap().get("key1"), "value1"); assertTrue(docproc.getConfig().mymap().containsKey("key2")); assertEquals(docproc.getConfig().mymap().get("key2"), "value2"); assertEquals(docproc.getConfig().mymapstruct().size(), 2); assertTrue(docproc.getConfig().mymapstruct().containsKey("key1")); assertEquals(docproc.getConfig().mymapstruct().get("key1").id(), "mapid1"); assertEquals(docproc.getConfig().mymapstruct().get("key1").value(), "mapvalue1"); assertTrue(docproc.getConfig().mymapstruct().containsKey("key2")); assertEquals(docproc.getConfig().mymapstruct().get("key2").id(), "mapid2"); assertEquals(docproc.getConfig().mymapstruct().get("key2").value(), "mapvalue2"); } }
@Test public void handler() throws Exception { try ( ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .handler("http: ) { RequestHandler handler = app.getRequestHandlerById(MockHttpHandler.class.getName()); assertNotNull(handler); Request request = new Request("http: Response response = app.handleRequest(request); assertNotNull(response); assertEquals(response.getStatus(), 200); assertEquals(response.getBodyAsString(), "OK"); request = new Request("http: response = app.handleRequest(request); assertNotNull(response); assertEquals(response.getStatus(), 200); assertEquals(response.getBodyAsString(), "OK"); request = new Request("http: response = app.handleRequest(request); assertNotNull(response); assertEquals(response.getStatus(), 200); assertEquals(response.getBodyAsString(), "OK"); } }
@Test public void renderer() throws Exception { try ( ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .renderer("mock", MockRenderer.class)))) ) { Request request = new Request("http: Response response = app.handleRequest(request); assertNotNull(response); assertEquals(response.getStatus(), 200); assertEquals(response.getBodyAsString(), "<mock hits=\"0\" />"); } }
@Test public void search_default() throws Exception { try ( ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .searcher(MockSearcher.class)))) ) { Result result = app.search(new Query("?query=foo&timeout=20000")); assertEquals(1, result.hits().size()); } }
@Test public void search() throws Exception { try ( ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .searcher("foo", MockSearcher.class)))) ) { Result result = app.search("foo", new Query("?query=foo&timeout=20000")); assertEquals(1, result.hits().size()); } }
@Test public void get_search_handler() throws Exception { try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().search(true))))) { SearchHandler searchHandler = (SearchHandler) app.getRequestHandlerById("com.yahoo.search.handler.SearchHandler"); assertNotNull(searchHandler); } }
@Test public void component() throws Exception { try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .component(MockSearcher.class))))) { Component c = app.getComponentById(MockSearcher.class.getName()); assertNotNull(c); } }
@Test public void component_with_config() throws Exception { MockApplicationConfig config = new MockApplicationConfig(new MockApplicationConfig.Builder().mystruct(new MockApplicationConfig.Mystruct.Builder().id("foo").value("bar"))); try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .component("foo", MockDocproc.class, config))))) { Component c = app.getComponentById("foo"); assertNotNull(c); } }
@Test public void server() throws Exception { try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .server("foo", MockServer.class))) )) { MockServer server = (MockServer) app.getServerById("foo"); assertNotNull(server); assertTrue(server.isStarted()); } }
@Test public void query_profile() throws Exception { try (Application app = Application.fromBuilder(new Application.Builder() .queryProfile("default", "<query-profile id=\"default\">\n" + "<field name=\"defaultage\">7d</field>\n" + "</query-profile>") .queryProfileType("type", "<query-profile-type id=\"type\">\n" + "<field name=\"defaultage\" type=\"string\" />\n" + "</query-profile-type>") .rankExpression("re", "commonfirstphase(globalstaticrank)") .documentType("test", new String(this.getClass().getResourceAsStream("/test.sd").readAllBytes(), StandardCharsets.UTF_8)) .container("default", new Application.Builder.Container() .search(true) ))) { Application unused = app; } }