From a6fea3c1444c3033b0b752d3e2d0e052d525601a Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Fri, 29 Jul 2022 13:53:19 +0200 Subject: Convert application to junit5 --- application/pom.xml | 29 +++++-- .../yahoo/application/ApplicationBuilderTest.java | 53 ++++++------ .../com/yahoo/application/ApplicationTest.java | 99 +++++++++++----------- .../container/ContainerDocprocTest.java | 80 +++++++++-------- .../container/ContainerModelEvaluationTest.java | 23 ++--- .../container/ContainerProcessingTest.java | 62 ++++++++------ .../container/ContainerRequestTest.java | 48 ++++++----- .../application/container/ContainerSchemaTest.java | 24 +++--- .../yahoo/application/container/ContainerTest.java | 35 ++++---- .../container/handler/HeadersTestCase.java | 77 ++++++++--------- .../container/handler/ResponseTestCase.java | 10 +-- 11 files changed, 296 insertions(+), 244 deletions(-) diff --git a/application/pom.xml b/application/pom.xml index 51448502d1d..34bf1b56c0d 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -60,11 +60,6 @@ ${project.version} compile - - junit - junit - test - @@ -172,6 +181,16 @@ jetty-servlets test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + diff --git a/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java b/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java index 800c30ac8b8..503f11ca0d7 100644 --- a/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java +++ b/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java @@ -2,13 +2,12 @@ package com.yahoo.application; import com.yahoo.io.IOUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.nio.file.Files; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Tony Vaagenes @@ -16,55 +15,53 @@ import static org.junit.Assert.assertTrue; */ public class ApplicationBuilderTest { @Test - public void query_profile_types_can_be_added() throws Exception { + void query_profile_types_can_be_added() throws Exception { withApplicationBuilder(builder -> { builder.queryProfileType("MyProfileType", "" + // - "" + // - "" + // - "" + // - ""); + "" + // + "" + // + "" + // + ""); assertTrue(Files.exists(builder.getPath().resolve("search/query-profiles/types/MyProfileType.xml"))); }); } @Test - public void query_profile_can_be_added() throws Exception { + void query_profile_can_be_added() throws Exception { withApplicationBuilder(builder -> { builder.queryProfile("MyProfile", - "" + - "Hello world!" + - ""); + "" + + "Hello world!" + + ""); assertTrue(Files.exists(builder.getPath().resolve("search/query-profiles/MyProfile.xml"))); }); } @Test - public void rank_expression_can_be_added() throws Exception { + void rank_expression_can_be_added() throws Exception { withApplicationBuilder(builder -> { builder.rankExpression("myExpression", "content"); assertTrue(Files.exists(builder.getPath().resolve("schemas/myExpression.expression"))); }); } - @SuppressWarnings("deprecation") - @Rule - public ExpectedException expectedException = ExpectedException.none(); - + // application unreferenced inside try @Test - @SuppressWarnings("try") // application unreferenced inside try - public void builder_cannot_be_reused() throws Exception { - expectedException.expect(RuntimeException.class); - expectedException.expectMessage("build method"); + @SuppressWarnings("try") + void builder_cannot_be_reused() throws Exception { + Throwable exception = assertThrows(RuntimeException.class, () -> { - ApplicationBuilder builder = new ApplicationBuilder(); - builder.servicesXml(""); - try (Application application = builder.build()) { - // do nothing - } + ApplicationBuilder builder = new ApplicationBuilder(); + builder.servicesXml(""); + try (Application application = builder.build()) { + // do nothing + } - builder.servicesXml(""); // should fail + builder.servicesXml(""); // should fail + }); + assertTrue(exception.getMessage().contains("build method")); // should fail } private interface TestCase { 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("", 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 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", "\n" + "7d\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; } diff --git a/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java b/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java index 7c786d35fab..7dad204a8ce 100644 --- a/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java +++ b/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java @@ -13,12 +13,13 @@ import com.yahoo.document.Document; import com.yahoo.document.DocumentPut; import com.yahoo.document.DocumentType; import com.yahoo.processing.execution.chain.ChainRegistry; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Einar M R Rosenvinge @@ -47,16 +48,16 @@ public class ContainerDocprocTest { return xml; } - @Before + @BeforeEach public void resetContainer() { Container.resetInstance(); } @Test - public void requireThatBasicDocumentProcessingWorks() throws Exception { + void requireThatBasicDocumentProcessingWorks() throws Exception { try (Application app = new ApplicationBuilder() - .servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())) - .documentType("music", DOCUMENT).build()) { + .servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())) + .documentType("music", DOCUMENT).build()) { JDisc container = app.getJDisc("container"); DocumentProcessing docProc = container.documentProcessing(); @@ -84,11 +85,11 @@ public class ContainerDocprocTest { } @Test - public void requireThatLaterDocumentProcessingWorks() throws Exception { + void requireThatLaterDocumentProcessingWorks() throws Exception { try (Application app = new ApplicationBuilder() - .servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())) - .networking(Networking.disable) - .documentType("music", DOCUMENT).build()) { + .servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())) + .networking(Networking.disable) + .documentType("music", DOCUMENT).build()) { JDisc container = app.getJDisc("container"); DocumentProcessing docProc = container.documentProcessing(); DocumentType type = docProc.getDocumentTypes().get("music"); @@ -118,35 +119,44 @@ public class ContainerDocprocTest { } } - @Test(expected = IllegalArgumentException.class) - public void requireThatUnknownChainThrows() { - try (JDisc container = JDisc.fromServicesXml( - getXML("foo", Rot13DocumentProcessor.class.getCanonicalName()), - Networking.disable)) { - container.documentProcessing().process(ComponentSpecification.fromString("unknown"), - new com.yahoo.docproc.Processing()); - } + @Test + void requireThatUnknownChainThrows() { + assertThrows(IllegalArgumentException.class, () -> { + try (JDisc container = JDisc.fromServicesXml( + getXML("foo", Rot13DocumentProcessor.class.getCanonicalName()), + Networking.disable)) { + container.documentProcessing().process(ComponentSpecification.fromString("unknown"), + new com.yahoo.docproc.Processing()); + } + + }); } - @Test(expected = UnsupportedOperationException.class) - public void requireThatProcessingFails() { - try (JDisc container = JDisc.fromServicesXml( - getXML("foo", Rot13DocumentProcessor.class.getCanonicalName()), - Networking.disable)) { - container.processing(); - } + @Test + void requireThatProcessingFails() { + assertThrows(UnsupportedOperationException.class, () -> { + try (JDisc container = JDisc.fromServicesXml( + getXML("foo", Rot13DocumentProcessor.class.getCanonicalName()), + Networking.disable)) { + container.processing(); + } + + }); } - @Test(expected = UnsupportedOperationException.class) - public void requireThatSearchFails() { - try (JDisc container = JDisc.fromServicesXml( - getXML("foo", Rot13DocumentProcessor.class.getCanonicalName()), - Networking.disable)) { - container.search(); - } + @Test + void requireThatSearchFails() { + assertThrows(UnsupportedOperationException.class, () -> { + try (JDisc container = JDisc.fromServicesXml( + getXML("foo", Rot13DocumentProcessor.class.getCanonicalName()), + Networking.disable)) { + container.search(); + } + + }); } diff --git a/application/src/test/java/com/yahoo/application/container/ContainerModelEvaluationTest.java b/application/src/test/java/com/yahoo/application/container/ContainerModelEvaluationTest.java index f76008b4e02..656660f7580 100644 --- a/application/src/test/java/com/yahoo/application/container/ContainerModelEvaluationTest.java +++ b/application/src/test/java/com/yahoo/application/container/ContainerModelEvaluationTest.java @@ -9,16 +9,16 @@ import com.yahoo.application.container.handler.Response; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.test.json.JsonTestHelper; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; import java.net.URLEncoder; import java.nio.charset.CharacterCodingException; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Verify that we can create a JDisc (and hence Application) instance capable of doing model evaluation @@ -27,22 +27,23 @@ import static org.junit.Assume.assumeTrue; */ public class ContainerModelEvaluationTest { + // This should ideally work but may not be worth the effort @Test - @Ignore // This should ideally work but may not be worth the effort - public void testCreateJDiscInstanceWithModelEvaluation() { + @Disabled + void testCreateJDiscInstanceWithModelEvaluation() { try (JDisc jdisc = - JDisc.fromPath(new File("src/test/app-packages/model-evaluation").toPath(), - Networking.disable)) { + JDisc.fromPath(new File("src/test/app-packages/model-evaluation").toPath(), + Networking.disable)) { assertLoadedModels(jdisc); } } @Test - public void testCreateApplicationInstanceWithModelEvaluation() { + void testCreateApplicationInstanceWithModelEvaluation() { assumeTrue(OnnxEvaluator.isRuntimeAvailable()); try (Application application = - Application.fromApplicationPackage(new File("src/test/app-packages/model-evaluation"), - Networking.disable)) { + Application.fromApplicationPackage(new File("src/test/app-packages/model-evaluation"), + Networking.disable)) { assertLoadedModels(application.getJDisc("default")); } } diff --git a/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java b/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java index e5019d6b54f..b10d62e72e0 100644 --- a/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java +++ b/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java @@ -7,13 +7,14 @@ import com.yahoo.component.ComponentSpecification; import com.yahoo.container.Container; import com.yahoo.processing.Request; import com.yahoo.processing.Response; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Einar M R Rosenvinge @@ -36,13 +37,13 @@ public class ContainerProcessingTest { return xml; } - @Before + @BeforeEach public void resetContainer() { Container.resetInstance(); } @Test - public void requireThatBasicProcessingWorks() { + void requireThatBasicProcessingWorks() { try (JDisc container = getContainerWithRot13()) { Processing processing = container.processing(); @@ -55,10 +56,10 @@ public class ContainerProcessingTest { } @Test - public void requireThatBasicProcessingDoesNotTruncateBigResponse() { - int SIZE = 50*1000; + void requireThatBasicProcessingDoesNotTruncateBigResponse() { + int SIZE = 50 * 1000; StringBuilder foo = new StringBuilder(); - for (int j = 0 ; j < SIZE ; j++) { + for (int j = 0; j < SIZE; j++) { foo.append('b'); } @@ -69,13 +70,13 @@ public class ContainerProcessingTest { container.handleRequest( new com.yahoo.application.container.handler.Request("http://foo/processing/?chain=foo&title=" + foo.toString())); - assertEquals(SIZE+26, response.getBody().length); + assertEquals(SIZE + 26, response.getBody().length); } } } @Test - public void processing_and_rendering_works() throws Exception { + void processing_and_rendering_works() throws Exception { try (JDisc container = getContainerWithRot13()) { Processing processing = container.processing(); @@ -90,27 +91,36 @@ public class ContainerProcessingTest { } } - @Test(expected = IllegalArgumentException.class) - public void requireThatUnknownChainThrows() { - try (JDisc container = getContainerWithRot13()) { - container.processing().process(ComponentSpecification.fromString("unknown"), new Request()); - } + @Test + void requireThatUnknownChainThrows() { + assertThrows(IllegalArgumentException.class, () -> { + try (JDisc container = getContainerWithRot13()) { + container.processing().process(ComponentSpecification.fromString("unknown"), new Request()); + } + + }); } - @Test(expected = UnsupportedOperationException.class) - public void requireThatDocprocFails() { - try (JDisc container = getContainerWithRot13()) { - container.documentProcessing(); - } + @Test + void requireThatDocprocFails() { + assertThrows(UnsupportedOperationException.class, () -> { + try (JDisc container = getContainerWithRot13()) { + container.documentProcessing(); + } + + }); } - @Test(expected = UnsupportedOperationException.class) - public void requireThatSearchFails() { - try (JDisc container = getContainerWithRot13()) { - container.search(); - } + @Test + void requireThatSearchFails() { + assertThrows(UnsupportedOperationException.class, () -> { + try (JDisc container = getContainerWithRot13()) { + container.search(); + } + + }); } diff --git a/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java b/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java index 911d57a7d6e..24cae99b5ab 100644 --- a/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java +++ b/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java @@ -11,12 +11,13 @@ import com.yahoo.application.container.handlers.HeaderEchoRequestHandler; import com.yahoo.application.container.handlers.ThrowingInWriteRequestHandler; import com.yahoo.application.container.handlers.WriteException; import com.yahoo.text.Utf8; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.charset.CharacterCodingException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Einar M R Rosenvinge @@ -37,7 +38,7 @@ public class ContainerRequestTest { } @Test - public void requireThatRequestBodyWorks() throws CharacterCodingException { + void requireThatRequestBodyWorks() throws CharacterCodingException { String DATA = "we have no bananas today"; Request req = new Request("http://banana/echo", DATA.getBytes(Utf8.getCharset())); @@ -50,7 +51,7 @@ public class ContainerRequestTest { } @Test - public void requireThatCustomRequestHeadersWork() { + void requireThatCustomRequestHeadersWork() { Request req = new Request("http://banana/echo"); req.getHeaders().add("X-Foo", "Bar"); @@ -62,26 +63,31 @@ public class ContainerRequestTest { } } - @Test(expected = WriteException.class) - public void requireThatRequestHandlerThatThrowsInWriteWorks() { - String DATA = "we have no bananas today"; - Request req = new Request("http://banana/throwwrite", DATA.getBytes(Utf8.getCharset())); + @Test + void requireThatRequestHandlerThatThrowsInWriteWorks() { + assertThrows(WriteException.class, () -> { + String DATA = "we have no bananas today"; + Request req = new Request("http://banana/throwwrite", DATA.getBytes(Utf8.getCharset())); - try (JDisc container = JDisc.fromServicesXml(getXML(ThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/throwwrite"), Networking.disable)) { - Response response = container.handleRequest(req); - req.toString(); - } + try (JDisc container = JDisc.fromServicesXml(getXML(ThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/throwwrite"), Networking.disable)) { + Response response = container.handleRequest(req); + req.toString(); + } + }); } - @Test(expected = DelayedWriteException.class) - public void requireThatRequestHandlerThatThrowsDelayedInWriteWorks() { - String DATA = "we have no bananas today"; - Request req = new Request("http://banana/delayedthrowwrite", DATA.getBytes(Utf8.getCharset())); + @Test + void requireThatRequestHandlerThatThrowsDelayedInWriteWorks() { + assertThrows(DelayedWriteException.class, () -> { + String DATA = "we have no bananas today"; + Request req = new Request("http://banana/delayedthrowwrite", DATA.getBytes(Utf8.getCharset())); - try (JDisc container = JDisc.fromServicesXml(getXML(DelayedThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/delayedthrowwrite"), Networking.disable)) { - Response response = container.handleRequest(req); - req.toString(); - } + try (JDisc container = JDisc.fromServicesXml(getXML(DelayedThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/delayedthrowwrite"), Networking.disable)) { + Response response = container.handleRequest(req); + req.toString(); + } + + }); } diff --git a/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java b/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java index e1e520bccc9..465bdef87a3 100644 --- a/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java +++ b/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java @@ -6,12 +6,13 @@ import com.yahoo.application.container.searchers.AddHitSearcher; import com.yahoo.component.ComponentSpecification; import com.yahoo.search.Query; import com.yahoo.search.Result; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author gjoranv @@ -20,7 +21,7 @@ import static org.junit.Assert.assertTrue; public class ContainerSchemaTest { @Test - public void processing_and_rendering_works() throws Exception { + void processing_and_rendering_works() throws Exception { final String searcherId = AddHitSearcher.class.getName(); try (JDisc container = containerWithSearch(searcherId)) { @@ -32,7 +33,7 @@ public class ContainerSchemaTest { } @Test - public void searching_works() { + void searching_works() { final String searcherId = AddHitSearcher.class.getName(); try (JDisc container = containerWithSearch(searcherId)) { @@ -54,11 +55,14 @@ public class ContainerSchemaTest { "", Networking.disable); } - @Test(expected = UnsupportedOperationException.class) - public void retrieving_search_from_container_without_search_is_illegal() { - try (JDisc container = JDisc.fromServicesXml("", Networking.disable)) { - container.search(); // throws - } + @Test + void retrieving_search_from_container_without_search_is_illegal() { + assertThrows(UnsupportedOperationException.class, () -> { + try (JDisc container = JDisc.fromServicesXml("", Networking.disable)) { + container.search(); // throws + } + + }); } } diff --git a/application/src/test/java/com/yahoo/application/container/ContainerTest.java b/application/src/test/java/com/yahoo/application/container/ContainerTest.java index fda8e0c597a..31e0b71d186 100644 --- a/application/src/test/java/com/yahoo/application/container/ContainerTest.java +++ b/application/src/test/java/com/yahoo/application/container/ContainerTest.java @@ -10,17 +10,17 @@ import com.yahoo.application.container.handlers.TestHandler; import com.yahoo.component.ComponentSpecification; import com.yahoo.search.Query; import com.yahoo.search.Result; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.nio.charset.CharacterCodingException; import java.nio.file.FileSystems; import static com.yahoo.application.container.JDisc.fromServicesXml; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Tony Vaagenes @@ -30,7 +30,7 @@ import static org.junit.Assert.fail; public class ContainerTest { @Test - public void container_can_be_used_as_top_level_element() { + void container_can_be_used_as_top_level_element() { try (JDisc container = fromServicesXml("" + // "" + // "", Networking.disable)) { @@ -39,7 +39,7 @@ public class ContainerTest { } @Test - public void container_id_can_be_set() { + void container_id_can_be_set() { try (JDisc container = fromServicesXml("" + // "" + // "", Networking.disable)) { @@ -48,7 +48,7 @@ public class ContainerTest { } @Test - public void container_can_be_embedded_in_services_tag() { + void container_can_be_embedded_in_services_tag() { try (JDisc container = fromServicesXml("" + // "" + // "" + // @@ -58,9 +58,10 @@ public class ContainerTest { } } + // container is unused inside the try block @Test - @SuppressWarnings("try") // container is unused inside the try block - public void multiple_container_elements_gives_exception() { + @SuppressWarnings("try") + void multiple_container_elements_gives_exception() { try (JDisc container = fromServicesXml("" + // "" + // "" + // @@ -72,7 +73,7 @@ public class ContainerTest { } @Test - public void handleRequest_yields_response_from_correct_request_handler() { + void handleRequest_yields_response_from_correct_request_handler() { final String handlerClass = TestHandler.class.getName(); try (JDisc container = fromServicesXml("" + // "" + // @@ -89,7 +90,7 @@ public class ContainerTest { } @Test - public void load_searcher_from_bundle() { + void load_searcher_from_bundle() { try (JDisc container = JDisc.fromPath(FileSystems.getDefault().getPath("src/test/app-packages/searcher-app"), Networking.disable)) { Result result = container.search().process(ComponentSpecification.fromString("default"), @@ -99,7 +100,7 @@ public class ContainerTest { } @Test - public void document_types_can_be_accessed() throws Exception { + void document_types_can_be_accessed() throws Exception { try (Application application = new ApplicationBuilder().documentType("example", EXAMPLE_DOCUMENT) .servicesXml(CONTAINER_WITH_DOCUMENT_PROCESSING).build()) { JDisc container = application.getJDisc("container"); @@ -109,7 +110,7 @@ public class ContainerTest { } @Test - public void annotation_types_can_be_accessed() throws Exception { + void annotation_types_can_be_accessed() throws Exception { try (Application application = new ApplicationBuilder().documentType("example", "search example {\n" + // " " + EXAMPLE_DOCUMENT + "\n" + // " annotation exampleAnnotation {}\n" + // @@ -121,9 +122,9 @@ public class ContainerTest { } } - @Ignore // Enable this when static state has been removed. + @Disabled // Enable this when static state has been removed. @Test - public void multiple_containers_can_be_run_in_parallel() throws Exception { + void multiple_containers_can_be_run_in_parallel() throws Exception { try (JDisc jdisc1 = jdiscWithHttp(); JDisc jdisc2 = jdiscWithHttp()) { sendRequest(jdisc1); sendRequest(jdisc2); diff --git a/application/src/test/java/com/yahoo/application/container/handler/HeadersTestCase.java b/application/src/test/java/com/yahoo/application/container/handler/HeadersTestCase.java index d88d69f247e..19d5176c108 100644 --- a/application/src/test/java/com/yahoo/application/container/handler/HeadersTestCase.java +++ b/application/src/test/java/com/yahoo/application/container/handler/HeadersTestCase.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.application.container.handler; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collection; @@ -12,12 +12,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** @@ -27,7 +28,7 @@ import static org.junit.Assert.fail; public class HeadersTestCase { @Test - public void requireThatSizeWorksAsExpected() { + void requireThatSizeWorksAsExpected() { Headers headers = new Headers(); assertEquals(0, headers.size()); headers.add("foo", "bar"); @@ -43,7 +44,7 @@ public class HeadersTestCase { } @Test - public void requireThatIsEmptyWorksAsExpected() { + void requireThatIsEmptyWorksAsExpected() { Headers headers = new Headers(); assertTrue(headers.isEmpty()); headers.add("foo", "bar"); @@ -53,7 +54,7 @@ public class HeadersTestCase { } @Test - public void requireThatContainsKeyWorksAsExpected() { + void requireThatContainsKeyWorksAsExpected() { Headers headers = new Headers(); assertFalse(headers.containsKey("foo")); assertFalse(headers.containsKey("FOO")); @@ -63,7 +64,7 @@ public class HeadersTestCase { } @Test - public void requireThatContainsValueWorksAsExpected() { + void requireThatContainsValueWorksAsExpected() { Headers headers = new Headers(); assertFalse(headers.containsValue(Arrays.asList("bar"))); headers.add("foo", "bar"); @@ -71,7 +72,7 @@ public class HeadersTestCase { } @Test - public void requireThatContainsWorksAsExpected() { + void requireThatContainsWorksAsExpected() { Headers headers = new Headers(); assertFalse(headers.contains("foo", "bar")); assertFalse(headers.contains("FOO", "bar")); @@ -85,7 +86,7 @@ public class HeadersTestCase { } @Test - public void requireThatContainsIgnoreCaseWorksAsExpected() { + void requireThatContainsIgnoreCaseWorksAsExpected() { Headers headers = new Headers(); assertFalse(headers.containsIgnoreCase("foo", "bar")); assertFalse(headers.containsIgnoreCase("FOO", "bar")); @@ -99,7 +100,7 @@ public class HeadersTestCase { } @Test - public void requireThatAddStringWorksAsExpected() { + void requireThatAddStringWorksAsExpected() { Headers headers = new Headers(); assertNull(headers.get("foo")); headers.add("foo", "bar"); @@ -109,7 +110,7 @@ public class HeadersTestCase { } @Test - public void requireThatAddListWorksAsExpected() { + void requireThatAddListWorksAsExpected() { Headers headers = new Headers(); assertNull(headers.get("foo")); headers.add("foo", Arrays.asList("bar")); @@ -119,7 +120,7 @@ public class HeadersTestCase { } @Test - public void requireThatAddAllWorksAsExpected() { + void requireThatAddAllWorksAsExpected() { Headers headers = new Headers(); headers.add("foo", "bar"); headers.add("bar", "baz"); @@ -136,7 +137,7 @@ public class HeadersTestCase { } @Test - public void requireThatPutStringWorksAsExpected() { + void requireThatPutStringWorksAsExpected() { Headers headers = new Headers(); assertNull(headers.get("foo")); headers.put("foo", "bar"); @@ -146,7 +147,7 @@ public class HeadersTestCase { } @Test - public void requireThatPutListWorksAsExpected() { + void requireThatPutListWorksAsExpected() { Headers headers = new Headers(); assertNull(headers.get("foo")); headers.put("foo", Arrays.asList("bar")); @@ -156,7 +157,7 @@ public class HeadersTestCase { } @Test - public void requireThatPutAllWorksAsExpected() { + void requireThatPutAllWorksAsExpected() { Headers headers = new Headers(); headers.add("foo", "bar"); headers.add("bar", "baz"); @@ -173,7 +174,7 @@ public class HeadersTestCase { } @Test - public void requireThatRemoveWorksAsExpected() { + void requireThatRemoveWorksAsExpected() { Headers headers = new Headers(); headers.put("foo", Arrays.asList("bar", "baz")); assertEquals(Arrays.asList("bar", "baz"), headers.get("foo")); @@ -183,7 +184,7 @@ public class HeadersTestCase { } @Test - public void requireThatRemoveStringWorksAsExpected() { + void requireThatRemoveStringWorksAsExpected() { Headers headers = new Headers(); headers.put("foo", Arrays.asList("bar", "baz")); assertEquals(Arrays.asList("bar", "baz"), headers.get("foo")); @@ -196,7 +197,7 @@ public class HeadersTestCase { } @Test - public void requireThatClearWorksAsExpected() { + void requireThatClearWorksAsExpected() { Headers headers = new Headers(); headers.add("foo", "bar"); headers.add("bar", "baz"); @@ -208,7 +209,7 @@ public class HeadersTestCase { } @Test - public void requireThatGetWorksAsExpected() { + void requireThatGetWorksAsExpected() { Headers headers = new Headers(); assertNull(headers.get("foo")); headers.add("foo", "bar"); @@ -216,7 +217,7 @@ public class HeadersTestCase { } @Test - public void requireThatGetFirstWorksAsExpected() { + void requireThatGetFirstWorksAsExpected() { Headers headers = new Headers(); assertNull(headers.getFirst("foo")); headers.add("foo", Arrays.asList("bar", "baz")); @@ -224,7 +225,7 @@ public class HeadersTestCase { } @Test - public void requireThatIsTrueWorksAsExpected() { + void requireThatIsTrueWorksAsExpected() { Headers headers = new Headers(); assertFalse(headers.isTrue("foo")); headers.put("foo", Arrays.asList("true")); @@ -242,7 +243,7 @@ public class HeadersTestCase { } @Test - public void requireThatKeySetWorksAsExpected() { + void requireThatKeySetWorksAsExpected() { Headers headers = new Headers(); assertEquals(Collections.>emptySet(), headers.keySet()); headers.add("foo", "bar"); @@ -252,7 +253,7 @@ public class HeadersTestCase { } @Test - public void requireThatValuesWorksAsExpected() { + void requireThatValuesWorksAsExpected() { Headers headers = new Headers(); assertTrue(headers.values().isEmpty()); headers.add("foo", "bar"); @@ -268,7 +269,7 @@ public class HeadersTestCase { } @Test - public void requireThatEntrySetWorksAsExpected() { + void requireThatEntrySetWorksAsExpected() { Headers headers = new Headers(); assertEquals(Collections.emptySet(), headers.entrySet()); headers.put("foo", Arrays.asList("bar", "baz")); @@ -282,7 +283,7 @@ public class HeadersTestCase { } @Test - public void requireThatEntriesWorksAsExpected() { + void requireThatEntriesWorksAsExpected() { Headers headers = new Headers(); assertEquals(Collections.emptyList(), headers.entries()); headers.put("foo", Arrays.asList("bar", "baz")); @@ -301,7 +302,7 @@ public class HeadersTestCase { } @Test - public void requireThatEntryIsUnmodifiable() { + void requireThatEntryIsUnmodifiable() { Headers headers = new Headers(); headers.put("foo", "bar"); Map.Entry entry = headers.entries().get(0); @@ -314,7 +315,7 @@ public class HeadersTestCase { } @Test - public void requireThatEntriesAreUnmodifiable() { + void requireThatEntriesAreUnmodifiable() { Headers headers = new Headers(); headers.put("foo", "bar"); List> entries = headers.entries(); @@ -333,25 +334,25 @@ public class HeadersTestCase { } @Test - public void requireThatEqualsWorksAsExpected() { + void requireThatEqualsWorksAsExpected() { Headers lhs = new Headers(); Headers rhs = new Headers(); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); lhs.add("foo", "bar"); - assertFalse(lhs.equals(rhs)); + assertNotEquals(lhs, rhs); rhs.add("foo", "bar"); - assertTrue(lhs.equals(rhs)); + assertEquals(lhs, rhs); } @Test - public void requireThatHashCodeWorksAsExpected() { + void requireThatHashCodeWorksAsExpected() { Headers lhs = new Headers(); Headers rhs = new Headers(); - assertTrue(lhs.hashCode() == rhs.hashCode()); + assertEquals(lhs.hashCode(), rhs.hashCode()); lhs.add("foo", "bar"); assertTrue(lhs.hashCode() != rhs.hashCode()); rhs.add("foo", "bar"); - assertTrue(lhs.hashCode() == rhs.hashCode()); + assertEquals(lhs.hashCode(), rhs.hashCode()); } private static class MyEntry implements Map.Entry { diff --git a/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java b/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java index edd2acb630d..b0971c141d6 100644 --- a/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java +++ b/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java @@ -1,10 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.application.container.handler; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Einar M R Rosenvinge @@ -12,7 +12,7 @@ import static org.junit.Assert.assertNotNull; public class ResponseTestCase { @Test - public void requireThatCharsetParsingWorks() { + void requireThatCharsetParsingWorks() { assertEquals("utf-8", Response.charset("text/foobar").toString().toLowerCase()); assertEquals("utf-8", Response.charset("adsf").toString().toLowerCase()); assertEquals("utf-8", Response.charset("").toString().toLowerCase()); @@ -26,7 +26,7 @@ public class ResponseTestCase { } @Test - public void testDefaultResponseBody() { + void testDefaultResponseBody() { Response res1 = new Response(); Response res2 = new Response(new byte[0]); -- cgit v1.2.3