This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit d55b7eccef6773eb94e6e0309237ec870c0544c4
Author: Christofer Dutz <christofer.d...@c-ware.de>
AuthorDate: Sun Mar 11 11:53:47 2018 +0100

    - Adjusted the uri pattern for the ADS driver
---
 .../org/apache/plc4x/java/ads/AdsPlcDriver.java    |  9 ++--
 .../apache/plc4x/java/ads/AdsPlcDriverTest.java    | 48 +++++++++++-----------
 2 files changed, 28 insertions(+), 29 deletions(-)

diff --git 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/AdsPlcDriver.java 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/AdsPlcDriver.java
index 36284f3..28af628 100644
--- 
a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/AdsPlcDriver.java
+++ 
b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/AdsPlcDriver.java
@@ -45,9 +45,9 @@ public class AdsPlcDriver implements PlcDriver {
             + "(/"
             + "(?<sourceAmsNetId>" + AmsNetId.AMS_NET_ID_PATTERN + 
"):(?<sourceAmsPort>" + AmsPort.AMS_PORT_PATTERN + ")"
             + ")?");
-    public static final Pattern INET_ADDRESS_PATTERN = 
Pattern.compile("(?<host>tcp:[\\w.]+)(:(?<port>\\d*))?");
-    public static final Pattern SERIAL_PATTERN = 
Pattern.compile("(?<serialDefinition>serial:.*)");
-    public static final Pattern ADS_URI_PATTERN = Pattern.compile("^ads:/?/?(" 
+ INET_ADDRESS_PATTERN + "|" + SERIAL_PATTERN + ")/" + ADS_ADDRESS_PATTERN);
+    public static final Pattern INET_ADDRESS_PATTERN = 
Pattern.compile("tcp://(?<host>[\\w.]+)(:(?<port>\\d*))?");
+    public static final Pattern SERIAL_PATTERN = 
Pattern.compile("serial://(?<serialDefinition>.*)");
+    public static final Pattern ADS_URI_PATTERN = Pattern.compile("^ads:(" + 
INET_ADDRESS_PATTERN + "|" + SERIAL_PATTERN + ")/" + ADS_ADDRESS_PATTERN);
 
     private AdsConnectionFactory adsConnectionFactory;
 
