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 2018/11/24 19:51:17 UTC

[incubator-plc4x] branch feature/plc4j-scraper updated (57b707b -> 258af1a)

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

jfeinauer pushed a change to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


    from 57b707b  [plc4j-scraper] Working state.
     new c4e4f88  [plc4j-opm] added some tests for entity interceptor
     new f93cf4e  [plc4j] cleanup mock code and moved it completely to driver-bases-test
     new 58a00fa  [plc4j-driver-bases-test] added some tests.
     new e8bf82c  [plc4j-driver-bases-test] enabled some tests.
     new 99d8f27  [plc4j-driver-simulated] added tests and fixed bugs.
     new 258af1a  [plc4j-opm] Minor test coverage.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../simulated/connection/TestFieldHandler.java     |   6 +-
 .../java/simulated/connection/TestFieldItem.java   |   2 +-
 .../java/simulated/SimulatedPlcDriverTest.java     |   7 +
 .../java/simulated/connection/TestDeviceTest.java  |   2 +-
 .../simulated/connection/TestFieldHandlerTest.java | 133 +++++++++++++++
 .../simulated/connection/TestFieldItemTest.java}   |   9 +-
 .../org/apache/plc4x/java/mock/MockDevice.java     |  18 +-
 .../java/org/apache/plc4x/java/mock/MockField.java |  13 ++
 .../apache/plc4x/java/mock/MockFieldHandler.java   |  70 ++++++++
 .../org/apache/plc4x/java/mock/MockFieldItem.java  |   0
 .../org/apache/plc4x/java/mock/MockReader.java     |  51 ------
 .../apache/plc4x/java/mock/PlcMockConnection.java  | 111 ++++++++++--
 .../org/apache/plc4x/java/mock/PlcMockDriver.java  |  22 ++-
 .../plc4x/java/mock/MockFieldHandlerTest.java      | 111 ++++++++++++
 .../apache/plc4x/java/mock/MockFieldItemTest.java} |   9 +-
 .../org/apache/plc4x/java/mock/MockFieldTest.java  |  31 ++--
 .../plc4x/java/mock/PlcMockConnectionTest.java     | 164 ++++++++++++++++++
 .../apache/plc4x/java/mock/PlcMockDriverTest.java  |  53 +++---
 plc4j/protocols/pom.xml                            |   4 +-
 plc4j/protocols/test/pom.xml                       |  51 ------
 .../org/apache/plc4x/java/mock/MockDevice.java     |  50 ------
 .../java/org/apache/plc4x/java/mock/MockField.java |  49 ------
 .../apache/plc4x/java/mock/MockFieldHandler.java   | 103 ------------
 .../apache/plc4x/java/mock/PlcMockConnection.java  | 186 ---------------------
 .../org/apache/plc4x/java/mock/PlcMockDriver.java  |  63 -------
 .../services/org.apache.plc4x.java.spi.PlcDriver   |  19 ---
 plc4j/utils/opm/pom.xml                            |   5 +-
 .../plc4x/java/opm/PlcEntityInterceptor.java       |   1 +
 .../plc4x/java/opm/PlcEntityInterceptorTest.java   |  65 ++++++-
 29 files changed, 753 insertions(+), 655 deletions(-)
 create mode 100644 plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldHandlerTest.java
 copy plc4j/{protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/AdsDeviceNotificationResponseTest.java => drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldItemTest.java} (77%)
 rename plc4j/protocols/{ => driver-bases}/test/src/main/java/org/apache/plc4x/java/mock/MockFieldItem.java (100%)
 delete mode 100644 plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockReader.java
 create mode 100644 plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldHandlerTest.java
 copy plc4j/protocols/{ads/src/test/java/org/apache/plc4x/java/ads/api/commands/AdsDeviceNotificationResponseTest.java => driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldItemTest.java} (78%)
 copy integrations/apache-camel/src/test/java/org/apache/plc4x/camel/Plc4XConsumerTest.java => plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldTest.java (60%)
 create mode 100644 plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java
 rename plc4j/protocols/{ => driver-bases}/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java (71%)
 delete mode 100644 plc4j/protocols/test/pom.xml
 delete mode 100644 plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java
 delete mode 100644 plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockField.java
 delete mode 100644 plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java
 delete mode 100644 plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java
 delete mode 100644 plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java
 delete mode 100644 plc4j/protocols/test/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver


[incubator-plc4x] 04/06: [plc4j-driver-bases-test] enabled some tests.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit e8bf82c96e5ce4f509afb3e4b05236bbfac34bf0
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Nov 24 19:24:10 2018 +0100

    [plc4j-driver-bases-test] enabled some tests.
---
 .../org/apache/plc4x/java/mock/PlcMockConnectionTest.java  | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java
index 37bcb1a..4a1da85 100644
--- a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java
+++ b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java
@@ -19,11 +19,13 @@
 
 package org.apache.plc4x.java.mock;
 
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.plc4x.java.api.messages.*;
 import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.assertj.core.api.WithAssertions;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
