You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2020/01/29 12:57:41 UTC
[plc4x] 04/06: [added] added test case for reading a full set of
variables
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch fixes-mathi
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 7c8b9120e7ac52f1151dd2e7a56ad8875d010edb
Author: Matthias Milan Strljic <ma...@gmail.com>
AuthorDate: Tue Jan 28 22:32:23 2020 +0100
[added] added test case for reading a full set of variables
Signed-off-by: Matthias Milan Strljic <Ma...@googlemail.com>
---
.../apache/plc4x/java/opcua/ManualPLC4XOpcua.java | 2 +-
.../plc4x/java/opcua/OpcuaPlcDriverTest.java | 105 +++++++++++++++++++++
2 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
index ce35fe9..57bf76a 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
@@ -46,7 +46,6 @@ import java.util.function.Consumer;
* The current version is tested against a public server, which is to be replaced later by a separate instance of the Milo framework.
* Afterwards the code represented here will be used as an example for the introduction page.
* <p>
- * TODO: replace current public server with local Milo instance
*
* Created by Matthias Milan Strljic on 10.05.2019
*/
@@ -112,6 +111,7 @@ public class ManualPLC4XOpcua {
PlcReadRequest request = builder.build();
PlcReadResponse response = opcuaConnection.read(request).get();
+
Collection coll = response.getAllStrings("String");
PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
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 7b3d951..8b34242 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
@@ -18,6 +18,13 @@
*/
package org.apache.plc4x.java.opcua;
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.opcua.connection.OpcuaTcpPlcConnection;
+import org.eclipse.milo.examples.server.ExampleServer;
+import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -30,13 +37,111 @@ import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
* Created by Matthias Milan Strljic on 10.05.2019
*/
public class OpcuaPlcDriverTest {
+ // Read only variables of milo example server of version 3.6
+ private static final String BOOL_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Boolean";
+ private static final String BYTE_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Byte";
+ private static final String DOUBLE_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Double";
+ private static final String FLOAT_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Float";
+ private static final String INT16_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Int16";
+ private static final String INT32_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Int32";
+ private static final String INT64_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Int64";
+ private static final String INTEGER_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Integer";
+ private static final String SBYTE_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/SByte";
+ private static final String STRING_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/String";
+ private static final String UINT16_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/UInt16";
+ private static final String UINT32_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/UInt32";
+ private static final String UINT64_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/UInt64";
+ private static final String UINTEGER_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/UInteger";
+ private static final String DOES_NOT_EXIST_IDENTIFIER_READ_WRITE = "ns=2;i=12512623";
+ // At the moment not used in PLC4X or in the OPC UA driver
+ private static final String BYTE_STRING_IDENTIFIER_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/ByteString";
+ private static final String DATE_TIME_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/DateTime";
+ private static final String DURATION_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Duration";
+ private static final String GUID_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Guid";
+ private static final String LOCALICED_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/LocalizedText";
+ private static final String NODE_ID_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/NodeId";
+ private static final String QUALIFIED_NAM_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/QualifiedName";
+ private static final String UTC_TIME_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/UtcTime";
+ private static final String VARIANT_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/Variant";
+ private static final String XML_ELEMENT_READ_WRITE = "ns=2;s=HelloWorld/ScalarTypes/XmlElement";
+ // Address of local milo server
+ String miloLocalAddress = "127.0.0.1:12686/milo";
+ //Tcp pattern of OPC UA
+ String opcPattern = "opcua:tcp://";
+ private ExampleServer exampleServer;
+
+
+
@BeforeEach
public void before() {
+ try {
+ exampleServer = new ExampleServer();
+ exampleServer.startup().get();
+ } catch (Exception e) {
+
+ }
}
@AfterEach
public void after() {
+ try {
+ exampleServer.shutdown().get();
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void readVariables() {
+ try {
+ OpcuaTcpPlcConnection opcuaConnection = (OpcuaTcpPlcConnection)
+ new PlcDriverManager().getConnection(opcPattern + miloLocalAddress);
+ assert opcuaConnection.isConnected();
+
+ PlcReadRequest.Builder builder = opcuaConnection.readRequestBuilder();
+ builder.addItem("Bool", BOOL_IDENTIFIER_READ_WRITE);
+ builder.addItem("Byte", BYTE_IDENTIFIER_READ_WRITE);
+ builder.addItem("Double", DOUBLE_IDENTIFIER_READ_WRITE);
+ builder.addItem("Float", FLOAT_IDENTIFIER_READ_WRITE);
+ builder.addItem("Int16", INT16_IDENTIFIER_READ_WRITE);
+ builder.addItem("Int32", INT32_IDENTIFIER_READ_WRITE);
+ builder.addItem("Int64", INT64_IDENTIFIER_READ_WRITE);
+ builder.addItem("Integer", INTEGER_IDENTIFIER_READ_WRITE);
+ builder.addItem("SByte", SBYTE_IDENTIFIER_READ_WRITE);
+ builder.addItem("String", STRING_IDENTIFIER_READ_WRITE);
+ builder.addItem("UInt16", UINT16_IDENTIFIER_READ_WRITE);
+ builder.addItem("UInt32", UINT32_IDENTIFIER_READ_WRITE);
+ builder.addItem("UInt64", UINT64_IDENTIFIER_READ_WRITE);
+ builder.addItem("UInteger", UINTEGER_IDENTIFIER_READ_WRITE);
+
+ builder.addItem("DoesNotExists", DOES_NOT_EXIST_IDENTIFIER_READ_WRITE);
+
+ PlcReadRequest request = builder.build();
+ PlcReadResponse response = opcuaConnection.read(request).get();
+ assert response.getResponseCode("Bool").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Byte").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Double").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Float").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Int16").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Int32").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Int64").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("Integer").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("SByte").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("String").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("UInt16").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("UInt32").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("UInt64").equals(PlcResponseCode.OK);
+ assert response.getResponseCode("UInteger").equals(PlcResponseCode.OK);
+
+ assert response.getResponseCode("DoesNotExists").equals(PlcResponseCode.NOT_FOUND);
+
+ opcuaConnection.close();
+ assert !opcuaConnection.isConnected();
+
+ } catch (Exception e) {
+ Assert.fail("Exception during readVariables Test EXCEPTION: " + e.getMessage());
+ }
}
@Test