This is an automated email from the ASF dual-hosted git repository.
hutcheb pushed a commit to branch fix/PLC4X-303
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/fix/PLC4X-303 by this push:
new db42b0b Add DriverTestSuite.xml tests
db42b0b is described below
commit db42b0be2647dbba52f3859d73c9a8d7ebc99c5f
Author: hutcheb <[email protected]>
AuthorDate: Tue Nov 9 05:33:59 2021 +1000
Add DriverTestSuite.xml tests
---
plc4j/drivers/opcua/pom.xml | 15 ++
.../apache/plc4x/java/opcua/OpcuaPlcDriver.java | 2 +-
.../plc4x/java/opcua/context/SecureChannel.java | 5 +-
.../org/apache/plc4x/java/opcua/OpcuaDriverIT.java | 29 ++++
.../apache/plc4x/java/opcua/PcapReplayTests.java | 55 +++++++
.../resources/protocols/opcua/DriverTestsuite.xml | 168 +++++++++++++++++++++
6 files changed, 271 insertions(+), 3 deletions(-)
diff --git a/plc4j/drivers/opcua/pom.xml b/plc4j/drivers/opcua/pom.xml
index ea4e250..f6e7e1a 100644
--- a/plc4j/drivers/opcua/pom.xml
+++ b/plc4j/drivers/opcua/pom.xml
@@ -130,11 +130,20 @@
<artifactId>plc4j-api</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
+
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-spi</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-test-utils</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
@@ -202,6 +211,12 @@
<artifactId>bcprov-jdk15on</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-test-utils</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<dependencyManagement>
diff --git
a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
index 088853c..da32c4f 100644
---
a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
+++
b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
@@ -51,7 +51,7 @@ public class OpcuaPlcDriver extends
GeneratedDriverBase<OpcuaAPU> {
private static final Logger LOGGER =
LoggerFactory.getLogger(OpcuaPlcDriver.class);
- public static final Pattern INET_ADDRESS_PATTERN =
Pattern.compile("(:(?<transportCode>tcp))?://" +
+ public static final Pattern INET_ADDRESS_PATTERN =
Pattern.compile("(:(?<transportCode>[a-z0-9]*))?://" +
"(?<transportHost>[\\w.-]+)(:" +
"(?<transportPort>\\d*))?");
diff --git
a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
index 9daf885..6e58b3a 100644
---
a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
+++
b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
@@ -261,13 +261,14 @@ public class SecureChannel {
DEFAULT_MAX_MESSAGE_SIZE,
DEFAULT_MAX_CHUNK_COUNT,
this.endpoint);
-
+ System.out.print(hello.toString());
Consumer<Integer> requestConsumer = t -> {
context.sendRequest(new OpcuaAPU(hello))
.expectResponse(OpcuaAPU.class, REQUEST_TIMEOUT)
.check(p -> p.getMessage() instanceof OpcuaAcknowledgeResponse)
.unwrap(p -> (OpcuaAcknowledgeResponse) p.getMessage())
.handle(opcuaAcknowledgeResponse -> {
+ System.out.print(opcuaAcknowledgeResponse.toString());
sendBufferSize =
Math.min(opcuaAcknowledgeResponse.getReceiveBufferSize(),
DEFAULT_SEND_BUFFER_SIZE);
maxMessageSize =
Math.min(opcuaAcknowledgeResponse.getMaxMessageSize(),
DEFAULT_MAX_MESSAGE_SIZE);
onConnectOpenSecureChannel(context,
opcuaAcknowledgeResponse);
@@ -1200,7 +1201,7 @@ public class SecureChannel {
* @return true if this endpoint matches our configuration
* @throws PlcRuntimeException - If the returned endpoint string doesn't
match the format expected
*/
- public boolean isEndpoint(EndpointDescription endpoint) throws
PlcRuntimeException {
+ private boolean isEndpoint(EndpointDescription endpoint) throws
PlcRuntimeException {
// Split up the connection string into it's individual segments.
Matcher matcher =
URI_PATTERN.matcher(endpoint.getEndpointUrl().getStringValue());
if (!matcher.matches()) {
diff --git
a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaDriverIT.java
b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaDriverIT.java
new file mode 100644
index 0000000..a7214b2
--- /dev/null
+++
b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaDriverIT.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.opcua;
+
+import org.apache.plc4x.test.driver.DriverTestsuiteRunner;
+
+public class OpcuaDriverIT extends DriverTestsuiteRunner {
+
+ public OpcuaDriverIT() {
+ super("/protocols/opcua/DriverTestsuite.xml", true);
+ }
+
+}
diff --git
a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/PcapReplayTests.java
b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/PcapReplayTests.java
new file mode 100644
index 0000000..3d4e187
--- /dev/null
+++
b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/PcapReplayTests.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.opcua;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.eclipse.milo.examples.server.ExampleServer;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.fail;
+
+public class PcapReplayTests {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(OpcuaPlcDriverTest.class);
+
+ @BeforeAll
+ public static void setup() {
+
+ }
+
+ @AfterAll
+ public static void tearDown() {
+
+ }
+
+ @Test
+ public void connectionNoParams(){
+
+ }
+}
diff --git
a/protocols/opcua/src/test/resources/protocols/opcua/DriverTestsuite.xml
b/protocols/opcua/src/test/resources/protocols/opcua/DriverTestsuite.xml
new file mode 100644
index 0000000..d26d59d
--- /dev/null
+++ b/protocols/opcua/src/test/resources/protocols/opcua/DriverTestsuite.xml
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+<test:driver-testsuite
xmlns:test="https://plc4x.apache.org/schemas/driver-testsuite.xsd"
+ bigEndian="false">
+
+ <!-- https://base64.guru/converter/encode/hex -->
+
+ <name>Opcua</name>
+
+ <protocolName>opcua</protocolName>
+ <outputFlavor>read-write</outputFlavor>
+
+ <driver-name>opcua</driver-name>
+
+ <testcase>
+ <name>Hello Request Response</name>
+ <steps>
+ <outgoing-plc-message name="Send Opcua Hello Packet">
+ <parser-arguments>
+ <response>false</response>
+ </parser-arguments>
+ <MessagePDU>
+ <messageType dataType="string" bitLength="24"
encoding="UTF-8">HEL</messageType>
+ <OpcuaHelloRequest>
+ <chunk dataType="string" bitLength="8" encoding="UTF-8">F</chunk>
+ <messageSize dataType="int" bitLength="32">52</messageSize>
+ <version dataType="int" bitLength="32">0</version>
+ <receiveBufferSize dataType="int"
bitLength="32">65535</receiveBufferSize>
+ <sendBufferSize dataType="int"
bitLength="32">65535</sendBufferSize>
+ <maxMessageSize dataType="int"
bitLength="32">2097152</maxMessageSize>
+ <maxChunkCount dataType="int" bitLength="32">64</maxChunkCount>
+ <endpoint>
+ <PascalString>
+ <sLength dataType="int" bitLength="32">20</sLength>
+ <stringValue dataType="string" bitLength="160"
encoding="'UTF-8'">opc.test://hurz:null</stringValue>
+ </PascalString>
+ </endpoint>
+ </OpcuaHelloRequest>
+ </MessagePDU>
+ </outgoing-plc-message>
+ <incoming-plc-message name="Receive Modbus Input-Register Read Response">
+ <parser-arguments>
+ <response>true</response>
+ </parser-arguments>
+ <MessagePDU>
+ <messageType dataType="string" bitLength="24">ACK</messageType>
+ <OpcuaAcknowledgeResponse>
+ <chunk dataType="string" bitLength="8">F</chunk>
+ <messageSize dataType="int" bitLength="32">24</messageSize>
+ <version dataType="int" bitLength="32">0</version>
+ <receiveBufferSize dataType="int"
bitLength="32">65535</receiveBufferSize>
+ <sendBufferSize dataType="int"
bitLength="32">65535</sendBufferSize>
+ <maxMessageSize dataType="int"
bitLength="32">2097152</maxMessageSize>
+ <maxChunkCount dataType="int" bitLength="32">64</maxChunkCount>
+ </OpcuaAcknowledgeResponse>
+ </MessagePDU>
+ </incoming-plc-message>
+ <outgoing-plc-message name="Send Opcua Open Request">
+ <parser-arguments>
+ <response>false</response>
+ </parser-arguments>
+ <MessagePDU>
+ <messageType dataType="string" bitLength="24"
encoding="UTF-8">OPN</messageType>
+ <OpcuaOpenRequest>
+ <chunk dataType="string" bitLength="8" encoding="UTF-8">F</chunk>
+ <messageSize dataType="int" bitLength="32">132</messageSize>
+ <secureChannelId dataType="int" bitLength="32">0</secureChannelId>
+ <endpoint>
+ <PascalString>
+ <sLength dataType="int" bitLength="32">47</sLength>
+ <stringValue dataType="string" bitLength="376"
encoding="'UTF-8'">http://opcfoundation.org/UA/SecurityPolicy#None</stringValue>
+ </PascalString>
+ </endpoint>
+ <senderCertificate>
+ <PascalByteString>
+ <stringLength dataType="int" bitLength="32">-1</stringLength>
+ <stringValue isList="true">
+ </stringValue>
+ </PascalByteString>
+ </senderCertificate>
+ <receiverCertificateThumbprint>
+ <PascalByteString>
+ <stringLength dataType="int" bitLength="32">-1</stringLength>
+ <stringValue isList="true">
+ </stringValue>
+ </PascalByteString>
+ </receiverCertificateThumbprint>
+ <sequenceNumber dataType="int" bitLength="32">1</sequenceNumber>
+ <requestId dataType="int" bitLength="32">1</requestId>
+ <message isList="true">
+ <value dataType="int" bitLength="8">1</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">-66</value>
+ <value dataType="int" bitLength="8">1</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">13</value>
+ <value dataType="int" bitLength="8">-12</value>
+ <value dataType="int" bitLength="8">3</value>
+ <value dataType="int" bitLength="8">-44</value>
+ <value dataType="int" bitLength="8">-44</value>
+ <value dataType="int" bitLength="8">-41</value>
+ <value dataType="int" bitLength="8">1</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">16</value>
+ <value dataType="int" bitLength="8">39</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">1</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">-1</value>
+ <value dataType="int" bitLength="8">0</value>
+ <value dataType="int" bitLength="8">81</value>
+ <value dataType="int" bitLength="8">37</value>
+ <value dataType="int" bitLength="8">2</value>
+ </message>
+ </OpcuaOpenRequest>
+ </MessagePDU>
+ </outgoing-plc-message>
+ </steps>
+ </testcase>
+
+</test:driver-testsuite>