You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/08/07 08:22:44 UTC
[plc4x] 05/05: test(plc4j/opcua): cleanup opcua driver test
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit e3293b9fca9f73e43d77c29efbd314d794fc50d9
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Aug 7 10:18:07 2023 +0200
test(plc4j/opcua): cleanup opcua driver test
---
.../plc4x/java/opcua/OpcuaPlcDriverTest.java | 102 +++++++++------------
1 file changed, 42 insertions(+), 60 deletions(-)
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
index 0de19d26db..86e78919f8 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
@@ -41,8 +41,6 @@ import java.util.stream.Stream;
import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.INET_ADDRESS_PATTERN;
import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.URI_PATTERN;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class OpcuaPlcDriverTest {
@@ -176,11 +174,6 @@ public class OpcuaPlcDriverTest {
@Nested
class readWrite {
- @BeforeEach
- public void testForLinux() {
- checkForLinux(); // TODO: seems those do not run on linux
- }
-
@Test
public void readVariables() throws Exception {
PlcConnection opcuaConnection = new DefaultPlcDriverManager().getConnection(tcpConnectionAddress);
@@ -221,33 +214,35 @@ public class OpcuaPlcDriverTest {
PlcReadRequest request = builder.build();
PlcReadResponse response = request.execute().get();
- assertThat(response.getResponseCode("Bool")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Byte")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Double")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Float")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Int16")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Int32")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Int64")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Integer")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("SByte")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("String")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInt16")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInt32")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInt64")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInteger")).isEqualTo(PlcResponseCode.OK);
-
- assertThat(response.getResponseCode("BoolArray")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("ByteArray")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("DoubleArray")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("FloatArray")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Int16Array")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Int32Array")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("Int64Array")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("SByteArray")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("StringArray")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInt16Array")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInt32Array")).isEqualTo(PlcResponseCode.OK);
- assertThat(response.getResponseCode("UInt64Array")).isEqualTo(PlcResponseCode.OK);
+ List.of(
+ "Bool",
+ "Byte",
+ "Double",
+ "Float",
+ "Int16",
+ "Int32",
+ "Int64",
+ "Integer",
+ "SByte",
+ "String",
+ "UInt16",
+ "UInt32",
+ "UInt64",
+ "UInteger",
+ "BoolArray",
+ "ByteArray",
+ "DoubleArray",
+ "FloatArray",
+ "Int16Array",
+ "Int32Array",
+ "Int64Array",
+ "SByteArray",
+ "StringArray",
+ "UInt16Array",
+ "UInt32Array",
+ "UInt64Array"
+ ).forEach(tag -> assertThat(response.getResponseCode(tag)).isEqualTo(PlcResponseCode.OK));
+
assertThat(response.getResponseCode("DoesNotExists")).isEqualTo(PlcResponseCode.NOT_FOUND);
@@ -367,8 +362,8 @@ public class OpcuaPlcDriverTest {
Test added to test the syncronized Trnasactionhandler.
The test originally failed one out of every 5 or so.
*/
-
- public void multipleThreads() {
+ //@Test
+ public void multipleThreads() throws Exception {
class ReadWorker extends Thread {
private final PlcConnection connection;
@@ -420,24 +415,20 @@ public class OpcuaPlcDriverTest {
}
- try {
- PlcConnection opcuaConnection = new DefaultPlcDriverManager().getConnection(tcpConnectionAddress);
- Condition<PlcConnection> is_connected = new Condition<>(PlcConnection::isConnected, "is connected");
- assertThat(opcuaConnection).is(is_connected);
+ PlcConnection opcuaConnection = new DefaultPlcDriverManager().getConnection(tcpConnectionAddress);
+ Condition<PlcConnection> is_connected = new Condition<>(PlcConnection::isConnected, "is connected");
+ assertThat(opcuaConnection).is(is_connected);
- ReadWorker read_worker = new ReadWorker(opcuaConnection);
- WriteWorker write_worker = new WriteWorker(opcuaConnection);
- read_worker.start();
- write_worker.start();
+ ReadWorker read_worker = new ReadWorker(opcuaConnection);
+ WriteWorker write_worker = new WriteWorker(opcuaConnection);
+ read_worker.start();
+ write_worker.start();
- read_worker.join();
- write_worker.join();
+ read_worker.join();
+ write_worker.join();
- opcuaConnection.close();
- assert !opcuaConnection.isConnected();
- } catch (Exception e) {
- fail("Exception during readVariables Test EXCEPTION: " + e.getMessage());
- }
+ opcuaConnection.close();
+ assert !opcuaConnection.isConnected();
}
private final String[] validTCPOPC = {
@@ -481,13 +472,4 @@ public class OpcuaPlcDriverTest {
);
}
- static void checkForLinux() {
- /*assumeTrue(() -> {
- String OS = System.getProperty("os.name").toLowerCase();
- return !OS.contains("nix")
- && !OS.contains("nux")
- && !OS.contains("aix")
- && !OS.contains("mac");
- }, "somehow opcua doesn't run properly on linux");*/
- }
}