You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jm...@apache.org on 2017/12/27 04:48:51 UTC

[incubator-plc4x] 01/10: add some simple unit tests

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

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

commit b10875b0520aab13046b42ec7fb1afc0b67009a7
Author: Justin Mclean <jm...@apache.org>
AuthorDate: Sun Dec 24 14:47:27 2017 +1100

    add some simple unit tests
---
 .../isotp/netty/model/params/ParameterTests.java   |  50 +++++++
 .../netty/model/params/TsapParameterTests.java     |  45 ++++++
 .../java/isotp/netty/model/types/TypeTests.java    | 153 +++++++++++++++++++++
 3 files changed, 248 insertions(+)

diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/params/ParameterTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/params/ParameterTests.java
new file mode 100644
index 0000000..66c6e88
--- /dev/null
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/params/ParameterTests.java
@@ -0,0 +1,50 @@
+package org.apache.plc4x.java.isotp.netty.model.params;
+
+import org.apache.plc4x.java.isotp.netty.model.types.DeviceGroup;
+import org.apache.plc4x.java.isotp.netty.model.types.ParameterCode;
+import org.apache.plc4x.java.isotp.netty.model.types.TpduSize;
+import org.junit.jupiter.api.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ParameterTest {
+    private ParameterTest tsapParaameter;
+
+    @BeforeEach
+    void setUp() {
+    }
+
+    @AfterEach
+    void tearDown() {
+        tsapParaameter = null;
+    }
+
+    @Test
+    @Tag("fast")
+    void checksumPartameterTest() {
+        ChecksumParameter checksumParameter = new ChecksumParameter((byte)1);
+
+        assertTrue(checksumParameter.getChecksum() == (byte)1, "Checksum incorrect");
+        assertTrue(checksumParameter.getType() == ParameterCode.CHECKSUM);
+    }
+
+    @Test
+    @Tag("fast")
+    void disconnectAdditionalInformationParameterTest() {
+        byte[] data = {(byte)1, (byte)2};
+        DisconnectAdditionalInformationParameter disconnectParameter = new DisconnectAdditionalInformationParameter(data);
+
+        assertTrue(disconnectParameter.getData()[0] == (byte)1, "Return parameter incorrect");
+        assertTrue(disconnectParameter.getData()[1] == (byte)2, "Return parameter incorrect");
+        assertTrue(disconnectParameter.getType() == ParameterCode.DISCONNECT_ADDITIONAL_INFORMATION);
+    }
+
+    @Test
+    @Tag("fast")
+    void tpduSizeParameterTest() {
+        TpduSizeParameter tpduSizeParameter = new TpduSizeParameter(TpduSize.SIZE_512);
+
+        assertTrue(tpduSizeParameter.getTpduSize() == TpduSize.SIZE_512, "Tpdu size incorrect");
+        assertTrue(tpduSizeParameter.getType() == ParameterCode.TPDU_SIZE);
+    }
+}
\ No newline at end of file
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/params/TsapParameterTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/params/TsapParameterTests.java
new file mode 100644
index 0000000..8f3cdbd
--- /dev/null
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/params/TsapParameterTests.java
@@ -0,0 +1,45 @@
+package org.apache.plc4x.java.isotp.netty.model.params;
+
+import org.apache.plc4x.java.isotp.netty.model.types.DeviceGroup;
+import org.apache.plc4x.java.isotp.netty.model.types.ParameterCode;
+import org.junit.jupiter.api.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class TsapParameterTests {
+    private TsapParameter tsapParameter;
+
+    @BeforeEach
+    void setUp() {
+    }
+
+    @AfterEach
+    void tearDown() {
+        tsapParameter = null;
+    }
+
+    @Test
+    @Tag("fast")
+    void calledPartameterTest() {
+        DeviceGroup deviceGroup = DeviceGroup.valueOf((byte)0);
+        tsapParameter = new CalledTsapParameter(deviceGroup, (byte)1, (byte)4);
+
+        assertTrue(tsapParameter.getDeviceGroup() == DeviceGroup.valueOf((byte)0), "Device group incorrect");
+        assertTrue(tsapParameter.getRackNumber() == (byte)1, "Rack number not correct");
+        assertTrue(tsapParameter.getSlotNumber() == (byte)4, "Slot number not coorect");
+        assertTrue(tsapParameter.getType() == ParameterCode.CALLED_TSAP);
+    }
+
+    @Test
+    @Tag("fast")
+    void callingPartameterTest() {
+        DeviceGroup deviceGroup = DeviceGroup.valueOf((byte)0);
+        tsapParameter = new CallingTsapParameter(deviceGroup, (byte)2, (byte)5);
+
+        assertTrue(tsapParameter.getDeviceGroup() == DeviceGroup.valueOf((byte)0), "Device group incorrect");
+        assertTrue(tsapParameter.getRackNumber() == (byte)2, "Rack number not correct");
+        assertTrue(tsapParameter.getSlotNumber() == (byte)5, "Slot number not coorect");
+        assertTrue(tsapParameter.getType() == ParameterCode.CALLING_TSAP);
+    }
+
+}
\ No newline at end of file
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/TypeTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/TypeTests.java
new file mode 100644
index 0000000..f920854
--- /dev/null
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/TypeTests.java
@@ -0,0 +1,153 @@
+package org.apache.plc4x.java.isotp.netty.model.types;
+
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class TypeTests {
+
+    @Test
+    @Tag("fast")
+    void deviceGroupTest() {
+        DeviceGroup deviceGroup;
+
+        deviceGroup = DeviceGroup.valueOf((byte)1);
+        assertTrue(deviceGroup == DeviceGroup.PG_OR_PC, "1 incorrectly mapped");
+        assertTrue(deviceGroup.getCode() == (byte)1, "code is not 1");
+
+        deviceGroup = DeviceGroup.valueOf((byte)2);
+        assertTrue(deviceGroup == DeviceGroup.OS, "2 incorrectly mapped");
+        assertTrue(deviceGroup.getCode() == (byte)2, "code is not 2");
+
+        deviceGroup = DeviceGroup.valueOf((byte)3);
+        assertTrue(deviceGroup == DeviceGroup.OTHERS, "3 incorrectly mapped");
+        assertTrue(deviceGroup.getCode() == (byte)3, "code is not 3");
+    }
+
+    @Test
+    @Tag("fast")
+    void deviceGroupUnknownTest() {
+        DeviceGroup deviceGroup = DeviceGroup.valueOf((byte)0x40);
+
+        assertNull(deviceGroup, "expected device group to be null");
+    }
+
+
+    @Test
+    @Tag("fast")
+    void disconnectReasonTest() {
+        DisconnectReason disconnectReason = DisconnectReason.valueOf((byte)3);
+
+        assertTrue(DisconnectReason.valueOf((byte)3) == DisconnectReason.ADDRESS_UNKNOWN, "3 incorrectly mapped");
+        assertTrue(disconnectReason.getCode() == (byte)3, "code is not 3");
+    }
+
+    @Test
+    @Tag("fast")
+    void diosconectReasonUnknownTest() {
+        DisconnectReason disconnectReason = DisconnectReason.valueOf((byte)4);
+
+        assertNull(disconnectReason, "expected disconnect reason to be null");
+    }
+
+    @Test
+    @Tag("fast")
+    void parameterCodeTest() {
+        ParameterCode parameterCode = ParameterCode.valueOf((byte)0xC1);
+
+        assertTrue(ParameterCode.valueOf((byte)0xC1) == ParameterCode.CALLING_TSAP, "0xC1 incorrectly mapped");
+        assertTrue(parameterCode.getCode() == (byte)0xC1, "code is not 0xC1");
+    }
+
+    @Test
+    @Tag("fast")
+    void parameterCodeUnknownTest() {
+        ParameterCode parameterCode = ParameterCode.valueOf((byte)0x90);
+
+        assertNull(parameterCode, "expected parameter code to be null");
+    }
+
+    @Test
+    @Tag("fast")
+    void protocolClassTest() {
+        ProtocolClass protocolClass;
+
+        protocolClass = ProtocolClass.valueOf((byte)0x10);
+        assertTrue(protocolClass == ProtocolClass.CLASS_1, "0x10 incorrectly mapped");
+        assertTrue(protocolClass.getCode() == (byte)0x10, "code is not 0x10");
+
+        protocolClass = ProtocolClass.valueOf((byte)0x20);
+        assertTrue(protocolClass == ProtocolClass.CLASS_2, "0x20 incorrectly mapped");
+        assertTrue(protocolClass.getCode() == (byte)0x20, "code is not 0x20");
+
+        protocolClass = ProtocolClass.valueOf((byte)0x30);
+        assertTrue(protocolClass == ProtocolClass.CLASS_3, "0x30 incorrectly mapped");
+        assertTrue(protocolClass.getCode() == (byte)0x30, "code is not 0x30");
+
+        protocolClass = ProtocolClass.valueOf((byte)0x40);
+        assertTrue(protocolClass == ProtocolClass.CLASS_4, "0x40 incorrectly mapped");
+        assertTrue(protocolClass.getCode() == (byte)0x40, "code is not 0x40");
+    }
+
+    @Test
+    @Tag("fast")
+    void protocolClassUnknownTest() {
+        ProtocolClass protocolClass = ProtocolClass.valueOf((byte)0x50);
+
+        assertNull(protocolClass, "expected protocol class to be null");
+    }
+
+    @Test
+    @Tag("fast")
+    void rejectCauseTest() {
+        RejectCause rejectCause = RejectCause.valueOf((byte)0x03);
+
+        assertTrue(RejectCause.valueOf((byte)0x03) == RejectCause.INVALID_PARAMETER_TYPE, "0x03 incorrectly mapped");
+        assertTrue(rejectCause.getCode() == (byte)0x03, "code is not 0x03");
+    }
+
+    @Test
+    @Tag("fast")
+    void rejectClauseUnknownTest() {
+        RejectCause rejectCause = RejectCause.valueOf((byte)0x90);
+
+        assertNull(rejectCause, "expected reject cause to be null");
+    }
+
+    @Test
+    @Tag("fast")
+    void tpduCodeTest() {
+        TpduCode tpduCode = TpduCode.valueOf((byte)0xF0);
+
+        assertTrue(TpduCode.valueOf((byte)0xF0) == TpduCode.DATA, "0xF0 incorrectly mapped");
+        assertTrue(tpduCode.getCode() == (byte)0xF0, "code is not 0xF0");
+    }
+
+    @Test
+    @Tag("fast")
+    void tpduCodeUnknownTest() {
+        TpduCode tpduCode = TpduCode.valueOf((byte)0x01);
+
+        assertNull(tpduCode, "expected tpdu code to be null");
+    }
+
+    @Test
+    @Tag("fast")
+    void typduSizeTest() {
+        TpduSize tpduSize = TpduSize.valueOf((byte)0x07);
+
+        assertTrue(TpduSize.valueOf((byte)0x07) == TpduSize.SIZE_128, "0x07 incorrectly mapped");
+        assertTrue(tpduSize.getCode() == (byte)0x07, "code is not 0x07");
+    }
+
+    @Test
+    @Tag("fast")
+    void tpduSizeUnknownTest() {
+        TpduSize tpduSize = TpduSize.valueOf((byte)0x06);
+
+        assertNull(tpduSize, "expected tpdu size to be null");
+    }
+
+
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.