@@ -88,8 +88,7 @@ public class AdsPlcDriver implements PlcDriver {
         AmsPort sourceAmsPort = StringUtils.isNotBlank(sourceAmsPortString) ? 
AmsPort.of(sourceAmsPortString) : null;
 
         if (serialDefinition != null) {
-            String serialPort = 
serialDefinition.substring(serialDefinition.indexOf(':'));
-            return adsConnectionFactory.adsSerialPlcConnectionOf(serialPort, 
targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort);
+            return 
adsConnectionFactory.adsSerialPlcConnectionOf(serialDefinition, targetAmsNetId, 
targetAmsPort, sourceAmsNetId, sourceAmsPort);
         } else {
             try {
                 return 
adsConnectionFactory.adsTcpPlcConnectionOf(InetAddress.getByName(host), port, 
targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort);
diff --git 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsPlcDriverTest.java
 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsPlcDriverTest.java
index d873f6a..e1eb30d 100644
--- 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsPlcDriverTest.java
+++ 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsPlcDriverTest.java
@@ -48,31 +48,31 @@ public class AdsPlcDriverTest {
         assertMatching(ADS_ADDRESS_PATTERN, "0.0.0.0.0.0:13");
         assertMatching(ADS_ADDRESS_PATTERN, "0.0.0.0.0.0:13/0.0.0.0.0.0:13");
 
-        assertMatching(INET_ADDRESS_PATTERN, "localhost");
-        assertMatching(INET_ADDRESS_PATTERN, "localhost:3131");
-        assertMatching(INET_ADDRESS_PATTERN, "www.google.de");
-        assertMatching(INET_ADDRESS_PATTERN, "www.google.de:443");
-
-        assertMatching(SERIAL_PATTERN, "serial:/dev/com1");
-        assertMatching(SERIAL_PATTERN, "serial:COM1");
-        assertMatching(SERIAL_PATTERN, "serial:/dev/ttyUSB0");
-
-        assertMatching(ADS_URI_PATTERN, "ads://www.google.de/0.0.0.0.0.0:13");
-        assertMatching(ADS_URI_PATTERN, 
"ads://www.google.de:443/0.0.0.0.0.0:13");
-        assertMatching(ADS_URI_PATTERN, 
"ads://serial:/dev/com1/0.0.0.0.0.0:13");
-        assertMatching(ADS_URI_PATTERN, "ads://serial:COM1/0.0.0.0.0.0:13");
-        assertMatching(ADS_URI_PATTERN, 
"ads://serial:/dev/ttyUSB0/0.0.0.0.0.0:13");
+        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(SERIAL_PATTERN, "serial:///dev/com1");
+        assertMatching(SERIAL_PATTERN, "serial://COM1");
+        assertMatching(SERIAL_PATTERN, "serial:///dev/ttyUSB0");
+
+        assertMatching(ADS_URI_PATTERN, 
"ads:tcp://www.google.de/0.0.0.0.0.0:13");
+        assertMatching(ADS_URI_PATTERN, 
"ads:tcp://www.google.de:443/0.0.0.0.0.0:13");
+        assertMatching(ADS_URI_PATTERN, 
"ads:serial:///dev/com1/0.0.0.0.0.0:13");
+        assertMatching(ADS_URI_PATTERN, "ads:serial://COM1/0.0.0.0.0.0:13");
+        assertMatching(ADS_URI_PATTERN, 
"ads:serial:///dev/ttyUSB0/0.0.0.0.0.0:13");
     }
 
     @Test
     public void testDriverWithCompleteUrls() throws Exception {
         AdsPlcDriver SUT = new AdsPlcDriver(mock(AdsConnectionFactory.class));
         Stream.of(
-            "ads://www.google.de/0.0.0.0.0.0:13",
-            "ads://www.google.de:443/0.0.0.0.0.0:13",
-            "ads://serial:/dev/com1/0.0.0.0.0.0:13",
-            "ads://serial:COM1/0.0.0.0.0.0:13",
-            "ads://serial:/dev/ttyUSB0/0.0.0.0.0.0:13"
+            "ads:tcp://www.google.de/0.0.0.0.0.0:13",
+            "ads:tcp://www.google.de:443/0.0.0.0.0.0:13",
+            "ads:serial:///dev/com1/0.0.0.0.0.0:13",
+            "ads:serial://COM1/0.0.0.0.0.0:13",
+            "ads:serial:///dev/ttyUSB0/0.0.0.0.0.0:13"
         ).forEach(url -> {
             try {
                 SUT.connect(url);
@@ -91,7 +91,7 @@ public class AdsPlcDriverTest {
     @Test
     public void getConnection() throws Exception {
         AdsTcpPlcConnection adsConnection = (AdsTcpPlcConnection)
-            new PlcDriverManager().getConnection("ads://localhost:" + 
tcpHexDumper.getPort() + "/0.0.0.0.0.0:13");
+            new PlcDriverManager().getConnection("ads:tcp://localhost:" + 
tcpHexDumper.getPort() + "/0.0.0.0.0.0:13");
         assertEquals(adsConnection.getTargetAmsNetId().toString(), 
"0.0.0.0.0.0");
         assertEquals(adsConnection.getTargetAmsPort().toString(), "13");
         adsConnection.close();
@@ -99,18 +99,18 @@ public class AdsPlcDriverTest {
 
     @Test(expected = PlcConnectionException.class)
     public void getConnectionNoAuthSupported() throws Exception {
-        new PlcDriverManager().getConnection("ads://localhost:" + 
tcpHexDumper.getPort() + "/0.0.0.0.0.0:13",
+        new PlcDriverManager().getConnection("ads:tcp://localhost:" + 
tcpHexDumper.getPort() + "/0.0.0.0.0.0:13",
             new PlcUsernamePasswordAuthentication("admin", "admin"));
     }
 
     @Test(expected = PlcConnectionException.class)
     public void getConnectionUnknownHost() throws Exception {
-        new 
PlcDriverManager().getConnection("ads://nowhere:8080/0.0.0.0.0.0:13");
+        new 
PlcDriverManager().getConnection("ads:tcp://nowhere:8080/0.0.0.0.0.0:13");
     }
 
     @Test(expected = PlcConnectionException.class)
     public void getConnectionUnknownPort() throws Exception {
-        new 
PlcDriverManager().getConnection("ads://nowhere:unknown/0.0.0.0.0.0:13");
+        new 
PlcDriverManager().getConnection("ads:tcp://nowhere:unknown/0.0.0.0.0.0:13");
     }
 
     /**
@@ -120,7 +120,7 @@ public class AdsPlcDriverTest {
      */
     @Test(expected = PlcConnectionException.class)
     public void getConnectionInvalidUrl() throws PlcException {
-        new PlcDriverManager().getConnection("ads://localhost/hurz/2");
+        new PlcDriverManager().getConnection("ads:tcp://localhost/hurz/2");
     }
 
     @Test

-- 
To stop receiving notification emails like this one, please contact
cd...@apache.org.

Reply via email to