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 2019/05/19 19:39:04 UTC
[plc4x] 05/07: Added test class bodies and renamed consistently
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 2b98afadd733c26b33998089e93b97c3a1bf8e9d
Author: Mathi <de...@googlemail.com>
AuthorDate: Tue May 14 00:17:38 2019 +0200
Added test class bodies and renamed consistently
---
.../{OPCUAPlcDriver.java => OpcuaPlcDriver.java} | 12 ++--
...Connection.java => BaseOpcuaPlcConnection.java} | 8 +--
...ionFactory.java => OpcuaConnectionFactory.java} | 8 +--
...cConnection.java => OpcuaTcpPlcConnection.java} | 25 ++++----
.../plc4x/java/opcua/protocol/OpcuaField.java | 2 +-
.../protocol/{model => }/OpcuaPlcFieldHandler.java | 3 +-
.../{model => }/OpcuaSubsriptionHandle.java | 6 +-
.../services/org.apache.plc4x.java.spi.PlcDriver | 2 +-
...ManualPLC4XOPCUA.java => ManualPLC4XOpcua.java} | 17 +++---
.../plc4x/java/opcua/OpcuaPlcDriverTest.java | 66 ++++++++++++++++++++++
.../org/apache/plc4x/java/opcua/UtilsTest.java} | 29 +++++-----
.../connection/OpcuaTcpPlcConnectionTest.java} | 23 ++++----
.../plc4x/java/opcua/protocol/OpcuaFieldTest.java} | 38 ++++++++-----
.../opcua/protocol/OpcuaPlcFieldHandlerTest.java} | 25 ++++----
.../protocol/OpcuaSubscriptionHandleTest.java} | 25 ++++----
15 files changed, 178 insertions(+), 111 deletions(-)
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
similarity index 90%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
index 271365e..ef5f985 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
@@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.authentication.PlcAuthentication;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.opcua.connection.OPCUAConnectionFactory;
+import org.apache.plc4x.java.opcua.connection.OpcuaConnectionFactory;
import org.apache.plc4x.java.spi.PlcDriver;
import java.net.InetAddress;
@@ -37,20 +37,20 @@ import java.util.regex.Pattern;
* Implementation of the OPC UA protocol, based on:
* - Eclipse Milo (https://github.com/eclipse/milo)
*/
-public class OPCUAPlcDriver implements PlcDriver {
+public class OpcuaPlcDriver implements PlcDriver {
public static final Pattern INET_ADDRESS_PATTERN = Pattern.compile("tcp://(?<host>[\\w.-]+)(:(?<port>\\d*))?");
public static final Pattern OPCUA_URI_PATTERN = Pattern.compile("^opcua:(" + INET_ADDRESS_PATTERN + ")?" + "(?<params>/[\\w/]+)?");
private static final int requestTimeout = 10000;
- private OPCUAConnectionFactory opcuaConnectionFactory;
+ private OpcuaConnectionFactory opcuaConnectionFactory;
- public OPCUAPlcDriver() {
- this.opcuaConnectionFactory = new OPCUAConnectionFactory();
+ public OpcuaPlcDriver() {
+ this.opcuaConnectionFactory = new OpcuaConnectionFactory();
}
- public OPCUAPlcDriver(OPCUAConnectionFactory opcuaConnectionFactory) {
+ public OpcuaPlcDriver(OpcuaConnectionFactory opcuaConnectionFactory) {
this.opcuaConnectionFactory = opcuaConnectionFactory;
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
similarity index 93%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
index 26cbb09..0585e82 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
@@ -27,16 +27,16 @@ import org.apache.plc4x.java.api.messages.PlcUnsubscriptionRequest;
import org.apache.plc4x.java.api.messages.PlcWriteRequest;
import org.apache.plc4x.java.base.connection.AbstractPlcConnection;
import org.apache.plc4x.java.base.messages.*;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
+import org.apache.plc4x.java.opcua.protocol.OpcuaPlcFieldHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class BaseOPCUAPlcConnection extends AbstractPlcConnection implements PlcReader, PlcWriter, PlcSubscriber {
+public abstract class BaseOpcuaPlcConnection extends AbstractPlcConnection implements PlcReader, PlcWriter, PlcSubscriber {
- private static final Logger logger = LoggerFactory.getLogger(BaseOPCUAPlcConnection.class);
+ private static final Logger logger = LoggerFactory.getLogger(BaseOpcuaPlcConnection.class);
- BaseOPCUAPlcConnection(String params) {
+ BaseOpcuaPlcConnection(String params) {
if (!StringUtils.isEmpty(params)) {
for (String param : params.split("&")) {
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
similarity index 83%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
index a49669c..84046ad 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
@@ -23,15 +23,15 @@ package org.apache.plc4x.java.opcua.connection;
import java.net.InetAddress;
import java.util.Objects;
-public class OPCUAConnectionFactory {
+public class OpcuaConnectionFactory {
- public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
+ public OpcuaTcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
Objects.requireNonNull(address);
if (port == null) {
- return OPCUATcpPlcConnection.of(address, params, requestTimeout);
+ return OpcuaTcpPlcConnection.of(address, params, requestTimeout);
} else {
- return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
+ return OpcuaTcpPlcConnection.of(address, port, params, requestTimeout);
}
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
similarity index 96%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
index afd89b5..b7de4b6 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
@@ -32,7 +32,7 @@ import org.apache.plc4x.java.base.messages.*;
import org.apache.plc4x.java.base.messages.items.*;
import org.apache.plc4x.java.base.model.SubscriptionPlcField;
import org.apache.plc4x.java.opcua.protocol.OpcuaField;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaSubsriptionHandle;
+import org.apache.plc4x.java.opcua.protocol.OpcuaSubsriptionHandle;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
@@ -70,11 +70,11 @@ import java.util.stream.Collectors;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
-public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
+public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
private static final int OPCUA_DEFAULT_TCP_PORT = 4840;
- private static final Logger logger = LoggerFactory.getLogger(OPCUATcpPlcConnection.class);
+ private static final Logger logger = LoggerFactory.getLogger(OpcuaTcpPlcConnection.class);
private InetAddress address;
private int requestTimeout = 5000;
private int port;
@@ -82,29 +82,30 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
private OpcUaClient client;
private boolean isConnected = false;
private final AtomicLong clientHandles = new AtomicLong(1L);
- private OPCUATcpPlcConnection(InetAddress address, String params, int requestTimeout) {
+
+ private OpcuaTcpPlcConnection(InetAddress address, String params, int requestTimeout) {
this( address, OPCUA_DEFAULT_TCP_PORT, params, requestTimeout);
- logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
+ logger.info("Configured OpcuaTcpPlcConnection with: host-name {}", address.getHostAddress());
}
- public OPCUATcpPlcConnection(InetAddress address, int port, String params, int requestTimeout) {
+ public OpcuaTcpPlcConnection(InetAddress address, int port, String params, int requestTimeout) {
this(params);
- logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
+ logger.info("Configured OpcuaTcpPlcConnection with: host-name {}", address.getHostAddress());
this.address = address;
this.port = port;
this.params = params;
}
- public OPCUATcpPlcConnection(String params) {
+ public OpcuaTcpPlcConnection(String params) {
super(params);
}
- public static OPCUATcpPlcConnection of(InetAddress address, String params, int requestTimeout) {
- return new OPCUATcpPlcConnection(address, params, requestTimeout);
+ public static OpcuaTcpPlcConnection of(InetAddress address, String params, int requestTimeout) {
+ return new OpcuaTcpPlcConnection(address, params, requestTimeout);
}
- public static OPCUATcpPlcConnection of(InetAddress address, int port, String params, int requestTimeout) {
- return new OPCUATcpPlcConnection(address, port, params, requestTimeout);
+ public static OpcuaTcpPlcConnection of(InetAddress address, int port, String params, int requestTimeout) {
+ return new OpcuaTcpPlcConnection(address, port, params, requestTimeout);
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
index 0ac3c9f..cd33c75 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
public class OpcuaField implements PlcField {
- private static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?<namespace>\\d+);(?<identifierType>[isgb])=((?<identifier>\\w+))?");
+ public static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?<namespace>\\d+);(?<identifierType>[isgb])=((?<identifier>\\w+))?");
private final OpcuaIdentifierType identifierType;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
similarity index 98%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
index f265e81..c39a352 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
@@ -18,14 +18,13 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.protocol.model;
+package org.apache.plc4x.java.opcua.protocol;
import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
import org.apache.plc4x.java.api.model.PlcField;
import org.apache.plc4x.java.base.connection.DefaultPlcFieldHandler;
import org.apache.plc4x.java.base.messages.items.*;
-import org.apache.plc4x.java.opcua.protocol.OpcuaField;
import java.math.BigInteger;
import java.util.ArrayList;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
similarity index 94%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
index 582993c..08da653 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
@@ -18,7 +18,7 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.protocol.model;
+package org.apache.plc4x.java.opcua.protocol;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@@ -28,7 +28,7 @@ import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
import org.apache.plc4x.java.api.types.PlcResponseCode;
import org.apache.plc4x.java.base.messages.DefaultPlcSubscriptionEvent;
import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
-import org.apache.plc4x.java.opcua.connection.OPCUATcpPlcConnection;
+import org.apache.plc4x.java.opcua.connection.OpcuaTcpPlcConnection;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
@@ -66,7 +66,7 @@ public class OpcuaSubsriptionHandle implements PlcSubscriptionHandle {
if(value.getStatusCode() != StatusCode.GOOD){
resultCode = PlcResponseCode.NOT_FOUND;
}else{
- stringItem = OPCUATcpPlcConnection.encodeFieldItem(value);
+ stringItem = OpcuaTcpPlcConnection.encodeFieldItem(value);
}
Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> fields = new HashMap<>();
diff --git a/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver b/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
index 860acdc..fe96e3a 100644
--- a/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
+++ b/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.plc4x.java.opcua.OPCUAPlcDriver
+org.apache.plc4x.java.opcua.OpcuaPlcDriver
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
similarity index 94%
rename from plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
rename to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
index f6eb6d5..8d12925 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
@@ -18,7 +18,7 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua;
import org.apache.plc4x.java.PlcDriverManager;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
@@ -28,8 +28,9 @@ import org.apache.plc4x.java.api.model.PlcField;
import org.apache.plc4x.java.api.types.PlcSubscriptionType;
import org.apache.plc4x.java.base.messages.DefaultPlcSubscriptionRequest;
import org.apache.plc4x.java.base.model.SubscriptionPlcField;
+import org.apache.plc4x.java.opcua.connection.OpcuaTcpPlcConnection;
import org.apache.plc4x.java.opcua.protocol.OpcuaField;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
+import org.apache.plc4x.java.opcua.protocol.OpcuaPlcFieldHandler;
import java.math.BigInteger;
import java.time.Duration;
@@ -39,17 +40,15 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.function.Consumer;
-public class ManualPLC4XOPCUA {
+public class ManualPLC4XOpcua {
public static void main(String args[]){
-
-
- OPCUATcpPlcConnection opcuaConnection = null;
+ OpcuaTcpPlcConnection opcuaConnection = null;
OpcuaPlcFieldHandler fieldH = new OpcuaPlcFieldHandler();
PlcField field = fieldH.createField("ns=2;i=10855");
try {
- opcuaConnection = (OPCUATcpPlcConnection)
+ opcuaConnection = (OpcuaTcpPlcConnection)
new PlcDriverManager().getConnection("opcua:tcp://opcua.demo-this.com:51210/UA/SampleServer");
} catch (PlcConnectionException e) {
@@ -82,7 +81,6 @@ public class ManualPLC4XOPCUA {
PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
- /*
wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
wBuilder.addItem("w-Byte", "ns=2;i=10846", (byte)1);
wBuilder.addItem("w-Double", "ns=2;i=10854", (double)0.25);
@@ -97,7 +95,6 @@ public class ManualPLC4XOPCUA {
wBuilder.addItem("w-UInt32", "ns=2;i=10850", (long)21412);
wBuilder.addItem("w-UInt64", "ns=2;i=10852", new BigInteger("1245152"));
wBuilder.addItem("w-UInteger", "ns=2;i=10870", new BigInteger("1245152"));
-*/
PlcWriteRequest writeRequest = wBuilder.build();
PlcWriteResponse wResponse = opcuaConnection.write(writeRequest).get();
@@ -113,7 +110,7 @@ public class ManualPLC4XOPCUA {
PlcConsumerRegistration registration = opcuaConnection.register(consumer, subResp.getSubscriptionHandles());
Thread.sleep(7000);
registration.unregister();
- Thread.sleep(200000);
+ Thread.sleep(20000);
opcuaConnection.close();
} catch (Exception e) {
e.printStackTrace();
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
new file mode 100644
index 0000000..0e0dd01
--- /dev/null
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
@@ -0,0 +1,66 @@
+/*
+ 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.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
+package org.apache.plc4x.java.opcua;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.INET_ADDRESS_PATTERN;
+import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.OPCUA_URI_PATTERN;
+import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
+
+public class OpcuaPlcDriverTest {
+ @BeforeEach
+ public void before() {
+ }
+
+ @AfterEach
+ public void after() {
+
+ }
+
+ @Test
+ public void testOpcuaAddressPattern() {
+
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://localhost");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://localhost:3131");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://www.google.de");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://www.google.de:443");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://127.0.0.1");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://127.0.0.1:251");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://254.254.254.254:1337");
+ assertMatching(INET_ADDRESS_PATTERN, "tcp://254.254.254.254");
+
+
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://localhost");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://localhost:3131");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://www.google.de");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://www.google.de:443");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://127.0.0.1");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://127.0.0.1:251");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://254.254.254.254:1337");
+ assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://254.254.254.254");
+
+
+ }
+
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
similarity index 59%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
index a49669c..bb1851a 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
@@ -6,9 +6,9 @@
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
-
+
+ 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
@@ -18,21 +18,22 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.connection;
-
-import java.net.InetAddress;
-import java.util.Objects;
+package org.apache.plc4x.java.opcua;
-public class OPCUAConnectionFactory {
+import java.util.regex.Pattern;
- public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
- Objects.requireNonNull(address);
+import static org.junit.Assert.fail;
- if (port == null) {
- return OPCUATcpPlcConnection.of(address, params, requestTimeout);
- } else {
- return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
+public class UtilsTest {
+ public static void assertMatching(Pattern pattern, String match) {
+ if (!pattern.matcher(match).matches()) {
+ fail(pattern + "doesn't match " + match);
}
}
+ public static void assertNoMatching(Pattern pattern, String match) {
+ if (pattern.matcher(match).matches()) {
+ fail(pattern + "does match " + match + " but should not");
+ }
+ }
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
similarity index 65%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
index a49669c..0e31f61 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
@@ -6,9 +6,9 @@
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
@@ -20,19 +20,16 @@
*/
package org.apache.plc4x.java.opcua.connection;
-import java.net.InetAddress;
-import java.util.Objects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
-public class OPCUAConnectionFactory {
+public class OpcuaTcpPlcConnectionTest {
+ @BeforeEach
+ public void before() {
+ }
- public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
- Objects.requireNonNull(address);
+ @AfterEach
+ public void after() {
- if (port == null) {
- return OPCUATcpPlcConnection.of(address, params, requestTimeout);
- } else {
- return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
- }
}
-
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java
similarity index 52%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java
index a49669c..f838b45 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java
@@ -6,9 +6,9 @@
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
@@ -18,21 +18,33 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua.protocol;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
+import static org.apache.plc4x.java.opcua.protocol.OpcuaField.ADDRESS_PATTERN;
-import java.net.InetAddress;
-import java.util.Objects;
+public class OpcuaFieldTest {
-public class OPCUAConnectionFactory {
+ @BeforeEach
+ public void before() {
+ }
- public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
- Objects.requireNonNull(address);
+ @AfterEach
+ public void after() {
- if (port == null) {
- return OPCUATcpPlcConnection.of(address, params, requestTimeout);
- } else {
- return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
- }
}
+ @Test
+ public void testOpcuaAddressPattern() {
+
+ assertMatching(ADDRESS_PATTERN, "ns=2;i=10846");
+ assertMatching(ADDRESS_PATTERN, "ns=2;s=test.variable.name.inspect");
+ assertMatching(ADDRESS_PATTERN, "ns=2;g=09087e75-8e5e-499b-954f-f2a8624db28a");
+ assertMatching(ADDRESS_PATTERN, "ns=2;b=asvaewavarahreb==");
+
+ }
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
similarity index 62%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
index a49669c..3153582 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
@@ -6,9 +6,9 @@
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
@@ -18,21 +18,18 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua.protocol;
-import java.net.InetAddress;
-import java.util.Objects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
-public class OPCUAConnectionFactory {
+public class OpcuaPlcFieldHandlerTest {
+ @BeforeEach
+ public void before() {
+ }
- public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
- Objects.requireNonNull(address);
+ @AfterEach
+ public void after() {
- if (port == null) {
- return OPCUATcpPlcConnection.of(address, params, requestTimeout);
- } else {
- return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
- }
}
-
}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
similarity index 62%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
rename to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
index a49669c..bc75d14 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
@@ -6,9 +6,9 @@
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
@@ -18,21 +18,18 @@
* @author Matthias Milan Stlrljic
* Created by Matthias Milan Stlrljic on 10.05.2019
*/
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua.protocol;
-import java.net.InetAddress;
-import java.util.Objects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
-public class OPCUAConnectionFactory {
+public class OpcuaSubscriptionHandleTest {
+ @BeforeEach
+ public void before() {
+ }
- public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
- Objects.requireNonNull(address);
+ @AfterEach
+ public void after() {
- if (port == null) {
- return OPCUATcpPlcConnection.of(address, params, requestTimeout);
- } else {
- return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
- }
}
-
}