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/23 11:31:05 UTC

[incubator-plc4x] branch develop updated: - Testfix in OPM. - Fix in PlcMockDriver.

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 47eccb1  - Testfix in OPM. - Fix in PlcMockDriver.
47eccb1 is described below

commit 47eccb1e84ad6810f32091286ed8fddbfe30eba0
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Fri Nov 23 12:30:52 2018 +0100

    - Testfix in OPM.
    - Fix in PlcMockDriver.
---
 .../org/apache/plc4x/java/mock/PlcMockConnection.java   |  4 +++-
 .../java/org/apache/plc4x/java/mock/PlcMockDriver.java  |  3 ++-
 plc4j/utils/opm/pom.xml                                 | 17 +++++++++++------
 .../org/apache/plc4x/java/opm/PlcEntityInterceptor.java |  6 ++++++
 .../apache/plc4x/java/opm/PlcEntityInterceptorTest.java |  2 +-
 5 files changed, 23 insertions(+), 9 deletions(-)

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
index 9130d7f..1972172 100644
--- 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
@@ -18,6 +18,7 @@ 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;
@@ -66,7 +67,7 @@ public class PlcMockConnection implements PlcConnection, PlcReader {
 
     @Override
     public boolean isConnected() {
-        return true;
+        return device != null;
     }
 
     @Override
@@ -105,6 +106,7 @@ public class PlcMockConnection implements PlcConnection, PlcReader {
 
             @Override
             public PlcReadResponse get() {
+                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(
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
index 0a2b1c0..3ff5dd4 100644
--- 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
@@ -25,6 +25,7 @@ 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
@@ -33,7 +34,7 @@ import java.util.WeakHashMap;
  */
 public class PlcMockDriver implements PlcDriver {
 
-    private Map<String, PlcConnection> connectionMap = new WeakHashMap<>();
+    private Map<String, PlcConnection> connectionMap = new ConcurrentHashMap<>();
 
     @Override
     public String getProtocolCode() {
diff --git a/plc4j/utils/opm/pom.xml b/plc4j/utils/opm/pom.xml
index 4e25bf7..a0fbda1 100644
--- a/plc4j/utils/opm/pom.xml
+++ b/plc4j/utils/opm/pom.xml
@@ -79,6 +79,12 @@
       <version>0.3.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-driver-simulated</artifactId>
+      <version>0.3.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -86,12 +92,11 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
-        <!--Currently commented out as the dependency is used "explicitly".-->
-        <!--<configuration>-->
-          <!--<usedDependencies combine.children="append">-->
-            <!--<usedDependency>org.apache.plc4x:plc4j-protocol-test</usedDependency>-->
-          <!--</usedDependencies>-->
-        <!--</configuration>-->
+        <configuration>
+          <usedDependencies combine.children="append">
+            <usedDependency>org.apache.plc4x:plc4j-driver-simulated</usedDependency>
+          </usedDependencies>
+        </configuration>
       </plugin>
     </plugins>
   </build>
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 7671563..f41f7c5 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
@@ -157,6 +157,12 @@ public class PlcEntityInterceptor {
             throw new OPMException("Non PlcEntity supplied");
         }
 
+        // Check if all fields are valid
+        for (Field field : entityClass.getDeclaredFields()) {
+            if (field.isAnnotationPresent(PlcField.class)) {
+                OpmUtils.getOrResolveAddress(registry, field.getAnnotation(PlcField.class).value());
+            }
+        }
         try (PlcConnection connection = driverManager.getConnection(address)) {
             // Catch the exception, if no reader present (see below)
             // Build the query
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 0450cae..301272b 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
@@ -109,7 +109,7 @@ public class PlcEntityInterceptorTest {
     @Test
     public void getterWithNoField() throws OPMException {
         PlcEntityManager entityManager = new PlcEntityManager();
-        BadEntity entity = entityManager.connect(BadEntity.class, "mock:test");
+        BadEntity entity = entityManager.connect(BadEntity.class, "test:test");
 
         String message = null;
         try {