You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2025/01/01 11:11:06 UTC
(jena) 08/08: Convert Fuseki-core tests to JUnit5
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit d9c17fe8a41326ddd80dc7bbf1ab77e83a32034e
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Wed Jan 1 10:02:55 2025 +0000
Convert Fuseki-core tests to JUnit5
---
.../org/apache/jena/fuseki/TestValidators.java | 83 +++++++++++-----------
.../fuseki/server/TestDatasetDescriptionMap.java | 6 +-
.../jena/fuseki/server/TestDispatchOnURI.java | 18 +++--
.../org/apache/jena/fuseki/test/FusekiTest.java | 6 +-
.../java/org/apache/jena/fuseki/test/HttpTest.java | 18 ++---
jena-fuseki2/jena-fuseki-webapp/pom.xml | 18 +++++
6 files changed, 85 insertions(+), 64 deletions(-)
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 e7c40f8a10..6259da5e9a 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("<http://example/>");
+ assertThrows(FusekiConfigException.class, ()->Validators.serviceName("<http://example/>"));
}
@Test public void validator_endpoint_null() {
@@ -127,49 +130,49 @@ public class TestValidators {
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("<http://example/>");
+ assertThrows(FusekiConfigException.class, ()->Validators.endpointName("<http://example/>)"));
}
@Test public void validator_graph_1() {
@@ -180,13 +183,13 @@ public class TestValidators {
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 3c58c38084..706d66f753 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 abad6c0f5d..b505eab431 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 @@ public class TestDispatchOnURI {
// 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 ab2775b535..be737bae67 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 @@ package org.apache.jena.fuseki.test;
import java.util.Objects;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
public class FusekiTest {
@@ -29,10 +29,10 @@ public class FusekiTest {
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 06d88dfc92..4026519bd0 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 class HttpTest {
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 d5f30151b7..f56d991397 100644
--- a/jena-fuseki2/jena-fuseki-webapp/pom.xml
+++ b/jena-fuseki2/jena-fuseki-webapp/pom.xml
@@ -134,6 +134,24 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-suite</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>