@@ -32,6 +34,10 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import java.util.Collections;
 import java.util.concurrent.CompletableFuture;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 @ExtendWith(MockitoExtension.class)
 class PlcMockConnectionTest implements WithAssertions {
 
@@ -94,8 +100,9 @@ class PlcMockConnectionTest implements WithAssertions {
     }
 
     @Test
-    @Disabled("due to mysterious NPE")
     void write() throws Exception {
+        when(mockDevice.write(any(), any())).thenReturn(PlcResponseCode.OK);
+
         PlcWriteRequest plcWriteRequest = SUT.writeRequestBuilder()
             .addItem("asd", "asd", "asd")
             .build();
@@ -106,8 +113,9 @@ class PlcMockConnectionTest implements WithAssertions {
     }
 
     @Test
-    @Disabled("due to mysterious NPE")
     void subscribe() throws Exception {
+        when(mockDevice.subscribe(any())).thenReturn(Pair.of(PlcResponseCode.OK, mock(PlcSubscriptionHandle.class)));
+
         PlcSubscriptionRequest plcSubscriptionRequest = SUT.subscriptionRequestBuilder()
             .addChangeOfStateField("asd", "asd")
             .build();


[incubator-plc4x] 06/06: [plc4j-opm] Minor test coverage.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 258af1adcb7523cf83f9e8b08c0f9a0b4e4007df
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sat Nov 24 20:47:32 2018 +0100

    [plc4j-opm] Minor test coverage.
---
 .../org/apache/plc4x/java/opm/PlcEntityInterceptor.java   |  1 +
 .../apache/plc4x/java/opm/PlcEntityInterceptorTest.java   | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
index ea0bb2e..26f121c 100644
--- a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
+++ b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
@@ -60,6 +60,7 @@ import java.util.concurrent.TimeoutException;
  *
  * @author julian
  */
+@SuppressWarnings({"common-java:DuplicatedBlocks", "Duplicates"})
 public class PlcEntityInterceptor {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PlcEntityInterceptor.class);
diff --git a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java
index 0873b13..6854123 100644
--- a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java
+++ b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java
@@ -139,7 +139,12 @@ public class PlcEntityInterceptorTest implements WithAssertions {
             }
 
             public void setOk2(String ok) {
+            }
+
+            public void setOkOk(String ok, String ok2) {
+            }
 
+            public void someNotSetterMethod(String arg) {
             }
 
             public void something() {
@@ -170,6 +175,16 @@ public class PlcEntityInterceptorTest implements WithAssertions {
                 .isInstanceOf(OPMException.class)
                 .hasMessage("Problem during processing")
                 .hasStackTraceContaining(" Unable to read specified field 'org.apache.plc4x.java.opm.PlcEntityInterceptorTest$Misc$MiscEntity.ok2', response code was 'null'");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptSetter(null, MiscEntity.class.getDeclaredMethod("setOk2", String.class), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessage("Problem during processing")
+                .hasStackTraceContaining(" Unable to read specified field 'org.apache.plc4x.java.opm.PlcEntityInterceptorTest$Misc$MiscEntity.ok2', response code was 'null'");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptSetter(null, MiscEntity.class.getDeclaredMethod("setOkOk", String.class, String.class), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessage("Only setter with one arguments are supported");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptSetter(null, MiscEntity.class.getDeclaredMethod("someNotSetterMethod", String.class), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessage("Unable to forward invocation someNotSetterMethod on connected PlcEntity");
         }
     }
 


[incubator-plc4x] 02/06: [plc4j] cleanup mock code and moved it completely to driver-bases-test

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit f93cf4ed4fe7d4a5c8065ba772688c6caab90bfe
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Nov 24 18:18:54 2018 +0100

    [plc4j] cleanup mock code and moved it completely to driver-bases-test
---
 .../org/apache/plc4x/java/mock/MockDevice.java     |  18 +-
 .../java/org/apache/plc4x/java/mock/MockField.java |  13 ++
 .../apache/plc4x/java/mock/MockFieldHandler.java   |  70 ++++++++
 .../org/apache/plc4x/java/mock/MockFieldItem.java  |   0
 .../org/apache/plc4x/java/mock/MockReader.java     |  51 ------
 .../apache/plc4x/java/mock/PlcMockConnection.java  | 111 ++++++++++--
 .../org/apache/plc4x/java/mock/PlcMockDriver.java  |  22 ++-
 .../apache/plc4x/java/mock/PlcMockDriverTest.java  |   0
 plc4j/protocols/pom.xml                            |   4 +-
 plc4j/protocols/test/pom.xml                       |  51 ------
 .../org/apache/plc4x/java/mock/MockDevice.java     |  50 ------
 .../java/org/apache/plc4x/java/mock/MockField.java |  49 ------
 .../apache/plc4x/java/mock/MockFieldHandler.java   | 103 ------------
 .../apache/plc4x/java/mock/PlcMockConnection.java  | 186 ---------------------
 .../org/apache/plc4x/java/mock/PlcMockDriver.java  |  63 -------
 .../services/org.apache.plc4x.java.spi.PlcDriver   |  19 ---
 plc4j/utils/opm/pom.xml                            |   5 +-
 17 files changed, 216 insertions(+), 599 deletions(-)

diff --git a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java
index def0589..999a4ac 100644
--- a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java
+++ b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java
@@ -20,10 +20,15 @@
 package org.apache.plc4x.java.mock;
 
 import org.apache.commons.lang3.tuple.Pair;
-import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent;
+import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
 
+import java.util.Collection;
+import java.util.function.Consumer;
+
 /**
  * Mock Object to do assertions on.
  */
@@ -31,4 +36,15 @@ public interface MockDevice {
 
     Pair<PlcResponseCode, BaseDefaultFieldItem> read(String fieldQuery);
 
+    PlcResponseCode write(String fieldQuery, Object value);
+
+    Pair<PlcResponseCode, PlcSubscriptionHandle> subscribe(String fieldQuery);
+
+    void unsubscribe();
+
+    // TODO: this might not be right here as you are not really register at the device, rather on the connection
+    PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> handles);
+
+    // TODO: this might not be right here as you are not really register at the device, rather on the connection
+    void unregister(PlcConsumerRegistration registration);
 }
diff --git a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockField.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockField.java
index e570b2b..b7dccc9 100644
--- a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockField.java
+++ b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockField.java
@@ -21,16 +21,29 @@ package org.apache.plc4x.java.mock;
 
 import org.apache.plc4x.java.api.model.PlcField;
 
+import java.util.List;
+
 public class MockField implements PlcField {
 
     private final String fieldQuery;
 
+    private final List<Object> values;
+
     public MockField(String fieldQuery) {
         this.fieldQuery = fieldQuery;
+        values = null;
+    }
+
+    public MockField(String fieldQuery, List<Object> values) {
+        this.fieldQuery = fieldQuery;
+        this.values = values;
     }
 
     public String getFieldQuery() {
         return fieldQuery;
     }
 
+    public List<Object> getValues() {
+        return values;
+    }
 }
diff --git a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java
index a8893e2..055769f 100644
--- a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java
+++ b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java
@@ -22,6 +22,7 @@ package org.apache.plc4x.java.mock;
 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.BaseDefaultFieldItem;
 
 public class MockFieldHandler extends DefaultPlcFieldHandler {
 
@@ -30,4 +31,73 @@ public class MockFieldHandler extends DefaultPlcFieldHandler {
         return new MockField(fieldQuery);
     }
 
+    @Override
+    public BaseDefaultFieldItem encodeBoolean(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeByte(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeShort(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeInteger(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeBigInteger(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeLong(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeFloat(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeBigDecimal(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeDouble(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeString(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeTime(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeDate(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeDateTime(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeByteArray(PlcField field, Object[] values) {
+        return new MockFieldItem(values);
+    }
 }
diff --git a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockFieldItem.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockFieldItem.java
similarity index 100%
rename from plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockFieldItem.java
rename to plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockFieldItem.java
diff --git a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockReader.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockReader.java
deleted file mode 100644
index 10febee..0000000
--- a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/MockReader.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.mock;
-
-import org.apache.commons.lang3.tuple.Pair;
-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.base.messages.DefaultPlcReadRequest;
-import org.apache.plc4x.java.base.messages.DefaultPlcReadResponse;
-import org.apache.plc4x.java.base.messages.PlcReader;
-import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
-
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-public class MockReader implements PlcReader {
-
-    private final MockDevice device;
-
-    public MockReader(MockDevice device) {
-        this.device = device;
-    }
-
-    @Override
-    public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
-        Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> response = readRequest.getFieldNames().stream()
-            .collect(Collectors.toMap(Function.identity(), name -> device.read(((MockField) readRequest.getField(name)).getFieldQuery())));
-        return CompletableFuture.completedFuture(new DefaultPlcReadResponse((DefaultPlcReadRequest)readRequest, response));
-    }
-
-}
diff --git a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java
index 9e834ec..9dc802f 100644
--- a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java
+++ b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java
@@ -18,22 +18,33 @@ under the License.
 */
 package org.apache.plc4x.java.mock;
 
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.lang3.tuple.Pair;
 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.api.exceptions.PlcUnsupportedOperationException;
-import org.apache.plc4x.java.api.messages.PlcReadRequest;
-import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest;
-import org.apache.plc4x.java.api.messages.PlcUnsubscriptionRequest;
-import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.*;
 import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
-import org.apache.plc4x.java.base.messages.DefaultPlcReadRequest;
+import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.base.messages.*;
+import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class PlcMockConnection implements PlcConnection {
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class PlcMockConnection implements PlcConnection, PlcReader, PlcWriter, PlcSubscriber {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PlcMockConnection.class);
 
     private final PlcAuthentication authentication;
 
-    private boolean isConnected = false;
     private MockDevice device;
 
     PlcMockConnection(PlcAuthentication authentication) {
@@ -45,6 +56,7 @@ public class PlcMockConnection implements PlcConnection {
     }
 
     public void setDevice(MockDevice device) {
+        LOGGER.info("Set Mock Devie on Mock Connection {} with device {}", this, device);
         this.device = device;
     }
 
@@ -55,14 +67,12 @@ public class PlcMockConnection implements PlcConnection {
 
     @Override
     public boolean isConnected() {
-        // is connected if a device is set
         return device != null;
     }
 
     @Override
     public void close() {
-        // unset device
-        this.device = null;
+        LOGGER.info("Closing MockConnection with device {}", device);
     }
 
     @Override
@@ -75,34 +85,99 @@ public class PlcMockConnection implements PlcConnection {
 
             @Override
             public boolean canWrite() {
-                return false;
+                return true;
             }
 
             @Override
             public boolean canSubscribe() {
-                return false;
+                return true;
             }
         };
     }
 
     @Override
     public PlcReadRequest.Builder readRequestBuilder() {
-        return new DefaultPlcReadRequest.Builder(new MockReader(device), new MockFieldHandler());
+        return new DefaultPlcReadRequest.Builder(this, new MockFieldHandler());
+    }
+
+    @Override
+    public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
+        return CompletableFuture.supplyAsync(() -> {
+            Validate.notNull(device, "No device is set in the mock connection!");
+            LOGGER.debug("Sending read request to MockDevice");
+            Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> response = readRequest.getFieldNames().stream()
+                .collect(Collectors.toMap(
+                    Function.identity(),
+                    name -> device.read(((MockField) readRequest.getField(name)).getFieldQuery())
+                    )
+                );
+            return new DefaultPlcReadResponse((DefaultPlcReadRequest) readRequest, response);
+        });
+    }
+
+    @Override
+    public CompletableFuture<PlcWriteResponse> write(PlcWriteRequest writeRequest) {
+        return CompletableFuture.supplyAsync(() -> {
+            Validate.notNull(device, "No device is set in the mock connection!");
+            LOGGER.debug("Sending write request to MockDevice");
+            Map<String, PlcResponseCode> response = writeRequest.getFieldNames().stream()
+                .collect(Collectors.toMap(
+                    Function.identity(),
+                    name -> device.write(((MockField) writeRequest.getField(name)).getFieldQuery(), ((MockField) writeRequest.getField(name)).getValues())
+                    )
+                );
+            return new DefaultPlcWriteResponse((DefaultPlcWriteRequest) writeRequest, response);
+        });
+    }
+
+    @Override
+    public CompletableFuture<PlcSubscriptionResponse> subscribe(PlcSubscriptionRequest subscriptionRequest) {
+        return CompletableFuture.supplyAsync(() -> {
+            Validate.notNull(device, "No device is set in the mock connection!");
+            LOGGER.debug("Sending subsribe request to MockDevice");
+            Map<String, Pair<PlcResponseCode, PlcSubscriptionHandle>> response = subscriptionRequest.getFieldNames().stream()
+                .collect(Collectors.toMap(
+                    Function.identity(),
+                    name -> device.subscribe(((MockField) subscriptionRequest.getField(name)).getFieldQuery())
+                    )
+                );
+            return new DefaultPlcSubscriptionResponse((DefaultPlcSubscriptionRequest) subscriptionRequest, response);
+        });
+    }
+
+    @Override
+    public CompletableFuture<PlcUnsubscriptionResponse> unsubscribe(PlcUnsubscriptionRequest unsubscriptionRequest) {
+        return CompletableFuture.supplyAsync(() -> {
+            Validate.notNull(device, "No device is set in the mock connection!");
+            LOGGER.debug("Sending subsribe request to MockDevice");
+            device.unsubscribe();
+            return new DefaultPlcUnsubscriptionResponse((DefaultPlcUnsubscriptionRequest) unsubscriptionRequest);
+        });
+    }
+
+    @Override
+    public PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> handles) {
+        return device.register(consumer, handles);
+    }
+
+    @Override
+    public void unregister(PlcConsumerRegistration registration) {
+        device.unregister(registration);
     }
 
     @Override
     public PlcWriteRequest.Builder writeRequestBuilder() {
-        throw new PlcUnsupportedOperationException("Write not supported by Mock Driver");
+        return new DefaultPlcWriteRequest.Builder(this, new MockFieldHandler());
     }
 
     @Override
     public PlcSubscriptionRequest.Builder subscriptionRequestBuilder() {
-        throw new PlcUnsupportedOperationException("Subscription not supported by Mock Driver");
+        return new DefaultPlcSubscriptionRequest.Builder(this, new MockFieldHandler());
     }
 
     @Override
     public PlcUnsubscriptionRequest.Builder unsubscriptionRequestBuilder() {
-        throw new PlcUnsupportedOperationException("Subscription not supported by Mock Driver");
+        return new DefaultPlcUnsubscriptionRequest.Builder(this);
     }
 
     public PlcAuthentication getAuthentication() {
diff --git a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java
index c693b84..3476794 100644
--- a/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java
+++ b/plc4j/protocols/driver-bases/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java
@@ -23,8 +23,18 @@ import org.apache.plc4x.java.api.authentication.PlcAuthentication;
 import org.apache.plc4x.java.api.PlcConnection;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
 
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Mocking Driver that keeps a Map of references to Connections so that you can fetch a reference to a connection
+ * which will be acquired by someone else (via the connection string).
+ * This allows for efficient Mocking.
+ */
 public class PlcMockDriver implements PlcDriver {
 
+    private Map<String, PlcConnection> connectionMap = new ConcurrentHashMap<>();
+
     @Override
     public String getProtocolCode() {
         return "mock";
@@ -36,13 +46,17 @@ public class PlcMockDriver implements PlcDriver {
     }
 
     @Override
-    public PlcConnection connect(String url) {
-        return new PlcMockConnection(null);
+    public PlcConnection connect(String url) throws PlcConnectionException {
+        return connect(url, null);
     }
 
     @Override
-    public PlcConnection connect(String url, PlcAuthentication authentication) {
-        return new PlcMockConnection(authentication);
+    public PlcConnection connect(String url, PlcAuthentication authentication) throws PlcConnectionException {
+        String deviceName = url.substring(5);
+        if (deviceName.isEmpty()) {
+            throw new PlcConnectionException("Invalid URL: no device name given.");
+        }
+        return connectionMap.computeIfAbsent(deviceName, name -> new PlcMockConnection(authentication));
     }
 
 }
diff --git a/plc4j/protocols/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java
similarity index 100%
rename from plc4j/protocols/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java
rename to plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java
diff --git a/plc4j/protocols/pom.xml b/plc4j/protocols/pom.xml
index f4cbe1d..2d18946 100644
--- a/plc4j/protocols/pom.xml
+++ b/plc4j/protocols/pom.xml
@@ -17,7 +17,8 @@
   limitations under the License.
 
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
   <modelVersion>4.0.0</modelVersion>
 
@@ -43,7 +44,6 @@
     <module>iso-tp</module>
     <module>modbus</module>
     <module>s7</module>
-    <module>test</module>
 
     <module>benchmarks</module>
   </modules>
diff --git a/plc4j/protocols/test/pom.xml b/plc4j/protocols/test/pom.xml
deleted file mode 100644
index d415346..0000000
--- a/plc4j/protocols/test/pom.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-<?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.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-
-  <parent>
-    <groupId>org.apache.plc4x</groupId>
-    <artifactId>plc4j-protocols</artifactId>
-    <version>0.3.0-SNAPSHOT</version>
-  </parent>
-
-  <artifactId>plc4j-protocol-test</artifactId>
-  <name>PLC4J: Protocol: TEST</name>
-  <description>Test implementation of a PLC4X driver.</description>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-api</artifactId>
-      <version>0.3.0-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-protocol-driver-base</artifactId>
-      <version>0.3.0-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-    </dependency>
-  </dependencies>
-
-</project>
\ No newline at end of file
diff --git a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java b/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java
deleted file mode 100644
index 999a4ac..0000000
--- a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockDevice.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.mock;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent;
-import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
-import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
-
-import java.util.Collection;
-import java.util.function.Consumer;
-
-/**
- * Mock Object to do assertions on.
- */
-public interface MockDevice {
-
-    Pair<PlcResponseCode, BaseDefaultFieldItem> read(String fieldQuery);
-
-    PlcResponseCode write(String fieldQuery, Object value);
-
-    Pair<PlcResponseCode, PlcSubscriptionHandle> subscribe(String fieldQuery);
-
-    void unsubscribe();
-
-    // TODO: this might not be right here as you are not really register at the device, rather on the connection
-    PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> handles);
-
-    // TODO: this might not be right here as you are not really register at the device, rather on the connection
-    void unregister(PlcConsumerRegistration registration);
-}
diff --git a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockField.java b/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockField.java
deleted file mode 100644
index b7dccc9..0000000
--- a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockField.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.mock;
-
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.List;
-
-public class MockField implements PlcField {
-
-    private final String fieldQuery;
-
-    private final List<Object> values;
-
-    public MockField(String fieldQuery) {
-        this.fieldQuery = fieldQuery;
-        values = null;
-    }
-
-    public MockField(String fieldQuery, List<Object> values) {
-        this.fieldQuery = fieldQuery;
-        this.values = values;
-    }
-
-    public String getFieldQuery() {
-        return fieldQuery;
-    }
-
-    public List<Object> getValues() {
-        return values;
-    }
-}
diff --git a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java b/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java
deleted file mode 100644
index 055769f..0000000
--- a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/MockFieldHandler.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.mock;
-
-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.BaseDefaultFieldItem;
-
-public class MockFieldHandler extends DefaultPlcFieldHandler {
-
-    @Override
-    public PlcField createField(String fieldQuery) throws PlcInvalidFieldException {
-        return new MockField(fieldQuery);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeBoolean(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeByte(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeShort(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeInteger(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeBigInteger(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeLong(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeFloat(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeBigDecimal(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeDouble(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeString(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeTime(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeDate(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeDateTime(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-
-    @Override
-    public BaseDefaultFieldItem encodeByteArray(PlcField field, Object[] values) {
-        return new MockFieldItem(values);
-    }
-}
diff --git a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java b/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java
deleted file mode 100644
index 9dc802f..0000000
--- a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockConnection.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
-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.mock;
-
-import org.apache.commons.lang3.Validate;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.authentication.PlcAuthentication;
-import org.apache.plc4x.java.api.messages.*;
-import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
-import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
-import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-import org.apache.plc4x.java.base.messages.*;
-import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
-public class PlcMockConnection implements PlcConnection, PlcReader, PlcWriter, PlcSubscriber {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(PlcMockConnection.class);
-
-    private final PlcAuthentication authentication;
-
-    private MockDevice device;
-
-    PlcMockConnection(PlcAuthentication authentication) {
-        this.authentication = authentication;
-    }
-
-    public MockDevice getDevice() {
-        return device;
-    }
-
-    public void setDevice(MockDevice device) {
-        LOGGER.info("Set Mock Devie on Mock Connection {} with device {}", this, device);
-        this.device = device;
-    }
-
-    @Override
-    public void connect() {
-        // do nothing
-    }
-
-    @Override
-    public boolean isConnected() {
-        return device != null;
-    }
-
-    @Override
-    public void close() {
-        LOGGER.info("Closing MockConnection with device {}", device);
-    }
-
-    @Override
-    public PlcConnectionMetadata getMetadata() {
-        return new PlcConnectionMetadata() {
-            @Override
-            public boolean canRead() {
-                return true;
-            }
-
-            @Override
-            public boolean canWrite() {
-                return true;
-            }
-
-            @Override
-            public boolean canSubscribe() {
-                return true;
-            }
-        };
-    }
-
-    @Override
-    public PlcReadRequest.Builder readRequestBuilder() {
-        return new DefaultPlcReadRequest.Builder(this, new MockFieldHandler());
-    }
-
-    @Override
-    public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
-        return CompletableFuture.supplyAsync(() -> {
-            Validate.notNull(device, "No device is set in the mock connection!");
-            LOGGER.debug("Sending read request to MockDevice");
-            Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> response = readRequest.getFieldNames().stream()
-                .collect(Collectors.toMap(
-                    Function.identity(),
-                    name -> device.read(((MockField) readRequest.getField(name)).getFieldQuery())
-                    )
-                );
-            return new DefaultPlcReadResponse((DefaultPlcReadRequest) readRequest, response);
-        });
-    }
-
-    @Override
-    public CompletableFuture<PlcWriteResponse> write(PlcWriteRequest writeRequest) {
-        return CompletableFuture.supplyAsync(() -> {
-            Validate.notNull(device, "No device is set in the mock connection!");
-            LOGGER.debug("Sending write request to MockDevice");
-            Map<String, PlcResponseCode> response = writeRequest.getFieldNames().stream()
-                .collect(Collectors.toMap(
-                    Function.identity(),
-                    name -> device.write(((MockField) writeRequest.getField(name)).getFieldQuery(), ((MockField) writeRequest.getField(name)).getValues())
-                    )
-                );
-            return new DefaultPlcWriteResponse((DefaultPlcWriteRequest) writeRequest, response);
-        });
-    }
-
-    @Override
-    public CompletableFuture<PlcSubscriptionResponse> subscribe(PlcSubscriptionRequest subscriptionRequest) {
-        return CompletableFuture.supplyAsync(() -> {
-            Validate.notNull(device, "No device is set in the mock connection!");
-            LOGGER.debug("Sending subsribe request to MockDevice");
-            Map<String, Pair<PlcResponseCode, PlcSubscriptionHandle>> response = subscriptionRequest.getFieldNames().stream()
-                .collect(Collectors.toMap(
-                    Function.identity(),
-                    name -> device.subscribe(((MockField) subscriptionRequest.getField(name)).getFieldQuery())
-                    )
-                );
-            return new DefaultPlcSubscriptionResponse((DefaultPlcSubscriptionRequest) subscriptionRequest, response);
-        });
-    }
-
-    @Override
-    public CompletableFuture<PlcUnsubscriptionResponse> unsubscribe(PlcUnsubscriptionRequest unsubscriptionRequest) {
-        return CompletableFuture.supplyAsync(() -> {
-            Validate.notNull(device, "No device is set in the mock connection!");
-            LOGGER.debug("Sending subsribe request to MockDevice");
-            device.unsubscribe();
-            return new DefaultPlcUnsubscriptionResponse((DefaultPlcUnsubscriptionRequest) unsubscriptionRequest);
-        });
-    }
-
-    @Override
-    public PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> handles) {
-        return device.register(consumer, handles);
-    }
-
-    @Override
-    public void unregister(PlcConsumerRegistration registration) {
-        device.unregister(registration);
-    }
-
-    @Override
-    public PlcWriteRequest.Builder writeRequestBuilder() {
-        return new DefaultPlcWriteRequest.Builder(this, new MockFieldHandler());
-    }
-
-    @Override
-    public PlcSubscriptionRequest.Builder subscriptionRequestBuilder() {
-        return new DefaultPlcSubscriptionRequest.Builder(this, new MockFieldHandler());
-    }
-
-    @Override
-    public PlcUnsubscriptionRequest.Builder unsubscriptionRequestBuilder() {
-        return new DefaultPlcUnsubscriptionRequest.Builder(this);
-    }
-
-    public PlcAuthentication getAuthentication() {
-        return authentication;
-    }
-}
diff --git a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java b/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java
deleted file mode 100644
index 3ff5dd4..0000000
--- a/plc4j/protocols/test/src/main/java/org/apache/plc4x/java/mock/PlcMockDriver.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-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.mock;
-
-import org.apache.plc4x.java.spi.PlcDriver;
-import org.apache.plc4x.java.api.authentication.PlcAuthentication;
-import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Mocking Driver that keeps a Map of references to Connections so that you can fetch a reference to a connection
- * which will be acquired by someone else (via the connection string).
- * This allows for efficient Mocking.
- */
-public class PlcMockDriver implements PlcDriver {
-
-    private Map<String, PlcConnection> connectionMap = new ConcurrentHashMap<>();
-
-    @Override
-    public String getProtocolCode() {
-        return "mock";
-    }
-
-    @Override
-    public String getProtocolName() {
-        return "Mock Protocol Implementation";
-    }
-
-    @Override
-    public PlcConnection connect(String url) throws PlcConnectionException {
-        return connect(url, null);
-    }
-
-    @Override
-    public PlcConnection connect(String url, PlcAuthentication authentication) throws PlcConnectionException {
-        String deviceName = url.substring(5);
-        if (deviceName.isEmpty()) {
-            throw new PlcConnectionException("Invalid URL: no device name given.");
-        }
-        return connectionMap.computeIfAbsent(deviceName, name -> new PlcMockConnection(authentication));
-    }
-
-}
diff --git a/plc4j/protocols/test/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver b/plc4j/protocols/test/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
deleted file mode 100644
index ebff4aa..0000000
--- a/plc4j/protocols/test/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-org.apache.plc4x.java.mock.PlcMockDriver
diff --git a/plc4j/utils/opm/pom.xml b/plc4j/utils/opm/pom.xml
index a0fbda1..4efbf62 100644
--- a/plc4j/utils/opm/pom.xml
+++ b/plc4j/utils/opm/pom.xml
@@ -17,7 +17,8 @@
   specific language governing permissions and limitations
   under the License.
   -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
   <modelVersion>4.0.0</modelVersion>
 
@@ -75,7 +76,7 @@
     </dependency>
     <dependency>
       <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-protocol-test</artifactId>
+      <artifactId>plc4j-protocol-driver-base-test</artifactId>
       <version>0.3.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>


[incubator-plc4x] 05/06: [plc4j-driver-simulated] added tests and fixed bugs.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 99d8f27a5d5840e17ea87d6c2e71b64e0f0b5196
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Nov 24 19:45:22 2018 +0100

    [plc4j-driver-simulated] added tests and fixed bugs.
---
 .../simulated/connection/TestFieldHandler.java     |   6 +-
 .../java/simulated/connection/TestFieldItem.java   |   2 +-
 .../java/simulated/SimulatedPlcDriverTest.java     |   7 ++
 .../java/simulated/connection/TestDeviceTest.java  |   2 +-
 .../simulated/connection/TestFieldHandlerTest.java | 133 +++++++++++++++++++++
 .../simulated/connection/TestFieldItemTest.java}   |  20 ++--
 6 files changed, 153 insertions(+), 17 deletions(-)

diff --git a/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldHandler.java b/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldHandler.java
index 329a28e..44d7151 100644
--- a/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldHandler.java
+++ b/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldHandler.java
@@ -100,7 +100,7 @@ public class TestFieldHandler implements PlcFieldHandler {
     public BaseDefaultFieldItem encodeFloat(PlcField field, Object[] values) {
         TestField testField = (TestField) field;
         if (testField.getDataType() == Float.class) {
-            return new DefaultDoubleFieldItem((Double[]) values);
+            return new DefaultFloatFieldItem((Float[]) values);
         }
         throw new PlcRuntimeException("Invalid encoder for type " + testField.getDataType().getName());
     }
@@ -136,7 +136,7 @@ public class TestFieldHandler implements PlcFieldHandler {
     public BaseDefaultFieldItem encodeTime(PlcField field, Object[] values) {
         TestField testField = (TestField) field;
         if (testField.getDataType() == LocalTime.class) {
-            return new DefaultLocalDateTimeFieldItem((LocalDateTime[]) values);
+            return new DefaultLocalTimeFieldItem((LocalTime[]) values);
         }
         throw new PlcRuntimeException("Invalid encoder for type " + testField.getDataType().getName());
     }
@@ -145,7 +145,7 @@ public class TestFieldHandler implements PlcFieldHandler {
     public BaseDefaultFieldItem encodeDate(PlcField field, Object[] values) {
         TestField testField = (TestField) field;
         if (testField.getDataType() == LocalDate.class) {
-            return new DefaultLocalDateTimeFieldItem((LocalDateTime[]) values);
+            return new DefaultLocalDateFieldItem((LocalDate[]) values);
         }
         throw new PlcRuntimeException("Invalid encoder for type " + testField.getDataType().getName());
     }
diff --git a/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java b/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java
index 230b7b7..e65ec8d 100644
--- a/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java
+++ b/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java
@@ -23,7 +23,7 @@ import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
 
 public class TestFieldItem<T> extends BaseDefaultFieldItem<T> {
 
-    public TestFieldItem(T[] values) {
+    public TestFieldItem(T... values) {
         super(values);
     }
 
diff --git a/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/SimulatedPlcDriverTest.java b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/SimulatedPlcDriverTest.java
index 61d39c9..6a5d9e8 100644
--- a/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/SimulatedPlcDriverTest.java
+++ b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/SimulatedPlcDriverTest.java
@@ -47,4 +47,11 @@ class SimulatedPlcDriverTest implements WithAssertions {
     void connect_secure() {
         assertThatThrownBy(() -> SUT.connect(null, null)).isInstanceOf(PlcConnectionException.class);
     }
+
+    @Test
+    void wrongUrl() {
+        assertThatThrownBy(() -> SUT.connect("test:"))
+            .isInstanceOf(PlcConnectionException.class)
+            .hasMessage("Invalid URL: no device name given.");
+    }
 }
\ No newline at end of file
diff --git a/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestDeviceTest.java b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestDeviceTest.java
index a4f2703..fbe3f36 100644
--- a/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestDeviceTest.java
+++ b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestDeviceTest.java
@@ -20,7 +20,7 @@ package org.apache.plc4x.java.simulated.connection;
 
 import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
 import org.apache.plc4x.java.base.messages.items.DefaultLongFieldItem;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.Optional;
 
diff --git a/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldHandlerTest.java b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldHandlerTest.java
new file mode 100644
index 0000000..9fff341
--- /dev/null
+++ b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldHandlerTest.java
@@ -0,0 +1,133 @@
+/*
+ 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.simulated.connection;
+
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@SuppressWarnings("unchecked")
+class TestFieldHandlerTest implements WithAssertions {
+
+    TestFieldHandler SUT = new TestFieldHandler();
+
+    @Mock
+    TestField plcField;
+
+    @Test
+    void createField() {
+        assertThat(SUT.createField("STATE/bar:INTEGER")).isNotNull();
+    }
+
+    @Test
+    void encodeBoolean() {
+        when(plcField.getDataType()).thenReturn((Class) Boolean.class);
+        assertThat(SUT.encodeBoolean(plcField, new Boolean[0])).isNotNull();
+    }
+
+    @Test
+    void encodeByte() {
+        when(plcField.getDataType()).thenReturn((Class) Byte.class);
+        assertThat(SUT.encodeByte(plcField, new Byte[0])).isNotNull();
+    }
+
+    @Test
+    void encodeShort() {
+        when(plcField.getDataType()).thenReturn((Class) Short.class);
+        assertThat(SUT.encodeShort(plcField, new Short[0])).isNotNull();
+    }
+
+    @Test
+    void encodeInteger() {
+        when(plcField.getDataType()).thenReturn((Class) Integer.class);
+        assertThat(SUT.encodeInteger(plcField, new Integer[0])).isNotNull();
+    }
+
+    @Test
+    void encodeBigInteger() {
+        when(plcField.getDataType()).thenReturn((Class) BigInteger.class);
+        assertThat(SUT.encodeBigInteger(plcField, new BigInteger[0])).isNotNull();
+    }
+
+    @Test
+    void encodeLong() {
+        when(plcField.getDataType()).thenReturn((Class) Long.class);
+        assertThat(SUT.encodeLong(plcField, new Long[0])).isNotNull();
+    }
+
+    @Test
+    void encodeFloat() {
+        when(plcField.getDataType()).thenReturn((Class) Float.class);
+        assertThat(SUT.encodeFloat(plcField, new Float[0])).isNotNull();
+    }
+
+    @Test
+    void encodeBigDecimal() {
+        when(plcField.getDataType()).thenReturn((Class) BigDecimal.class);
+        assertThat(SUT.encodeBigDecimal(plcField, new BigDecimal[0])).isNotNull();
+    }
+
+    @Test
+    void encodeDouble() {
+        when(plcField.getDataType()).thenReturn((Class) Double.class);
+        assertThat(SUT.encodeDouble(plcField, new Double[0])).isNotNull();
+    }
+
+    @Test
+    void encodeString() {
+        when(plcField.getDataType()).thenReturn((Class) String.class);
+        assertThat(SUT.encodeString(plcField, new String[0])).isNotNull();
+    }
+
+    @Test
+    void encodeTime() {
+        when(plcField.getDataType()).thenReturn((Class) LocalTime.class);
+        assertThat(SUT.encodeTime(plcField, new LocalTime[0])).isNotNull();
+    }
+
+    @Test
+    void encodeDate() {
+        when(plcField.getDataType()).thenReturn((Class) LocalDate.class);
+        assertThat(SUT.encodeDate(plcField, new LocalDate[0])).isNotNull();
+    }
+
+    @Test
+    void encodeDateTime() {
+        when(plcField.getDataType()).thenReturn((Class) LocalDateTime.class);
+        assertThat(SUT.encodeDateTime(plcField, new LocalDateTime[0])).isNotNull();
+    }
+
+    @Test
+    void encodeByteArray() {
+        when(plcField.getDataType()).thenReturn((Class) Byte[].class);
+        assertThat(SUT.encodeByteArray(plcField, new Byte[0])).isNotNull();
+    }
+}
\ No newline at end of file
diff --git a/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldItemTest.java
similarity index 69%
copy from plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java
copy to plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldItemTest.java
index 230b7b7..bad6841 100644
--- a/plc4j/drivers/simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java
+++ b/plc4j/drivers/simulated/src/test/java/org/apache/plc4x/java/simulated/connection/TestFieldItemTest.java
@@ -7,7 +7,7 @@
  "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
@@ -19,17 +19,13 @@
 
 package org.apache.plc4x.java.simulated.connection;
 
-import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
 
-public class TestFieldItem<T> extends BaseDefaultFieldItem<T> {
+class TestFieldItemTest implements WithAssertions {
 
-    public TestFieldItem(T[] values) {
-        super(values);
+    @Test
+    void getObject() {
+        assertThat(new TestFieldItem<String>("").getObject(0)).isNotNull();
     }
-
-    @Override
-    public Object getObject(int index) {
-        return getValue(index);
-    }
-
-}
+}
\ No newline at end of file


[incubator-plc4x] 03/06: [plc4j-driver-bases-test] added some tests.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 58a00fae9a162c80fc814230cdf54f9778577738
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Nov 24 19:10:30 2018 +0100

    [plc4j-driver-bases-test] added some tests.
---
 .../plc4x/java/mock/MockFieldHandlerTest.java      | 111 +++++++++++++++
 .../apache/plc4x/java/mock/MockFieldItemTest.java  |  31 ++++
 .../org/apache/plc4x/java/mock/MockFieldTest.java  |  48 +++++++
 .../plc4x/java/mock/PlcMockConnectionTest.java     | 156 +++++++++++++++++++++
 .../apache/plc4x/java/mock/PlcMockDriverTest.java  |  53 +++----
 5 files changed, 375 insertions(+), 24 deletions(-)

diff --git a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldHandlerTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldHandlerTest.java
new file mode 100644
index 0000000..fb3d786
--- /dev/null
+++ b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldHandlerTest.java
@@ -0,0 +1,111 @@
+/*
+ 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.mock;
+
+import org.apache.plc4x.java.api.model.PlcField;
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class MockFieldHandlerTest implements WithAssertions {
+
+    MockFieldHandler SUT = new MockFieldHandler();
+
+    @Mock
+    PlcField plcField;
+
+    @Test
+    void createField() {
+        assertThat(SUT.createField("")).isNotNull();
+    }
+
+    @Test
+    void encodeBoolean() {
+        assertThat(SUT.encodeBoolean(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeByte() {
+        assertThat(SUT.encodeByte(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeShort() {
+        assertThat(SUT.encodeShort(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeInteger() {
+        assertThat(SUT.encodeInteger(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeBigInteger() {
+        assertThat(SUT.encodeBigInteger(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeLong() {
+        assertThat(SUT.encodeLong(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeFloat() {
+        assertThat(SUT.encodeFloat(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeBigDecimal() {
+        assertThat(SUT.encodeBigDecimal(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeDouble() {
+        assertThat(SUT.encodeDouble(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeString() {
+        assertThat(SUT.encodeString(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeTime() {
+        assertThat(SUT.encodeTime(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeDate() {
+        assertThat(SUT.encodeDate(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeDateTime() {
+        assertThat(SUT.encodeDateTime(plcField, new Object[0])).isNotNull();
+    }
+
+    @Test
+    void encodeByteArray() {
+        assertThat(SUT.encodeByteArray(plcField, new Object[0])).isNotNull();
+    }
+}
\ No newline at end of file
diff --git a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldItemTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldItemTest.java
new file mode 100644
index 0000000..066f87c
--- /dev/null
+++ b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldItemTest.java
@@ -0,0 +1,31 @@
+/*
+ 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.mock;
+
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
+
+class MockFieldItemTest implements WithAssertions {
+
+    @Test
+    void getObject() {
+        assertThat(new MockFieldItem("").getObject(0)).isNotNull();
+    }
+}
\ No newline at end of file
diff --git a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldTest.java
new file mode 100644
index 0000000..5864e59
--- /dev/null
+++ b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/MockFieldTest.java
@@ -0,0 +1,48 @@
+/*
+ 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.mock;
+
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+class MockFieldTest implements WithAssertions {
+
+    @Test
+    void constructor1() {
+        assertThat(new MockField("")).isNotNull();
+    }
+
+    @Test
+    void constructor2() {
+        assertThat(new MockField("", Collections.emptyList())).isNotNull();
+    }
+
+    @Test
+    void getFieldQuery() {
+        new MockField("", Collections.emptyList()).getFieldQuery();
+    }
+
+    @Test
+    void getValues() {
+        new MockField("", Collections.emptyList()).getValues();
+    }
+}
\ No newline at end of file
diff --git a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java
new file mode 100644
index 0000000..37bcb1a
--- /dev/null
+++ b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockConnectionTest.java
@@ -0,0 +1,156 @@
+/*
+ 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.mock;
+
+import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+
+@ExtendWith(MockitoExtension.class)
+class PlcMockConnectionTest implements WithAssertions {
+
+    PlcMockConnection SUT = new PlcMockConnection(null);
+
+    @Mock
+    MockDevice mockDevice;
+
+    @BeforeEach
+    void setUp() {
+        SUT.setDevice(mockDevice);
+    }
+
+    @Test
+    void getDevice() {
+        assertThat(SUT.getDevice()).isNotNull();
+    }
+
+    @Test
+    void setDevice() {
+        SUT.setDevice(null);
+    }
+
+    @Test
+    void connect() {
+        SUT.connect();
+    }
+
+    @Test
+    void isConnected() {
+        SUT.setDevice(mockDevice);
+        assertThat(SUT.isConnected()).isTrue();
+        SUT.setDevice(null);
+        assertThat(SUT.isConnected()).isFalse();
+    }
+
+    @Test
+    void close() {
+        SUT.close();
+    }
+
+    @Test
+    void getMetadata() {
+        PlcConnectionMetadata metadata = SUT.getMetadata();
+        assertThat(metadata).isNotNull();
+        assertThat(metadata.canRead()).isTrue();
+        assertThat(metadata.canWrite()).isTrue();
+        assertThat(metadata.canSubscribe()).isTrue();
+    }
+
+    @Test
+    void readRequestBuilder() {
+        assertThat(SUT.readRequestBuilder()).isNotNull();
+    }
+
+    @Test
+    void read() {
+        PlcReadRequest plcReadRequest = SUT.readRequestBuilder().build();
+        assertThat(SUT.read(plcReadRequest)).isNotNull();
+    }
+
+    @Test
+    @Disabled("due to mysterious NPE")
+    void write() throws Exception {
+        PlcWriteRequest plcWriteRequest = SUT.writeRequestBuilder()
+            .addItem("asd", "asd", "asd")
+            .build();
+        CompletableFuture<PlcWriteResponse> write = SUT.write(plcWriteRequest);
+        assertThat(write).isNotNull();
+        PlcWriteResponse plcWriteResponse = write.get();
+        assertThat(plcWriteResponse).isNotNull();
+    }
+
+    @Test
+    @Disabled("due to mysterious NPE")
+    void subscribe() throws Exception {
+        PlcSubscriptionRequest plcSubscriptionRequest = SUT.subscriptionRequestBuilder()
+            .addChangeOfStateField("asd", "asd")
+            .build();
+        CompletableFuture<PlcSubscriptionResponse> subscribe = SUT.subscribe(plcSubscriptionRequest);
+        assertThat(subscribe).isNotNull();
+        PlcSubscriptionResponse plcSubscriptionResponse = subscribe.get();
+        assertThat(plcSubscriptionResponse).isNotNull();
+    }
+
+    @Test
+    void unsubscribe() {
+        PlcUnsubscriptionRequest unsubscriptionRequest = SUT.unsubscriptionRequestBuilder().build();
+        assertThat(SUT.unsubscribe(unsubscriptionRequest)).isNotNull();
+    }
+
+    @Test
+    void register() {
+        SUT.register(plcSubscriptionEvent -> {
+        }, Collections.emptyList());
+    }
+
+    @Test
+    void unregister() {
+        SUT.unregister(null);
+    }
+
+    @Test
+    void writeRequestBuilder() {
+        assertThat(SUT.writeRequestBuilder()).isNotNull();
+    }
+
+    @Test
+    void subscriptionRequestBuilder() {
+        assertThat(SUT.subscriptionRequestBuilder()).isNotNull();
+    }
+
+    @Test
+    void unsubscriptionRequestBuilder() {
+        assertThat(SUT.unsubscriptionRequestBuilder()).isNotNull();
+    }
+
+    @Test
+    void getAuthentication() {
+        assertThat(SUT.getAuthentication()).isNull();
+    }
+}
\ No newline at end of file
diff --git a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java
index 1da4853..b13ccbc 100644
--- a/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java
+++ b/plc4j/protocols/driver-bases/test/src/test/java/org/apache/plc4x/java/mock/PlcMockDriverTest.java
@@ -1,20 +1,20 @@
 /*
- * 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.
+ 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.mock;
@@ -25,20 +25,18 @@ import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
 import org.apache.plc4x.java.api.messages.PlcReadResponse;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.java.base.messages.items.DefaultIntegerFieldItem;
-import org.apache.plc4x.java.base.messages.items.DefaultLongFieldItem;
-import org.junit.Test;
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 
 import java.util.concurrent.ExecutionException;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 
-public class PlcMockDriverTest {
+public class PlcMockDriverTest implements WithAssertions {
 
     private final PlcMockDriver driver = new PlcMockDriver();
 
@@ -53,10 +51,10 @@ public class PlcMockDriverTest {
     /**
      * Example of Mock Usage.
      * The idea is to fetch a mock connection with a specific name and prepare a {@link MockDevice} which is set there.
-     *
+     * <p>
      * Some application code which uses the same Connection String will then automatically get the same connection
      * and operate against the same {@link MockDevice} without the necessity to also mock field queries or other things.
-     *
+     * <p>
      * In this example the {@link #someCodeWhichShouldDoPlcManipulation(String)} function represents the Business Logic
      * which should be tested and where only the connection string is manipulated for the test.
      */
@@ -74,8 +72,15 @@ public class PlcMockDriverTest {
         verify(mock, times(1)).read("DB2.DBD17:INT");
     }
 
+    @Test
+    public void wrongDevice() {
+        assertThatThrownBy(() -> driver.connect("mock:"))
+            .isInstanceOf(PlcConnectionException.class);
+    }
+
     /**
      * Example function that does some reading from a siemens plc using Siemens Syntax
+     *
      * @param connection Connection String, e.g., from config
      */
     private void someCodeWhichShouldDoPlcManipulation(String connection) throws PlcConnectionException, ExecutionException, InterruptedException {


[incubator-plc4x] 01/06: [plc4j-opm] added some tests for entity interceptor

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch feature/plc4j-scraper
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit c4e4f8857bf15fdd1e8923fa422ba93078ad4250
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Nov 24 17:49:44 2018 +0100

    [plc4j-opm] added some tests for entity interceptor
---
 .../plc4x/java/opm/PlcEntityInterceptorTest.java   | 50 +++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java
index fadf6f4..0873b13 100644
--- a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java
+++ b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java
@@ -20,6 +20,7 @@
 package org.apache.plc4x.java.opm;
 
 import org.apache.commons.lang3.tuple.Pair;
+import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 import org.apache.plc4x.java.api.messages.PlcReadRequest;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
@@ -28,13 +29,17 @@ import org.assertj.core.api.WithAssertions;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.mockito.stubbing.Answer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.time.Instant;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
@@ -114,14 +119,57 @@ public class PlcEntityInterceptorTest implements WithAssertions {
         @Mock
         Callable callable;
 
+        @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+        PlcDriverManager plcDriverManager;
+
+        class MiscEntity {
+
+            @PlcField("asd")
+            private String ok2;
+
+            public void getTest(String a) {
+            }
+
+            public String getOk() {
+                return "";
+            }
+
+            public String getOk2() {
+                return ok2;
+            }
+
+            public void setOk2(String ok) {
+
+            }
+
+            public void something() {
+
+            }
+        }
+
         @Test
         void missingCases() throws Exception {
             when(callable.call()).then(invocation -> {
                 throw new PlcRuntimeException("broken");
             });
-            assertThatThrownBy(() -> PlcEntityInterceptor.interceptGetter(null, this.getClass().getDeclaredMethod("missingCases"), callable, null, null, null, null, null))
+            Map<String, Instant> lastFetched = new HashMap<>();
+            Map<String, Instant> lastWritten = new HashMap<>();
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptGetter(null, MiscEntity.class.getDeclaredMethod("something"), callable, null, null, null, lastFetched, lastWritten))
                 .isInstanceOf(OPMException.class)
                 .hasMessage("Exception during forwarding call");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptGetter(null, MiscEntity.class.getDeclaredMethod("getTest", String.class), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessage("Only getter with no arguments are supported");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptGetter(null, MiscEntity.class.getDeclaredMethod("getOk"), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessageMatching("Unable to identify field with name .*");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptGetter(null, MiscEntity.class.getDeclaredMethod("getOk2"), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessage("Problem during processing");
+            assertThatThrownBy(() -> PlcEntityInterceptor.interceptGetter(null, MiscEntity.class.getDeclaredMethod("getOk2"), callable, null, plcDriverManager, null, lastFetched, lastWritten))
+                .isInstanceOf(OPMException.class)
+                .hasMessage("Problem during processing")
+                .hasStackTraceContaining(" Unable to read specified field 'org.apache.plc4x.java.opm.PlcEntityInterceptorTest$Misc$MiscEntity.ok2', response code was 'null'");
         }
     }