You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/10/26 20:59:22 UTC

[incubator-plc4x] branch master updated: [plc4j-opm] added left over types and added test for the remaining once.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 778b224  [plc4j-opm] added left over types and added test for the remaining once.
778b224 is described below

commit 778b2240b70a2f96182677f6949452fce95fedb7
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Oct 26 22:56:57 2018 +0200

    [plc4j-opm] added left over types and added test for the remaining once.
---
 .../apache/plc4x/java/opm/PlcEntityManager.java    |  9 +--
 .../plc4x/java/opm/PlcEntityManagerTest.java       | 82 ++++++++++++++++++++--
 2 files changed, 80 insertions(+), 11 deletions(-)

diff --git a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
index 0a51049..ccb8e3d 100644
--- a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
+++ b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
@@ -392,14 +392,11 @@ public class PlcEntityManager {
         } else if (clazz == String.class) {
             return response.getString(sourceFieldName);
         } else if (clazz == LocalTime.class) {
-            // TODO: where are the methods for this?
-            throw new UnsupportedOperationException("no supported yet for " + clazz);
+            return response.getTime(sourceFieldName);
         } else if (clazz == LocalDate.class) {
-            // TODO: where are the methods for this?
-            throw new UnsupportedOperationException("no supported yet for " + clazz);
+            return response.getDate(sourceFieldName);
         } else if (clazz == LocalDateTime.class) {
-            // TODO: where are the methods for this?
-            throw new UnsupportedOperationException("no supported yet for " + clazz);
+            return response.getDateTime(sourceFieldName);
         } else if (clazz == byte[].class) {
             return ArrayUtils.toPrimitive(response.getByteArray(sourceFieldName));
         } else if (clazz == Byte[].class) {
diff --git a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java
index ec0dc6c..d43604d 100644
--- a/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java
+++ b/plc4j/utils/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityManagerTest.java
@@ -37,6 +37,12 @@ import org.junit.Test;
 import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -89,7 +95,20 @@ public class PlcEntityManagerTest {
         map.put(prefix + "shortVar", new DefaultShortFieldItem((short) 1));
         map.put(prefix + "intVar", new DefaultIntegerFieldItem(1));
         map.put(prefix + "longVar", new DefaultLongFieldItem(1l));
-        map.put(prefix + "boxedLongVar", new DefaultLongFieldItem(1L));
+        map.put(prefix + "boxedBoolVar", new DefaultLongFieldItem(1L));
+        map.put(prefix + "boxedByteVar", new DefaultByteFieldItem((byte) 1));
+        map.put(prefix + "boxedShortVar", new DefaultShortFieldItem((short) 1));
+        map.put(prefix + "boxedIntegerVar", new DefaultIntegerFieldItem(1));
+        map.put(prefix + "boxedLongVar", new DefaultLongFieldItem(1l));
+        map.put(prefix + "bigIntegerVar", new DefaultBigIntegerFieldItem(BigInteger.ONE));
+        map.put(prefix + "floatVar", new DefaultFloatFieldItem(1f));
+        map.put(prefix + "doubleVar", new DefaultDoubleFieldItem(1d));
+        map.put(prefix + "bigDecimalVar", new DefaultBigDecimalFieldItem(BigDecimal.ONE));
+        map.put(prefix + "localTimeVar", new DefaultLocalTimeFieldItem(LocalTime.of(1, 1)));
+        map.put(prefix + "localDateVar", new DefaultLocalDateFieldItem(LocalDate.of(1, 1, 1)));
+        map.put(prefix + "localDateTimeVar", new DefaultLocalDateTimeFieldItem(LocalDateTime.of(1, 1, 1, 1, 1)));
+        map.put(prefix + "byteArrayVar", new DefaultByteArrayFieldItem(new Byte[]{0x0, 0x1}));
+        map.put(prefix + "bigByteArrayVar", new DefaultByteArrayFieldItem(new Byte[]{0x0, 0x1}));
         map.put(prefix + "stringVar", new DefaultStringFieldItem("Hallo"));
         PlcEntityManager manager = getPlcEntityManager(map);
 
@@ -100,7 +119,7 @@ public class PlcEntityManagerTest {
         // Call different mehtod
         String s = connect.toString();
 
-        assertEquals("ConnectedEntity{boolVar=true, byteVar=1, shortVar=1, intVar=1, longVar=1, boxedLongVar=1, stringVar='Hallo'}", s);
+        assertEquals("ConnectedEntity{boolVar=true, byteVar=1, shortVar=1, intVar=1, longVar=1, boxedBoolVar=true, boxedByteVar=1, boxedShortVar=1, boxedIntegerVar=1, boxedLongVar=1, bigIntegerVar=1, floatVar=1.0, doubleVar=1.0, bigDecimalVar=1, localTimeVar=01:01, localDateVar=0001-01-01, localDateTimeVar=0001-01-01T01:01, byteArrayVar=[0, 1], bigByteArrayVar=[0, 1], stringVar='Hallo'}", s);
     }
 
     @Test
@@ -112,7 +131,20 @@ public class PlcEntityManagerTest {
         map.put(prefix + "shortVar", new DefaultShortFieldItem((short) 1));
         map.put(prefix + "intVar", new DefaultIntegerFieldItem(1));
         map.put(prefix + "longVar", new DefaultLongFieldItem(1l));
-        map.put(prefix + "boxedLongVar", new DefaultLongFieldItem(1L));
+        map.put(prefix + "boxedBoolVar", new DefaultLongFieldItem(1L));
+        map.put(prefix + "boxedByteVar", new DefaultByteFieldItem((byte) 1));
+        map.put(prefix + "boxedShortVar", new DefaultShortFieldItem((short) 1));
+        map.put(prefix + "boxedIntegerVar", new DefaultIntegerFieldItem(1));
+        map.put(prefix + "boxedLongVar", new DefaultLongFieldItem(1l));
+        map.put(prefix + "bigIntegerVar", new DefaultBigIntegerFieldItem(BigInteger.ONE));
+        map.put(prefix + "floatVar", new DefaultFloatFieldItem(1f));
+        map.put(prefix + "doubleVar", new DefaultDoubleFieldItem(1d));
+        map.put(prefix + "bigDecimalVar", new DefaultBigDecimalFieldItem(BigDecimal.ONE));
+        map.put(prefix + "localTimeVar", new DefaultLocalTimeFieldItem(LocalTime.of(1, 1)));
+        map.put(prefix + "localDateVar", new DefaultLocalDateFieldItem(LocalDate.of(1, 1, 1)));
+        map.put(prefix + "localDateTimeVar", new DefaultLocalDateTimeFieldItem(LocalDateTime.of(1, 1, 1, 1, 1)));
+        map.put(prefix + "byteArrayVar", new DefaultByteArrayFieldItem(new Byte[]{0x0, 0x1}));
+        map.put(prefix + "bigByteArrayVar", new DefaultByteArrayFieldItem(new Byte[]{0x0, 0x1}));
         map.put(prefix + "stringVar", new DefaultStringFieldItem("Hallo"));
         PlcEntityManager manager = getPlcEntityManager(map);
 
@@ -123,7 +155,7 @@ public class PlcEntityManagerTest {
         // Call different mehtod
         String s = connect.toString();
 
-        assertEquals("ConnectedEntity{boolVar=true, byteVar=1, shortVar=1, intVar=1, longVar=1, boxedLongVar=1, stringVar='Hallo'}", s);
+        assertEquals("ConnectedEntity{boolVar=true, byteVar=1, shortVar=1, intVar=1, longVar=1, boxedBoolVar=true, boxedByteVar=1, boxedShortVar=1, boxedIntegerVar=1, boxedLongVar=1, bigIntegerVar=1, floatVar=1.0, doubleVar=1.0, bigDecimalVar=1, localTimeVar=01:01, localDateVar=0001-01-01, localDateTimeVar=0001-01-01T01:01, byteArrayVar=[0, 1], bigByteArrayVar=[0, 1], stringVar='Hallo'}", s);
     }
 
     @Test
@@ -313,8 +345,35 @@ public class PlcEntityManagerTest {
         private int intVar;
         @PlcField("%DB1.DW111:LONG")
         private long longVar;
-        @PlcField("%DB1.DW111:STRING")
+        @PlcField("%DB1.DW111:BOOL")
+        private Boolean boxedBoolVar;
+        @PlcField("%DB1.DW111:BYTE")
+        private Byte boxedByteVar;
+        @PlcField("%DB1.DW111:SHORT")
+        private Short boxedShortVar;
+        @PlcField("%DB1.DW111:SHORT")
+        private Integer boxedIntegerVar;
+        @PlcField("%DB1.DW111:LONG")
         private Long boxedLongVar;
+        @PlcField("%DB1.DW111:BIGINT")
+        private BigInteger bigIntegerVar;
+        @PlcField("%DB1.DW111:FLOAT")
+        private Float floatVar;
+        @PlcField("%DB1.DW111:DOUBLE")
+        private Double doubleVar;
+        @PlcField("%DB1.DW111:BIGDECIMAL")
+        private BigDecimal bigDecimalVar;
+        @PlcField("%DB1.DW111:LOCALTIME")
+        private LocalTime localTimeVar;
+        @PlcField("%DB1.DW111:LOCALDATE")
+        private LocalDate localDateVar;
+        @PlcField("%DB1.DW111:LOCALDATETIME")
+        private LocalDateTime localDateTimeVar;
+        @PlcField("%DB1.DW111:BYTEARRAY")
+        private byte[] byteArrayVar;
+        @PlcField("%DB1.DW111:BYTEARRAY")
+        private Byte[] bigByteArrayVar;
+
         @PlcField("%DB1.DW111:STRING")
         private String stringVar;
 
@@ -362,7 +421,20 @@ public class PlcEntityManagerTest {
                 ", shortVar=" + shortVar +
                 ", intVar=" + intVar +
                 ", longVar=" + longVar +
+                ", boxedBoolVar=" + boxedBoolVar +
+                ", boxedByteVar=" + boxedByteVar +
+                ", boxedShortVar=" + boxedShortVar +
+                ", boxedIntegerVar=" + boxedIntegerVar +
                 ", boxedLongVar=" + boxedLongVar +
+                ", bigIntegerVar=" + bigIntegerVar +
+                ", floatVar=" + floatVar +
+                ", doubleVar=" + doubleVar +
+                ", bigDecimalVar=" + bigDecimalVar +
+                ", localTimeVar=" + localTimeVar +
+                ", localDateVar=" + localDateVar +
+                ", localDateTimeVar=" + localDateTimeVar +
+                ", byteArrayVar=" + Arrays.toString(byteArrayVar) +
+                ", bigByteArrayVar=" + Arrays.toString(bigByteArrayVar) +
                 ", stringVar='" + stringVar + '\'' +
                 '}';
         }