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
The following commit(s) were added to refs/heads/main by this push:
new 212fd3a81f Java fixes for github actions
212fd3a81f is described below
commit 212fd3a81f021a6b17316bc226d71d59e505959a
Author: Andy Seaborne <[email protected]>
AuthorDate: Tue May 27 22:03:33 2025 +0100
Java fixes for github actions
---
.../fuseki/main/TestFusekiStdReadOnlySetup.java | 1 +
.../jena/fuseki/main/TestFusekiStdSetup.java | 2 +-
.../rdfconnection/TestRDFConnectionFuseki.java | 42 ++--
.../rdfconnection/TestRDFConnectionRemote.java | 254 ++++++++++++++-------
4 files changed, 202 insertions(+), 97 deletions(-)
diff --git
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdReadOnlySetup.java
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdReadOnlySetup.java
index 9d0fa78a48..abebe0eaac 100644
---
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdReadOnlySetup.java
+++
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdReadOnlySetup.java
@@ -40,6 +40,7 @@ import org.apache.jena.sparql.sse.SSE;
/** Tests for .add("/ds", dsg, false) */
public class TestFusekiStdReadOnlySetup {
+
// This test suite is TestFusekiStdSetup, modified for read-only.
private static FusekiServer server = null;
diff --git
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdSetup.java
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdSetup.java
index 3d654dd906..d56bab9235 100644
---
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdSetup.java
+++
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestFusekiStdSetup.java
@@ -59,7 +59,7 @@ public class TestFusekiStdSetup {
dataset.add(SSE.parseQuad("(:g :s :p 2 )"));
}
- // ==== Common code: TestFusekiStdSetup, TestFusekiStdReadOnlySetup,
TestFusekiShaclValidation
+ // ==== Common code: TestFusekiStdSetup, TestFusekiStdReadOnlySetup,
TestFusekiShaclValidation, TestRDFConnectionRemote
private static Object lock = new Object();
diff --git
a/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionFuseki.java
b/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionFuseki.java
index dfc8cbe8f3..81069d7b7b 100644
---
a/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionFuseki.java
+++
b/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionFuseki.java
@@ -44,31 +44,35 @@ public class TestRDFConnectionFuseki extends
TestRDFConnectionRemote {
@Override
@Test(expected=QueryParseException.class)
public void non_standard_syntax_1() {
- RDFConnection conn =
RDFConnectionFuseki.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build();
- try ( conn ) {
- ResultSet rs = conn.query("FOOBAR").execSelect();
- }
+ withServer((datasetURL)->{
+ RDFConnection conn =
RDFConnectionFuseki.service(datasetURL).parseCheckSPARQL(true).build();
+ try ( conn ) {
+ ResultSet rs = conn.query("FOOBAR").execSelect();
+ }
+ });
}
@Override
@Test
public void non_standard_syntax_2() {
- // This should result in a 400 from Fuseki - and not a parse-check
before sending.
- RDFConnection conn =
RDFConnectionFuseki.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build();
- try ( conn ) {
- String level = LogCtl.getLevel(Fuseki.actionLog);
- try {
- LogCtl.setLevel(Fuseki.actionLog, "ERROR");
- Runnable action = ()-> {
- try( QueryExecution qExec = conn.query("FOOBAR") ) {
- qExec.execSelect();
- }};
- FusekiTestLib.expectQueryFail(action, Code.BAD_REQUEST);
- } finally {
- LogCtl.setLevel(Fuseki.actionLog, level);
- conn.close();
+ withServer((datasetURL)->{
+ // This should result in a 400 from Fuseki - and not a parse-check
before sending.
+ RDFConnection conn =
RDFConnectionFuseki.service(datasetURL).parseCheckSPARQL(false).build();
+ try ( conn ) {
+ String level = LogCtl.getLevel(Fuseki.actionLog);
+ try {
+ LogCtl.setLevel(Fuseki.actionLog, "ERROR");
+ Runnable action = ()-> {
+ try( QueryExecution qExec = conn.query("FOOBAR") ) {
+ qExec.execSelect();
+ }};
+ FusekiTestLib.expectQueryFail(action,
Code.BAD_REQUEST);
+ } finally {
+ LogCtl.setLevel(Fuseki.actionLog, level);
+ conn.close();
+ }
}
- }
+ });
}
}
diff --git
a/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionRemote.java
b/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionRemote.java
index 75f19f3836..082af1bbdd 100644
---
a/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionRemote.java
+++
b/jena-integration-tests/src/test/java/org/apache/jena/test/rdfconnection/TestRDFConnectionRemote.java
@@ -18,10 +18,12 @@
package org.apache.jena.test.rdfconnection;
+import static org.apache.jena.fuseki.main.ConfigureTests.OneServerPerTestSuite;
import static org.junit.Assert.assertNotNull;
import org.apache.jena.atlas.logging.LogCtl;
import org.apache.jena.fuseki.Fuseki;
+import org.apache.jena.fuseki.main.ConfigureTests;
import org.apache.jena.fuseki.main.FusekiServer ;
import org.apache.jena.fuseki.main.FusekiTestLib;
import org.apache.jena.query.QueryExecution;
@@ -39,27 +41,90 @@ import org.apache.jena.system.Txn ;
import org.apache.jena.update.UpdateException;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.web.HttpSC.Code;
-import org.junit.AfterClass ;
import org.junit.Before ;
-import org.junit.BeforeClass ;
import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
public class TestRDFConnectionRemote extends AbstractTestRDFConnection {
protected static FusekiServer server ;
private static DatasetGraph serverdsg = DatasetGraphFactory.createTxnMem()
;
- @BeforeClass
+ // ==== Common code: TestFusekiStdSetup, TestFusekiStdReadOnlySetup,
TestFusekiShaclValidation
+
+ private static Object lock = new Object();
+
+ private static void sync(Runnable action) {
+ synchronized(lock) {
+ action.run();
+ }
+ }
+
+ @BeforeAll
public static void beforeClass() {
- // Enable server output.
- //LogCtl.setLevel(Fuseki.actionLog, "INFO");
+ if ( OneServerPerTestSuite ) {
+ server = createServer().start();
+ }
+ }
+
+ @AfterAll
+ public static void afterClass() {
+ if ( OneServerPerTestSuite )
+ stopServer(server);
+ }
+
+ @FunctionalInterface
+ interface Action { void run(String datasetURL); }
+
+ protected void withServer(Action action) {
+ FusekiServer server = server();
+ try {
+ String datasetURL = server.datasetURL("/ds");
+ sync(()-> {
+ action.run(datasetURL);
+ });
+ } finally {
+ finishWithServer(server);
+ }
+ }
+
+ private static FusekiServer createServer() {
+ serverdsg = DatasetGraphFactory.createTxnMem() ;
server = FusekiServer.create().loopback(true)
.verbose(true)
.port(0)
.add("/ds", serverdsg)
.build() ;
server.start() ;
+ return server;
+ }
+
+ private FusekiServer server() {
+ if ( OneServerPerTestSuite )
+ return server;
+ else
+ return createServer().start();
+ }
+
+ private void finishWithServer(FusekiServer server) {
+ if ( ConfigureTests.OneServerPerTestSuite )
+ return;
+ stopServer(server);
+ }
+
+ private static void stopServer(FusekiServer server) {
+ if ( ! ConfigureTests.CloseTestServers )
+ return;
+ sync(()->server.stop());
}
+ private static void clearAll(RDFConnection conn) {
+ if ( !ConfigureTests.OneServerPerTestSuite )
+ try { conn.update("CLEAR ALL"); } catch (Throwable th) {}
+ }
+
+ // ====
+
@Before
public void beforeTest() {
// Clear server
@@ -69,11 +134,6 @@ public class TestRDFConnectionRemote extends
AbstractTestRDFConnection {
// @After
// public void afterTest() {}
- @AfterClass
- public static void afterClass() {
- server.stop();
- }
-
@Override
protected boolean supportsAbort() { return false ; }
@@ -89,173 +149,213 @@ public class TestRDFConnectionRemote extends
AbstractTestRDFConnection {
// the encoded "<" the Jetty request has decoded %3E.
@Test public void named_graph_load_remote_1() {
- test_named_graph_load_remote_200(connection(), "http://host/abc%3E");
+ withServer((datasetURL)->{
+ test_named_graph_load_remote_200(connection(),
"http://host/abc%3E");
+ });
}
@Test public void named_graph_load_remote_2() {
- test_named_graph_load_remote_200(connection(),
"http://host/abc%20xyz");
+ withServer((datasetURL)->{
+ test_named_graph_load_remote_200(connection(),
"http://host/abc%20xyz");
+ });
}
@Test public void named_graph_load_remote_3() {
- test_named_graph_load_remote_400(connection(), "http://host/abc<");
+ withServer((datasetURL)->{
+ test_named_graph_load_remote_400(connection(), "http://host/abc<");
+ });
}
@Test public void named_graph_load_remote_4() {
- test_named_graph_load_remote_400(connection(), "http://host/abc def");
+ withServer((datasetURL)->{
+ test_named_graph_load_remote_400(connection(), "http://host/abc
def");
+ });
}
@Test(expected=QueryParseException.class)
public void non_standard_syntax_0() {
- // Default setup - local checking.
- try ( RDFConnection conn = connection() ) {
- ResultSet rs = conn.query("FOOBAR").execSelect();
- }
+ withServer((datasetURL)->{
+ // Default setup - local checking.
+ try ( RDFConnection conn = connection() ) {
+ ResultSet rs = conn.query("FOOBAR").execSelect();
+ }
+ });
}
@Test(expected=QueryParseException.class)
public void non_standard_syntax_1() {
- RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build();
- try ( conn ) {
- ResultSet rs = conn.query("FOOBAR").execSelect();
- }
+ withServer((datasetURL)->{
+ RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(true).build();
+ try ( conn ) {
+ ResultSet rs = conn.query("FOOBAR").execSelect();
+ }
+ });
}
@Test
public void non_standard_syntax_2() {
- // This should result in a 400 from Fuseki - and not a parse-check
before sending.
- RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build();
- try ( conn ) {
- String level = LogCtl.getLevel(Fuseki.actionLog);
- try {
- LogCtl.setLevel(Fuseki.actionLog, "ERROR");
- Runnable action = ()-> {
- try( QueryExecution qExec = conn.query("FOOBAR") ) {
- qExec.execSelect();
- }};
- FusekiTestLib.expectQueryFail(action, Code.BAD_REQUEST);
- } finally {
- LogCtl.setLevel(Fuseki.actionLog, level);
+ withServer((datasetURL)->{
+ // This should result in a 400 from Fuseki - and not a parse-check
before sending.
+ RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build();
+ try ( conn ) {
+ String level = LogCtl.getLevel(Fuseki.actionLog);
+ try {
+ LogCtl.setLevel(Fuseki.actionLog, "ERROR");
+ Runnable action = ()-> {
+ try( QueryExecution qExec = conn.query("FOOBAR") ) {
+ qExec.execSelect();
+ }};
+ FusekiTestLib.expectQueryFail(action,
Code.BAD_REQUEST);
+ } finally {
+ LogCtl.setLevel(Fuseki.actionLog, level);
+ }
}
- }
+ });
}
/** Non-standard query syntax on remote connection with parse check
enabled is expected to fail. */
@Test(expected = QueryParseException.class)
public void non_standard_syntax_query_remote_1a() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build()
) {
- try (QueryExecution qe = conn.newQuery().query("FOOBAR").build())
{ }
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(true).build() ) {
+ try (QueryExecution qe =
conn.newQuery().query("FOOBAR").build()) { }
+ }
+ });
}
/** Non-standard query syntax on remote connection with parse flag
overridden on the builder is expected to work. */
@Test
public void non_standard_syntax_query_remote_1b() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build()
) {
- try (QueryExecution qe =
conn.newQuery().parseCheck(false).query("FOOBAR").build()) { }
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(true).build() ) {
+ try (QueryExecution qe =
conn.newQuery().parseCheck(false).query("FOOBAR").build()) { }
+ }
+ });
}
/** Non-standard query syntax on remote connection with parse check
disabled is expected to work. */
@Test
public void non_standard_syntax_query_remote_2a() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- try (QueryExecution qe = conn.newQuery().query("FOOBAR").build())
{ }
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ try (QueryExecution qe =
conn.newQuery().query("FOOBAR").build()) { }
+ }
+ });
}
/** Non-standard query syntax on remote connection with parse flag
overridden on the builder is expected to fail. */
@Test(expected = QueryParseException.class)
public void non_standard_syntax_query_remote_2b() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- try (QueryExecution qe =
conn.newQuery().parseCheck(true).query("FOOBAR").build()) { }
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ try (QueryExecution qe =
conn.newQuery().parseCheck(true).query("FOOBAR").build()) { }
+ }
+ });
}
/** Non-standard update syntax on remote connection with parse check
enabled is expected to fail. */
@Test(expected = QueryParseException.class)
public void non_standard_syntax_update_remote_1a() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build()
) {
- conn.newUpdate().update("FOOBAR").build();
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(true).build() ) {
+ conn.newUpdate().update("FOOBAR").build();
+ }
+ });
}
/** Non-standard update syntax on remote connection with parse flag
overridden on the builder is expected to work. */
@Test
public void non_standard_syntax_update_remote_1b() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build()
) {
- conn.newUpdate().parseCheck(false).update("FOOBAR").build();
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(true).build() ) {
+ conn.newUpdate().parseCheck(false).update("FOOBAR").build();
+ }
+ });
}
/** Non-standard update syntax on remote connection with parse check
disabled is expected to work. */
@Test
public void non_standard_syntax_update_remote_2a() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- conn.newUpdate().update("FOOBAR").build();
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ conn.newUpdate().update("FOOBAR").build();
+ }
+ });
}
/** Non-standard update syntax on remote connection with parse flag
overridden on the builder is expected to fail. */
@Test(expected = QueryParseException.class)
- public void non_standard_syntax_update_remote_2b() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
+ public void non_standard_syntax_update_remote_2b()
{withServer((datasetURL)->{
+
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
conn.newUpdate().parseCheck(true).update("FOOBAR").build();
}
+ });
}
/** Non-standard update syntax on remote connection with parse check
disabled is expected to work. */
@Test
public void non_standard_syntax_update_remote_3a() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- conn.newUpdate().update("FOO").update("BAR").build();
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ conn.newUpdate().update("FOO").update("BAR").build();
+ }
+ });
}
/** Non-standard update syntax on remote connection with parse flag
disabled on the builder is expected to work. */
public void non_standard_syntax_update_remote_3b() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(true).build()
) {
-
conn.newUpdate().parseCheck(false).update("FOO").update("BAR").build();
- }
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(true).build() ) {
+
conn.newUpdate().parseCheck(false).update("FOO").update("BAR").build();
+ }
+ });
}
/** Non-standard update syntax with substitution should fail on build. */
@Test(expected = UpdateException.class)
public void non_standard_syntax_update_remote_3c() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- conn.newUpdate().parseCheck(false).update("FOO").update("BAR")
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ conn.newUpdate().parseCheck(false).update("FOO").update("BAR")
.substitution("foo", RDF.type).build();
- }
+ }
+ });
}
/** Standard update syntax with substitution should work. */
@Test
public void standard_syntax_update_remote_1a() {
- RDFNode FALSE = ResourceFactory.createTypedLiteral(false);
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- conn.newUpdate()
+ withServer((datasetURL)->{
+ RDFNode FALSE = ResourceFactory.createTypedLiteral(false);
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ conn.newUpdate()
.update("INSERT { <a> <b> <c> } WHERE { FILTER(?foo) }")
.update("INSERT { <x> <y> <z> } WHERE { FILTER(?foo) }")
.substitution("foo", FALSE)
.build()
.execute();
- }
+ }
+ });
}
/** Standard update syntax with substitution should work when comments are
involved. */
@Test
public void standard_syntax_update_remote_2b() {
- try ( RDFConnection conn =
RDFConnectionRemote.service(server.datasetURL("/ds")).parseCheckSPARQL(false).build()
) {
- conn.newUpdate()
+ withServer((datasetURL)->{
+ try ( RDFConnection conn =
RDFConnectionRemote.service(datasetURL).parseCheckSPARQL(false).build() ) {
+ conn.newUpdate()
.update("# <update1>\n INSERT { <a> <urn:b> <c> } WHERE {
FILTER(false) } # </update1>")
.update("# <update2>\n INSERT { <d> <urn:e> <f> } WHERE {
FILTER(false) } # </update2>")
.update("# <update3>\n INSERT { <g> <urn:h> <i> } WHERE {
FILTER(false) } # </update3>")
.build()
.execute();
- }
+ }
+ });
}
// Should work.
- private static void test_named_graph_load_remote_200(RDFConnection
connection, String target) {
+ private void test_named_graph_load_remote_200(RDFConnection connection,
String target) {
String testDataFile = DIR+"data.ttl";
try ( RDFConnection conn = connection ) {
conn.load(target, testDataFile);
@@ -265,6 +365,7 @@ public class TestRDFConnectionRemote extends
AbstractTestRDFConnection {
}
// Should be a bad request.
+
private static void test_named_graph_load_remote_400(RDFConnection
connection, String target) {
String logLevel = LogCtl.getLevel(Fuseki.actionLogName);
LogCtl.setLevel(Fuseki.actionLogName, "ERROR");
@@ -281,4 +382,3 @@ public class TestRDFConnectionRemote extends
AbstractTestRDFConnection {
}
}
}
-