Skip to content

Commit

Permalink
Convert Fuseki-core tests to JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Jan 1, 2025
1 parent 8e18af1 commit 5524964
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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("<http://example/>");
assertThrows(FusekiConfigException.class, ()->Validators.endpointName("<http://example/>)"));
}

@Test public void validator_graph_1() {
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Objects;

import org.junit.Assert;
import org.junit.jupiter.api.Assertions;

public class FusekiTest {

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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()+" ::");
}
}

Expand Down
18 changes: 18 additions & 0 deletions jena-fuseki2/jena-fuseki-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 5524964

Please sign in to comment.