diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestValidators.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestValidators.java index e7c40f8a100..6259da5e9ac 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestValidators.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestValidators.java @@ -18,8 +18,11 @@ package org.apache.jena.fuseki; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + import org.apache.jena.fuseki.server.Validators; -import org.junit.Test; public class TestValidators { @Test public void validator_service_1() { @@ -50,49 +53,49 @@ public class TestValidators { Validators.serviceName("/abc.def_ghi"); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_1() { - Validators.serviceName(null); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName(null)); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_2() { - Validators.serviceName(" "); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName(" ")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_3() { - Validators.serviceName("\\"); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName("\\")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_4() { - Validators.serviceName("<"); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName("<")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_5() { - Validators.serviceName(">"); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName(">")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_6() { - Validators.serviceName("?"); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName("?")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_7() { - Validators.serviceName("#"); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName("#")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_8() { - Validators.serviceName("\""); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName("\"")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_service_bad_20() { - Validators.serviceName(""); + assertThrows(FusekiConfigException.class, ()->Validators.serviceName("")); } @Test public void validator_endpoint_null() { @@ -127,49 +130,49 @@ public void validator_service_bad_20() { Validators.endpointName("/abc.def_ghi"); } -// @Test(expected=FusekiConfigException.class) +// @Test // public void validator_endpoint_bad_1() { // Validators.endpointName(null); // } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_2() { - Validators.endpointName(" "); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName(" ")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_3() { - Validators.endpointName("\\"); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName("\\")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_4() { - Validators.endpointName("<"); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName("<")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_5() { - Validators.endpointName(">"); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName(">")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_6() { - Validators.endpointName("?"); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName("?")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_7() { - Validators.endpointName("#"); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName("#")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_8() { - Validators.endpointName("\""); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName("\"")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_endpoint_bad_20() { - Validators.endpointName(""); + assertThrows(FusekiConfigException.class, ()->Validators.endpointName(")")); } @Test public void validator_graph_1() { @@ -180,13 +183,13 @@ public void validator_endpoint_bad_20() { Validators.graphName("http://example/abc#def"); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_graph_bad_1() { - Validators.graphName("abc"); + assertThrows(FusekiConfigException.class, ()->Validators.graphName("abc")); } - @Test(expected=FusekiConfigException.class) + @Test public void validator_graph_bad_2() { - Validators.graphName("#abc"); + assertThrows(FusekiConfigException.class, ()->Validators.graphName("#abc")); } } diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDatasetDescriptionMap.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDatasetDescriptionMap.java index 3c58c380844..706d66f7536 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDatasetDescriptionMap.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDatasetDescriptionMap.java @@ -18,10 +18,10 @@ package org.apache.jena.fuseki.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.jena.fuseki.build.DatasetDescriptionMap; import org.apache.jena.fuseki.build.FusekiConfig; diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDispatchOnURI.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDispatchOnURI.java index abad6c0f5d8..b505eab431b 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDispatchOnURI.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/server/TestDispatchOnURI.java @@ -18,14 +18,12 @@ package org.apache.jena.fuseki.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - import org.apache.jena.fuseki.servlets.ActionLib; -import org.junit.BeforeClass; -import org.junit.Test; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /* * Test the request URI part of dispatch. @@ -38,7 +36,7 @@ public class TestDispatchOnURI { private static DataAccessPointRegistry registryNoRoot; private static DataAccessPointRegistry registryWithRoot; - @BeforeClass public static void beforeClass() { + @BeforeAll public static void beforeClass() { registryNoRoot = new DataAccessPointRegistry(); DataService dSrv1 = DataService.newBuilder() .addEndpoint(Operation.Query) @@ -119,7 +117,7 @@ public class TestDispatchOnURI { private void testNoDispatch(String requestURI, DataAccessPointRegistry registry) { DataAccessPoint dap = Dispatcher.locateDataAccessPoint(requestURI, registry); - assertNull("Expect no dispatch for "+requestURI, dap); + assertNull(dap, "Expected no dispatch for "+requestURI); } private void testDispatch(String requestURI, DataAccessPointRegistry registry, String expectedDataset, String expectedEndpoint) { @@ -132,6 +130,6 @@ private void testDispatch(String requestURI, DataAccessPointRegistry registry, S // The request URI part of dispatch choice in Dispatcher.chooseProcessor(HttpAction action) String ep = ActionLib.mapRequestToEndpointName(requestURI, dap); assertNotNull(ep); - assertEquals("Endpoint", expectedEndpoint, ep); + assertEquals(expectedEndpoint, ep); } } diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/FusekiTest.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/FusekiTest.java index ab2775b5358..be737bae671 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/FusekiTest.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/FusekiTest.java @@ -20,7 +20,7 @@ import java.util.Objects; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; public class FusekiTest { @@ -29,10 +29,10 @@ public static void assertStringList(String str, String... expected) { str = str.replace(" ", ""); String[] x = str.split(","); for ( String ex : expected ) { - Assert.assertTrue("Got: "+str+" - Does not contain "+ex, containsStr(ex, x)); + Assertions.assertTrue(containsStr(ex, x), "Got: "+str+" - Does not contain "+ex); } for ( String s : x ) { - Assert.assertTrue("Got: "+str+" - Not expected "+s, containsStr(s, expected)); + Assertions.assertTrue(containsStr(s, expected), "Got: "+str+" - Not expected "+s); } } diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/HttpTest.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/HttpTest.java index 06d88dfc92d..4026519bd09 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/HttpTest.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/test/HttpTest.java @@ -18,24 +18,27 @@ package org.apache.jena.fuseki.test; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Assertions; + import org.apache.jena.atlas.web.HttpException; import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; import org.apache.jena.web.HttpSC; -import org.junit.Assert; public class HttpTest { public static void expect4xx(Runnable action) { try { action.run(); - Assert.fail("Expected HttpException"); + Assertions.fail("Expected HttpException"); } catch (QueryExceptionHTTP ex) { if ( ex.getStatusCode() < 400 || ex.getStatusCode() > 499 ) - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } catch (HttpException ex) { // -1 : any status code in HttpException if ( ex.getStatusCode() < 400 || ex.getStatusCode() > 499 ) - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } } @@ -63,17 +66,16 @@ public static void expect415(Runnable action) { execWithHttpException(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, action); } - public static void execWithHttpException(int expectedStatusCode, Runnable action) { try { action.run(); - Assert.fail("Expected HttpException "+expectedStatusCode); + fail("Expected HttpException "+expectedStatusCode); } catch (QueryExceptionHTTP ex) { if ( expectedStatusCode > 0 ) - Assert.assertEquals(ex.getMessage()+" ::", expectedStatusCode, ex.getStatusCode()); + Assertions.assertEquals(expectedStatusCode, ex.getStatusCode(), ex.getMessage()+" ::"); } catch (HttpException ex) { if ( expectedStatusCode > 0 ) - Assert.assertEquals(ex.getMessage()+" ::", expectedStatusCode, ex.getStatusCode()); + Assertions.assertEquals(expectedStatusCode, ex.getStatusCode(), ex.getMessage()+" ::"); } } diff --git a/jena-fuseki2/jena-fuseki-webapp/pom.xml b/jena-fuseki2/jena-fuseki-webapp/pom.xml index d5f30151b7c..f56d9913970 100644 --- a/jena-fuseki2/jena-fuseki-webapp/pom.xml +++ b/jena-fuseki2/jena-fuseki-webapp/pom.xml @@ -134,6 +134,24 @@ test + + org.junit.jupiter + junit-jupiter + test + + + + org.junit.jupiter + junit-jupiter-params + test + + + + org.junit.platform + junit-platform-suite + test + + org.awaitility awaitility