From 252c03ad502aa8b6465c3c60ee6e6cb9bf4053e4 Mon Sep 17 00:00:00 2001 From: Luca Roffia Date: Fri, 6 Dec 2024 16:13:32 +0100 Subject: [PATCH] fix junti test passed; fixed forced bindings for multiple updates --- .../properties/SPARQL11SEProperties.java | 2 +- .../it/unibo/arces/wot/sepa/pattern/JSAP.java | 35 +++++++++++----- .../arces/wot/sepa/ConfigurationProvider.java | 41 ++++++++++--------- .../it/unibo/arces/wot/sepa/Publisher.java | 2 +- .../it/unibo/arces/wot/sepa/Subscriber.java | 2 +- .../java/it/unibo/arces/wot/sepa/Sync.java | 8 ++-- .../arces/wot/sepa/stress/StressPAC.java | 10 ++--- client-api/src/test/resources/sepatest.jsap | 4 +- .../sepa/engine/core/EngineProperties.java | 2 +- pom.xml | 21 +++++----- 10 files changed, 71 insertions(+), 56 deletions(-) diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java index 1552f53b..07462856 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java @@ -133,7 +133,7 @@ public SPARQL11SEProperties(URI uri, String[] args) throws SEPAPropertiesExcepti Logging.logger.trace("Argument " + args[i]); String[] params = args[i].split("="); if (params.length == 2) { - setParameter(params[0], params[1]); + setSeParameter(params[0], params[1]); } } } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java index cb15eeaf..67b7301b 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java @@ -188,7 +188,6 @@ }} * */ -@SuppressWarnings("JavadocLinkAsPlainText") public class JSAP extends SPARQL11SEProperties { private static final Set numbersOrBoolean = new HashSet<>(); private final PrefixMappingMem prefixes; @@ -451,6 +450,12 @@ public boolean reconnect() { /* * UPDATE */ + public String getUpdateHost() { + String ret = sparql11protocol.getHost(); + if (ret == null) ret = host; + return ret; + } + public String getSPARQLUpdate(String id) { return (updates.get(id) == null ? null : updates.get(id).sparql); } @@ -596,6 +601,12 @@ public void setUsingGraphURI(String id, Set graph) { /* * QUERY */ + public String getQueryHost() { + String ret = sparql11protocol.getHost(); + if (ret == null) ret = host; + return ret; + } + public String getSPARQLQuery(String id) { return (queries.get(id) == null ? null : queries.get(id).sparql); } @@ -738,7 +749,12 @@ public void setDefaultGraphURI(String id, Set graph) { /* * SUBSCRIBE */ - + public String getSubscribeHost() { + String ret = sparql11seprotocol.getHost(); + if (ret == null) ret = host; + return ret; + } + public String getSubscribeHost(String id) { String ret=null; try { @@ -1030,12 +1046,13 @@ public String addPrefixesAndReplaceBindings(String sparql, Bindings bindings) th UpdateRequest request = UpdateFactory.create(); request.setPrefixMapping(prefixes); UpdateFactory.parse(request, replaceBindings(sparql, bindings)); - IndentedWriter writer = new IndentedLineBuffer(); - UpdateWriterVisitor visitor = new UpdateWriterVisitor(writer, new SerializationContext()); - + for (Update upd : request.getOperations()) { + IndentedWriter writer = new IndentedLineBuffer(); + UpdateWriterVisitor visitor = new UpdateWriterVisitor(writer, new SerializationContext()); if (!sb.toString().isEmpty()) sb.append(";"); - + else sb.append(prologue); + if (upd instanceof UpdateDataDelete) visitor.visit((UpdateDataDelete) upd); else if (upd instanceof UpdateDataInsert) @@ -1061,13 +1078,11 @@ else if (upd instanceof UpdateCreate) else if (upd instanceof UpdateModify) visitor.visit((UpdateModify) upd); - if (upd instanceof UpdateModify || upd instanceof UpdateAdd || upd instanceof UpdateDataDelete || upd instanceof UpdateDataInsert - || upd instanceof UpdateDeleteWhere) - sb.append(prologue); - sb.append(writer); } + + } catch (QueryParseException ex) { sb.append(prologue).append(replaceBindings(sparql, bindings)); } diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java index 8b467a2b..63f933a8 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java @@ -14,15 +14,15 @@ import it.unibo.arces.wot.sepa.pattern.JSAP; import java.io.Closeable; -import java.io.File; +//import java.io.File; import java.io.IOException; -import java.net.URI; +//import java.net.URI; import java.util.UUID; public class ConfigurationProvider implements Closeable { private final JSAP appProfile; private String prefixes = ""; - private final String jsapPath; + //private final String jsapPath; public long TIMEOUT; public long NRETRY; @@ -34,25 +34,26 @@ public class ConfigurationProvider implements Closeable { public ConfigurationProvider() throws SEPAPropertiesException, SEPASecurityException { String jsapFileName = "sepatest.jsap"; - if (System.getProperty("testConfiguration") != null) { - jsapFileName = System.getProperty("testConfiguration"); - Logging.logger.debug("JSAP from property testConfiguration: " + jsapFileName); - } else if (System.getProperty("secure") != null) { - jsapFileName = "sepatest-secure.jsap"; - Logging.logger.debug("JSAP secure default: " + jsapFileName); - } - - jsapPath = getClass().getClassLoader().getResource(jsapFileName).getPath(); - File f = new File(jsapPath); - if (!f.exists()) { - Logging.logger.error("File not found: " + jsapPath); - throw new SEPAPropertiesException("File not found: " + jsapPath); - } - - Logging.logger.debug("Loading JSAP from: " + f.getPath()); +// if (System.getProperty("testConfiguration") != null) { +// jsapFileName = System.getProperty("testConfiguration"); +// Logging.logger.debug("JSAP from property testConfiguration: " + jsapFileName); +// } else if (System.getProperty("secure") != null) { +// jsapFileName = "sepatest-secure.jsap"; +// Logging.logger.debug("JSAP secure default: " + jsapFileName); +// } +// +// jsapPath = getClass().getClassLoader().getResource(jsapFileName).getPath(); +// File f = new File(jsapPath); +// if (!f.exists()) { +// Logging.logger.error("File not found: " + jsapPath); +// throw new SEPAPropertiesException("File not found: " + jsapPath); +// } +// +// Logging.logger.debug("Loading JSAP from: " + f.getPath()); try { - appProfile = new JSAP(URI.create(f.getPath())); +// appProfile = new JSAP(URI.create(f.getPath())); + appProfile = new JSAP(jsapFileName); } catch (SEPAPropertiesException e) { Logging.logger.error(e.getMessage()); throw new RuntimeException(e); diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/Publisher.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/Publisher.java index aa0ba8f8..fad4c0ec 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/Publisher.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/Publisher.java @@ -25,7 +25,7 @@ public Publisher(ConfigurationProvider provider, String id, long n) running = new AtomicLong(n); - this.setName("Publisher-" + id + "-" + this.getId()); + this.setName("Publisher-" + id + "-" + this.threadId()); this.provider = provider; client = new SPARQL11Protocol(provider.getClientSecurityManager()); diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java index 8f86e728..384734a4 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java @@ -27,7 +27,7 @@ public class Subscriber extends Thread implements Closeable, ISubscriptionHandle public Subscriber(ConfigurationProvider provider, String id, ISubscriptionHandler sync) throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException { - this.setName("Subscriber-" + id + "-" + this.getId()); + this.setName("Subscriber-" + id + "-" + this.threadId()); this.provider = provider; this.id = id; this.handler = sync; diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/Sync.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/Sync.java index b20af8fb..83fa608a 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/Sync.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/Sync.java @@ -53,9 +53,9 @@ public synchronized void waitSubscribes(int total) { synchronized (subscribesMutex) { while (subscribes < total) { try { - Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " waitSubscribes"); + Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " waitSubscribes"); subscribesMutex.wait(); - Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " awaken from waitSubscribes"); + Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " awaken from waitSubscribes"); } catch (InterruptedException e) { throw new RuntimeException(e.getCause()); } @@ -88,9 +88,9 @@ public synchronized void waitEvents(int total) { synchronized (eventsMutex) { while (events < total) { try { - Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " waitEvents"); + Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " waitEvents"); eventsMutex.wait(); - Logging.logger.trace("Thread id "+Thread.currentThread().getId()+ " awaken from waitEvents"); + Logging.logger.trace("Thread id "+Thread.currentThread().threadId()+ " awaken from waitEvents"); } catch (InterruptedException e) { throw new RuntimeException(e.getCause()); } diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/stress/StressPAC.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/stress/StressPAC.java index a1edbd10..1f32b948 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/stress/StressPAC.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/stress/StressPAC.java @@ -41,10 +41,10 @@ public static void end() { public void beginTest() throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException, SEPABindingsException, InterruptedException, IOException { Thread.sleep(ConfigurationProvider.SLEEP); - assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes()); - sync.reset(); + assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes()); + Producer deleteAll = new Producer(provider.getJsap(), "DELETE_ALL"); deleteAll.update(); deleteAll.close(); @@ -53,7 +53,7 @@ public void beginTest() throws SEPAProtocolException, SEPASecurityException, SEP @AfterEach public void afterTest() throws IOException, InterruptedException, SEPASecurityException, SEPAPropertiesException, SEPAProtocolException { - assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes()); + assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes()); } @RepeatedTest(ConfigurationProvider.REPEATED_TEST) @@ -84,7 +84,7 @@ public void aggregationX10() throws InterruptedException, SEPASecurityException, randomAggregator.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY); consumerRandom1.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY); - assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes()); + assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes()); randomAggregator.close(); consumerRandom1.close(); @@ -120,7 +120,7 @@ public void aggregationX100() throws InterruptedException, SEPASecurityException randomAggregator.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY); consumerRandom1.syncUnsubscribe(provider.TIMEOUT, provider.NRETRY); - assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+"Unsubscribes: "+sync.getUnsubscribes()); + assertFalse(sync.getSubscribes() != sync.getUnsubscribes(), "Subscribes: "+sync.getSubscribes()+" == Unsubscribes: "+sync.getUnsubscribes()); randomAggregator.close(); consumerRandom1.close(); diff --git a/client-api/src/test/resources/sepatest.jsap b/client-api/src/test/resources/sepatest.jsap index 8a285930..1718e7a1 100644 --- a/client-api/src/test/resources/sepatest.jsap +++ b/client-api/src/test/resources/sepatest.jsap @@ -7,12 +7,12 @@ "protocol": "http", "port": 8000, "query": { - "path": "/sparql", + "path": "/query", "method": "POST", "format": "JSON" }, "update": { - "path": "/sparql", + "path": "/update", "method": "POST", "format": "JSON" } diff --git a/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java b/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java index 3320c651..957ac371 100644 --- a/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java +++ b/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java @@ -335,7 +335,7 @@ public int getWsShutdownTimeout(){ public String getSSLCertificate() { if (!isSecure()) return "Security off"; - return jwt.getParsedX509CertChain().get(0).getIssuerDN().getName() + " " + return jwt.getParsedX509CertChain().get(0).getSubjectX500Principal().getName() + " " + jwt.getParsedX509CertChain().get(0).getNotAfter().toString(); } diff --git a/pom.xml b/pom.xml index 334eb3dd..7fa9a582 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 it.unibo.arces.wot sepa @@ -68,9 +68,9 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.9.0 - 11 + 23 @@ -138,7 +138,7 @@ - + @@ -202,16 +202,15 @@ nimbus-jose-jwt 9.40 + org.junit.jupiter junit-jupiter-api - 5.10.3 - - - org.junit.jupiter - junit-jupiter-engine - 5.10.2 + 5.11.3 + test + org.java-websocket Java-WebSocket