diff options
Diffstat (limited to 'application/src/test/java/com/yahoo/application/ApplicationTest.java')
-rw-r--r-- | application/src/test/java/com/yahoo/application/ApplicationTest.java | 99 |
1 files changed, 51 insertions, 48 deletions
diff --git a/application/src/test/java/com/yahoo/application/ApplicationTest.java b/application/src/test/java/com/yahoo/application/ApplicationTest.java index 1b542b4ac98..5b4a68756f0 100644 --- a/application/src/test/java/com/yahoo/application/ApplicationTest.java +++ b/application/src/test/java/com/yahoo/application/ApplicationTest.java @@ -21,7 +21,7 @@ import com.yahoo.search.handler.SearchHandler; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.File; @@ -33,10 +33,11 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import static com.yahoo.vespa.defaults.Defaults.getDefaults; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author bratseth @@ -45,28 +46,28 @@ import static org.junit.Assert.fail; public class ApplicationTest { @Test - public void minimal_application_can_be_constructed() { + void minimal_application_can_be_constructed() { try (Application application = Application.fromServicesXml("<container version=\"1.0\"/>", Networking.disable)) { - Application unused = application; + Application unused = application; } } /** Tests that an application with search chains referencing a content cluster can be constructed. */ @Test - public void container_and_referenced_content() { + void container_and_referenced_content() { try (Application application = - Application.fromApplicationPackage(new File("src/test/app-packages/withcontent"), Networking.disable)) { + Application.fromApplicationPackage(new File("src/test/app-packages/withcontent"), Networking.disable)) { Result result = application.getJDisc("default").search().process(new ComponentSpecification("default"), - new Query("?query=substring:foobar&timeout=20000")); + new Query("?query=substring:foobar&timeout=20000")); assertEquals("WEAKAND(100) (AND substring:fo substring:oo substring:ob substring:ba substring:ar)", - result.hits().get("hasQuery").getQuery().getModel().getQueryTree().toString()); + result.hits().get("hasQuery").getQuery().getModel().getQueryTree().toString()); } } @Test - public void application_with_query_profile_sets_up_query_profile_registry() { + void application_with_query_profile_sets_up_query_profile_registry() { try (Application application = - Application.fromApplicationPackage(new File("src/test/app-packages/withqueryprofile"), Networking.disable)) { + Application.fromApplicationPackage(new File("src/test/app-packages/withqueryprofile"), Networking.disable)) { Query query = new Query(HttpRequest.createTestRequest("?query=substring:foobar&timeout=20000", com.yahoo.jdisc.http.HttpRequest.Method.GET), application.getCompiledQueryProfileRegistry().findQueryProfile("default")); Result result = application.getJDisc("default").search().process(new ComponentSpecification("default"), query); @@ -82,7 +83,7 @@ public class ApplicationTest { } @Test - public void empty_container() throws Exception { + 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)); @@ -108,7 +109,7 @@ public class ApplicationTest { } @Test - public void config() throws Exception { + 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) @@ -122,7 +123,7 @@ public class ApplicationTest { .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); @@ -162,11 +163,11 @@ public class ApplicationTest { } @Test - public void handler() throws Exception { + void handler() throws Exception { try ( ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .handler("http://*/", MockHttpHandler.class)))) - ) { + ) { RequestHandler handler = app.getRequestHandlerById(MockHttpHandler.class.getName()); assertNotNull(handler); @@ -191,13 +192,13 @@ public class ApplicationTest { } } - @Test // TODO: Creates access log - public void renderer() throws Exception { + @Test + 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://localhost:" + getDefaults().vespaWebServicePort() + "/search/?format=mock"); Response response = app.handleRequest(request); @@ -208,36 +209,36 @@ public class ApplicationTest { } @Test - public void search_default() throws Exception { + 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 { + 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 document_type() throws Exception { + void document_type() throws Exception { try ( Application app = Application.fromBuilder(new Application.Builder() .documentType("test", new String(this.getClass().getResourceAsStream("/test.sd").readAllBytes(), StandardCharsets.UTF_8)) .container("default", new Application.Builder.Container() - .documentProcessor(MockDocproc.class) - .config(new MockApplicationConfig(new MockApplicationConfig.Builder().mystruct(new MockApplicationConfig.Mystruct.Builder().id("foo").value("bar")))))) - ) { + .documentProcessor(MockDocproc.class) + .config(new MockApplicationConfig(new MockApplicationConfig.Builder().mystruct(new MockApplicationConfig.Mystruct.Builder().id("foo").value("bar")))))) + ) { Map<String, DocumentType> typeMap = app.getJDisc("jdisc").documentProcessing().getDocumentTypes(); assertNotNull(typeMap); assertTrue(typeMap.containsKey("test")); @@ -245,7 +246,7 @@ public class ApplicationTest { } @Test - public void get_search_handler() throws Exception { + 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); @@ -253,7 +254,7 @@ public class ApplicationTest { } @Test - public void component() throws Exception { + 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()); @@ -262,7 +263,7 @@ public class ApplicationTest { } @Test - public void component_with_config() throws Exception { + 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))))) { @@ -272,7 +273,7 @@ public class ApplicationTest { } @Test - public void file_distribution() { + void file_distribution() { try (Application application = Application.fromApplicationPackage(new File("src/test/app-packages/filedistribution/"), Networking.disable)) { // Deployment succeeded Application unused = application; @@ -280,7 +281,7 @@ public class ApplicationTest { } @Test - public void server() throws Exception { + void server() throws Exception { try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container() .server("foo", MockServer.class))) )) { @@ -291,7 +292,7 @@ public class ApplicationTest { } @Test - public void query_profile() throws Exception { + 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" + @@ -302,25 +303,27 @@ public class ApplicationTest { .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) + .search(true) ))) { Application unused = app; } } - @Test(expected = ConnectException.class) - public void http_interface_is_off_when_networking_is_disabled() throws Exception { - int httpPort = getFreePort(); - try (Application application = Application.fromServicesXml(servicesXmlWithServer(httpPort), Networking.disable)) { - HttpClient client = new org.apache.http.impl.client.DefaultHttpClient(); - int statusCode = client.execute(new HttpGet("http://localhost:" + httpPort)).getStatusLine().getStatusCode(); - fail("Networking.disable is specified, but the network interface is enabled! Got status code: " + statusCode); - Application unused = application; - } + @Test + void http_interface_is_off_when_networking_is_disabled() throws Exception { + assertThrows(ConnectException.class, () -> { + int httpPort = getFreePort(); + try (Application application = Application.fromServicesXml(servicesXmlWithServer(httpPort), Networking.disable)) { + HttpClient client = new org.apache.http.impl.client.DefaultHttpClient(); + int statusCode = client.execute(new HttpGet("http://localhost:" + httpPort)).getStatusLine().getStatusCode(); + fail("Networking.disable is specified, but the network interface is enabled! Got status code: " + statusCode); + Application unused = application; + } + }); } @Test - public void http_interface_is_on_when_networking_is_enabled() throws Exception { + void http_interface_is_on_when_networking_is_enabled() throws Exception { int httpPort = getFreePort(); try (Application application = Application.fromServicesXml(servicesXmlWithServer(httpPort), Networking.enable)) { HttpClient client = new org.apache.http.impl.client.DefaultHttpClient(); @@ -338,7 +341,7 @@ public class ApplicationTest { } @Test - public void athenz_in_deployment_xml() { + void athenz_in_deployment_xml() { try (Application application = Application.fromApplicationPackage(new File("src/test/app-packages/athenz-in-deployment-xml/"), Networking.disable)) { // Deployment succeeded Application unused = application; @@ -360,7 +363,7 @@ public class ApplicationTest { } @Test - public void application_with_access_control_can_be_constructed() { + void application_with_access_control_can_be_constructed() { try (Application application = Application.fromServicesXml(servicesXmlWithAccessControl(), Networking.disable)) { Application unused = application; } |