Loading plugins/org.etsi.mts.tdl.execution.java/pom.xml +10 −0 Original line number Diff line number Diff line Loading @@ -57,5 +57,15 @@ <artifactId>junit-jupiter-api</artifactId> <version>5.9.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.14.1</version> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.24.2</version> </dependency> </dependencies> </project> No newline at end of file plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/adapters/http/HttpResponseData.java +0 −1 Original line number Diff line number Diff line package org.etsi.mts.tdl.execution.java.adapters.http; import java.util.ArrayList; import java.util.List; public class HttpResponseData { Loading plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/adapters/http/HttpSystemAdapter.java +11 −30 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Queue; Loading @@ -18,7 +17,6 @@ import org.etsi.mts.tdl.execution.java.rt.core.PojoData; import org.etsi.mts.tdl.execution.java.tri.Argument; import org.etsi.mts.tdl.execution.java.tri.Connection; import org.etsi.mts.tdl.execution.java.tri.Data; import org.etsi.mts.tdl.execution.java.tri.Receiver; import org.etsi.mts.tdl.execution.java.tri.Reporter; import org.etsi.mts.tdl.execution.java.tri.SystemAdapter; import org.etsi.mts.tdl.execution.java.tri.Validator; Loading @@ -39,12 +37,10 @@ public class HttpSystemAdapter implements SystemAdapter { private ObjectMapper mapper; private String baseUri = BASE_URI; // private URI uri = URI.create(baseUri); private Connection[] connections; private Queue<HttpResponse<String>> unhandledResponses = new ConcurrentLinkedQueue<>(); private List<Receiver> receivers = Collections.synchronizedList(new ArrayList<>()); public HttpSystemAdapter(Validator validator, Reporter reporter) { this.validator = validator; Loading @@ -53,9 +49,8 @@ public class HttpSystemAdapter implements SystemAdapter { @Override public void configure(Connection[] connections) { // TODO Auto-generated method stub // XXX // TODO multiple connections this.connections = connections; builder = HttpClient.newBuilder(); Loading @@ -69,8 +64,11 @@ public class HttpSystemAdapter implements SystemAdapter { mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); // mapper.registerModule(new JavaTimeModule()); // mapper.registerModule(new JsonNullableModule()); /* * TODO optional modules * mapper.registerModule(new JavaTimeModule()); * mapper.registerModule(new JsonNullableModule()); */ } private void handleResponse(HttpResponse<String> response, Throwable t) { Loading @@ -92,8 +90,8 @@ public class HttpSystemAdapter implements SystemAdapter { private void applyDefaults(HttpRequest.Builder requestBuilder) { requestBuilder.header("Content-Type", "application/json"); requestBuilder.header("Accept", "application/json"); // XXX requestBuilder.header("Cookie", "usertoken=" + AUTH); // TODO configuration (e.g. auth) // requestBuilder.header("Cookie", "usertoken=" + AUTH); } @Override Loading @@ -103,7 +101,7 @@ public class HttpSystemAdapter implements SystemAdapter { HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(); applyDefaults(requestBuilder); // XXX parameters // TODO parameters try { requestBuilder.uri(URI.create(baseUri + httpData.uri)); Loading Loading @@ -138,7 +136,7 @@ public class HttpSystemAdapter implements SystemAdapter { response = unhandledResponses.peek(); } //XXX //TODO logging reporter.comment("Incoming: " + response.body()); try { Loading Loading @@ -176,12 +174,6 @@ public class HttpSystemAdapter implements SystemAdapter { return null; } @Override public Data ignoreUntil(Data expected, Connection connection) { // XXX return null; } @Override public Data call(Object operation, Argument[] arguments, Data expectedReturn, Data expectedException, Connection connection) { Loading @@ -198,16 +190,5 @@ public class HttpSystemAdapter implements SystemAdapter { throw new UnsupportedOperationException("Procedure-based communication is not supported by this adapter."); } @Override public void addReceiver(Receiver r) { receivers.add(r); } @Override public void removeReceiver(Receiver r) { receivers.remove(r); } private static String BASE_URI = "https://test.valto.fi/valto-360-api"; private static String AUTH = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxOSIsImV4cCI6MTY4NTcxNjU1OCwiaWF0IjoxNjg1NjMwMTU4fQ.y03piKrOIeypj0esuHf1tDSLlbvJPqC3z6eMZaBxtifHNvFY0b04mc8FSjEZzxXa92j6QEVw29xn7AKuTOzEKA"; private static String BASE_URI = "<todo>"; } No newline at end of file plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/rt/core/ReceiverHub.java +13 −11 Original line number Diff line number Diff line Loading @@ -59,10 +59,14 @@ public class ReceiverHub { if (currentlyExpecting.anyReceiver) { // Switch to the first one for reporting synchronized (expecting) { if (expecting.size() > 0) for (Expectable e: expecting) if (!e.ignoreUnmatched) { currentlyExpecting = expecting.get(0); break; } } } // XXX this is not correct expecting.clear(); synchronized (currentlyExpecting) { currentlyExpecting.received = data; Loading @@ -72,6 +76,7 @@ public class ReceiverHub { } catch (InterruptedException e) { } catch (AssertionError e) { if (!currentlyExpecting.ignoreUnmatched) currentlyExpecting.error = e; } } Loading @@ -82,8 +87,8 @@ public class ReceiverHub { this.thread.interrupt(); } public Data receive(Data expected) throws StopException { Expectable expectable = new Expectable(expected); public Data receive(Data expected, boolean ignoreUntil) { Expectable expectable = new Expectable(expected, ignoreUntil); synchronized (expecting) { expecting.add(expectable); expecting.notifyAll(); Loading @@ -104,11 +109,6 @@ public class ReceiverHub { } } public Data ignoreUntil(Data expected) { // XXX return null; } public Data call(Object operation, Argument[] arguments, Data expectedReturn, Data expectedException) { // XXX return null; Loading @@ -118,10 +118,12 @@ public class ReceiverHub { Data expected; Data received; AssertionError error; boolean ignoreUnmatched = false; boolean anyReceiver = false; public Expectable(Data expected) { public Expectable(Data expected, boolean ignoreUnmatched) { this.expected = expected; this.ignoreUnmatched = ignoreUnmatched; this.anyReceiver = expected == null; } } Loading plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/rt/core/TestControl.java +9 −14 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ public class TestControl { anyReceiver.callable = new ExecutionCallable() { @Override public ExecutionResult call() throws Exception { Data data = hub.receive(null); Data data = hub.receive(null, false); return data != null ? new InteractionResult(data) : null; } Loading Loading @@ -227,25 +227,20 @@ public class TestControl { } public ExecutionCallable receive(Data expected, Connection connection) { ExecutionCallableWithDefaults c = new ExecutionCallableWithDefaults() { @Override public ExecutionResult call() throws Exception { Data data = getReceiver(connection).receive(expected); return data != null ? new InteractionResult(data) : null; } }; return c; return receive(expected, connection, false); } public ExecutionCallable trigger(Data expected, Connection connection) { // XXX Receiver return receive(expected, connection, true); } public ExecutionCallable receive(Data expected, Connection connection, boolean isTrigger) { ExecutionCallableWithDefaults c = new ExecutionCallableWithDefaults() { @Override public ExecutionResult call() throws Exception { Data data = getReceiver(connection).ignoreUntil(expected); if (Thread.interrupted()) return null; return new InteractionResult(data); Data data = getReceiver(connection).receive(expected, isTrigger); return data != null ? new InteractionResult(data) : null; } }; return c; Loading Loading
plugins/org.etsi.mts.tdl.execution.java/pom.xml +10 −0 Original line number Diff line number Diff line Loading @@ -57,5 +57,15 @@ <artifactId>junit-jupiter-api</artifactId> <version>5.9.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.14.1</version> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.24.2</version> </dependency> </dependencies> </project> No newline at end of file
plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/adapters/http/HttpResponseData.java +0 −1 Original line number Diff line number Diff line package org.etsi.mts.tdl.execution.java.adapters.http; import java.util.ArrayList; import java.util.List; public class HttpResponseData { Loading
plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/adapters/http/HttpSystemAdapter.java +11 −30 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Queue; Loading @@ -18,7 +17,6 @@ import org.etsi.mts.tdl.execution.java.rt.core.PojoData; import org.etsi.mts.tdl.execution.java.tri.Argument; import org.etsi.mts.tdl.execution.java.tri.Connection; import org.etsi.mts.tdl.execution.java.tri.Data; import org.etsi.mts.tdl.execution.java.tri.Receiver; import org.etsi.mts.tdl.execution.java.tri.Reporter; import org.etsi.mts.tdl.execution.java.tri.SystemAdapter; import org.etsi.mts.tdl.execution.java.tri.Validator; Loading @@ -39,12 +37,10 @@ public class HttpSystemAdapter implements SystemAdapter { private ObjectMapper mapper; private String baseUri = BASE_URI; // private URI uri = URI.create(baseUri); private Connection[] connections; private Queue<HttpResponse<String>> unhandledResponses = new ConcurrentLinkedQueue<>(); private List<Receiver> receivers = Collections.synchronizedList(new ArrayList<>()); public HttpSystemAdapter(Validator validator, Reporter reporter) { this.validator = validator; Loading @@ -53,9 +49,8 @@ public class HttpSystemAdapter implements SystemAdapter { @Override public void configure(Connection[] connections) { // TODO Auto-generated method stub // XXX // TODO multiple connections this.connections = connections; builder = HttpClient.newBuilder(); Loading @@ -69,8 +64,11 @@ public class HttpSystemAdapter implements SystemAdapter { mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); // mapper.registerModule(new JavaTimeModule()); // mapper.registerModule(new JsonNullableModule()); /* * TODO optional modules * mapper.registerModule(new JavaTimeModule()); * mapper.registerModule(new JsonNullableModule()); */ } private void handleResponse(HttpResponse<String> response, Throwable t) { Loading @@ -92,8 +90,8 @@ public class HttpSystemAdapter implements SystemAdapter { private void applyDefaults(HttpRequest.Builder requestBuilder) { requestBuilder.header("Content-Type", "application/json"); requestBuilder.header("Accept", "application/json"); // XXX requestBuilder.header("Cookie", "usertoken=" + AUTH); // TODO configuration (e.g. auth) // requestBuilder.header("Cookie", "usertoken=" + AUTH); } @Override Loading @@ -103,7 +101,7 @@ public class HttpSystemAdapter implements SystemAdapter { HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(); applyDefaults(requestBuilder); // XXX parameters // TODO parameters try { requestBuilder.uri(URI.create(baseUri + httpData.uri)); Loading Loading @@ -138,7 +136,7 @@ public class HttpSystemAdapter implements SystemAdapter { response = unhandledResponses.peek(); } //XXX //TODO logging reporter.comment("Incoming: " + response.body()); try { Loading Loading @@ -176,12 +174,6 @@ public class HttpSystemAdapter implements SystemAdapter { return null; } @Override public Data ignoreUntil(Data expected, Connection connection) { // XXX return null; } @Override public Data call(Object operation, Argument[] arguments, Data expectedReturn, Data expectedException, Connection connection) { Loading @@ -198,16 +190,5 @@ public class HttpSystemAdapter implements SystemAdapter { throw new UnsupportedOperationException("Procedure-based communication is not supported by this adapter."); } @Override public void addReceiver(Receiver r) { receivers.add(r); } @Override public void removeReceiver(Receiver r) { receivers.remove(r); } private static String BASE_URI = "https://test.valto.fi/valto-360-api"; private static String AUTH = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxOSIsImV4cCI6MTY4NTcxNjU1OCwiaWF0IjoxNjg1NjMwMTU4fQ.y03piKrOIeypj0esuHf1tDSLlbvJPqC3z6eMZaBxtifHNvFY0b04mc8FSjEZzxXa92j6QEVw29xn7AKuTOzEKA"; private static String BASE_URI = "<todo>"; } No newline at end of file
plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/rt/core/ReceiverHub.java +13 −11 Original line number Diff line number Diff line Loading @@ -59,10 +59,14 @@ public class ReceiverHub { if (currentlyExpecting.anyReceiver) { // Switch to the first one for reporting synchronized (expecting) { if (expecting.size() > 0) for (Expectable e: expecting) if (!e.ignoreUnmatched) { currentlyExpecting = expecting.get(0); break; } } } // XXX this is not correct expecting.clear(); synchronized (currentlyExpecting) { currentlyExpecting.received = data; Loading @@ -72,6 +76,7 @@ public class ReceiverHub { } catch (InterruptedException e) { } catch (AssertionError e) { if (!currentlyExpecting.ignoreUnmatched) currentlyExpecting.error = e; } } Loading @@ -82,8 +87,8 @@ public class ReceiverHub { this.thread.interrupt(); } public Data receive(Data expected) throws StopException { Expectable expectable = new Expectable(expected); public Data receive(Data expected, boolean ignoreUntil) { Expectable expectable = new Expectable(expected, ignoreUntil); synchronized (expecting) { expecting.add(expectable); expecting.notifyAll(); Loading @@ -104,11 +109,6 @@ public class ReceiverHub { } } public Data ignoreUntil(Data expected) { // XXX return null; } public Data call(Object operation, Argument[] arguments, Data expectedReturn, Data expectedException) { // XXX return null; Loading @@ -118,10 +118,12 @@ public class ReceiverHub { Data expected; Data received; AssertionError error; boolean ignoreUnmatched = false; boolean anyReceiver = false; public Expectable(Data expected) { public Expectable(Data expected, boolean ignoreUnmatched) { this.expected = expected; this.ignoreUnmatched = ignoreUnmatched; this.anyReceiver = expected == null; } } Loading
plugins/org.etsi.mts.tdl.execution.java/runtime-src/org/etsi/mts/tdl/execution/java/rt/core/TestControl.java +9 −14 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ public class TestControl { anyReceiver.callable = new ExecutionCallable() { @Override public ExecutionResult call() throws Exception { Data data = hub.receive(null); Data data = hub.receive(null, false); return data != null ? new InteractionResult(data) : null; } Loading Loading @@ -227,25 +227,20 @@ public class TestControl { } public ExecutionCallable receive(Data expected, Connection connection) { ExecutionCallableWithDefaults c = new ExecutionCallableWithDefaults() { @Override public ExecutionResult call() throws Exception { Data data = getReceiver(connection).receive(expected); return data != null ? new InteractionResult(data) : null; } }; return c; return receive(expected, connection, false); } public ExecutionCallable trigger(Data expected, Connection connection) { // XXX Receiver return receive(expected, connection, true); } public ExecutionCallable receive(Data expected, Connection connection, boolean isTrigger) { ExecutionCallableWithDefaults c = new ExecutionCallableWithDefaults() { @Override public ExecutionResult call() throws Exception { Data data = getReceiver(connection).ignoreUntil(expected); if (Thread.interrupted()) return null; return new InteractionResult(data); Data data = getReceiver(connection).receive(expected, isTrigger); return data != null ? new InteractionResult(data) : null; } }; return c; Loading