You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/01/21 14:28:16 UTC

[incubator-plc4x] branch develop updated: - Managed to get the Daffodil testcase working.

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

cdutz 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 7a93015  - Managed to get the Daffodil testcase working.
7a93015 is described below

commit 7a930157b37009ce316e0eff250b352a8f613450
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Jan 21 15:27:57 2019 +0100

    - Managed to get the Daffodil testcase working.
---
 .../src/main/dfdl/daffodil-built-in-catalog.xml    | 25 ++++++++
 .../apache/plc4x/protocols/tpkt-protocol.dfdl.xsd  | 69 +++++++++++-----------
 ...CotpProtocolTest.java => TpktProtocolTest.java} | 18 ++++--
 .../org/apache/plc4x/protocols/cotp-protocol.tdml  | 46 ---------------
 .../org/apache/plc4x/protocols/tpkt-protocol.tdml  | 67 +++++++++++++++++++++
 5 files changed, 140 insertions(+), 85 deletions(-)

diff --git a/protocols/src/main/dfdl/daffodil-built-in-catalog.xml b/protocols/src/main/dfdl/daffodil-built-in-catalog.xml
new file mode 100644
index 0000000..db26ac7
--- /dev/null
+++ b/protocols/src/main/dfdl/daffodil-built-in-catalog.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+  <uri name="http://plc4x.apache.org/tpkt"
+       uri="org/apache/plc4x/protocols/tpkt-protocol.dfdl.xsd"/>
+  <uri name="http://plc4x.apache.org/cotp"
+       uri="org/apache/plc4x/protocols/cotp-protocol.dfdl.xsd"/>
+  <uri name="http://plc4x.apache.org/cotp"
+       uri="org/apache/plc4x/protocols/s7-protocol.dfdl.xsd"/>
+</catalog>
\ No newline at end of file
diff --git a/protocols/src/main/dfdl/org/apache/plc4x/protocols/tpkt-protocol.dfdl.xsd b/protocols/src/main/dfdl/org/apache/plc4x/protocols/tpkt-protocol.dfdl.xsd
index 2341219..6c3e73a 100644
--- a/protocols/src/main/dfdl/org/apache/plc4x/protocols/tpkt-protocol.dfdl.xsd
+++ b/protocols/src/main/dfdl/org/apache/plc4x/protocols/tpkt-protocol.dfdl.xsd
@@ -24,19 +24,22 @@
     <xs:annotation>
         <xs:appinfo source="http://www.ogf.org/dfdl/">
             <dfdl:defineVariable name="messageType" type="xs:string"/>
-            <dfdl:format representation="binary"
-                         binaryNumberRep="binary"
-                         byteOrder="bigEndian"
-                         lengthKind="implicit" lengthUnits="bytes" length="0"
-                         occursCountKind="implicit"
-                         textOutputMinLength="0"
-                         alignment="1" alignmentUnits="bits"
-                         leadingSkip="0" trailingSkip="0"
-                         textPadKind="none" ignoreCase="no"
-                         encoding="utf-8" truncateSpecifiedLengthString="no"
-                         initiator="" terminator=""
-                         sequenceKind="ordered" separator=""
-                         escapeSchemeRef=""  initiatedContent="no"/>
+            <dfdl:defineFormat name="tpktFormat">
+                <dfdl:format representation="binary"
+                             binaryNumberRep="binary"
+                             byteOrder="bigEndian"
+                             lengthKind="implicit" lengthUnits="bytes" length="0"
+                             occursCountKind="implicit"
+                             textOutputMinLength="0"
+                             alignment="1" alignmentUnits="bits"
+                             leadingSkip="0" trailingSkip="0"
+                             textPadKind="none" ignoreCase="no"
+                             encoding="utf-8" truncateSpecifiedLengthString="no"
+                             initiator="" terminator=""
+                             sequenceKind="ordered" separator=""
+                             escapeSchemeRef=""  initiatedContent="no"/>
+            </dfdl:defineFormat>
+            <dfdl:format ref="tpkt:tpktFormat"/>
         </xs:appinfo>
     </xs:annotation>
 
@@ -60,25 +63,25 @@
 
     -->
 
-    <xs:element name="TpktMessage">
-        <xs:complexType>
-            <xs:sequence>
-                <!-- TPKT Magic Byte always 0x03 -->
-                <xs:element name="magicByte" type="tpkt:byte">
-                    <xs:annotation>
-                        <xs:appinfo source="http://www.ogf.org/dfdl/">
-                            <dfdl:assert message="Magic number was not 0x03."
-                                         test="{. eq 3}" />
-                        </xs:appinfo>
-                    </xs:annotation>
-                </xs:element>
-                <xs:element name="reserved" type="tpkt:byte"/>
-                <xs:element name="length" type="tpkt:short"/>
-                <xs:element name="userData" type="xs:hexBinary"
-                            dfdl:byteOrder="bigEndian" dfdl:lengthUnits="bytes" dfdl:lengthKind="explicit"
-                            dfdl:length="{../length - 4}"/>
-            </xs:sequence>
-        </xs:complexType>
-    </xs:element>
+    <xs:element name="TpktMessage" type="tpkt:TpktMessageType"/>
+
+    <xs:complexType name="TpktMessageType">
+        <xs:sequence>
+            <!-- TPKT Magic Byte always 0x03 -->
+            <xs:element name="magicByte" type="tpkt:byte">
+                <xs:annotation>
+                    <xs:appinfo source="http://www.ogf.org/dfdl/">
+                        <dfdl:assert message="Magic number was not 0x03."
+                                     test="{. eq 3}" />
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="reserved" type="tpkt:byte"/>
+            <xs:element name="length" type="tpkt:short"/>
+            <xs:element name="userData" type="xs:hexBinary"
+                        dfdl:byteOrder="bigEndian" dfdl:lengthUnits="bytes" dfdl:lengthKind="explicit"
+                        dfdl:length="{../length - 4}"/>
+        </xs:sequence>
+    </xs:complexType>
 
 </xs:schema>
\ No newline at end of file
diff --git a/protocols/src/test/java/org/apache/plc4x/protocols/CotpProtocolTest.java b/protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java
similarity index 61%
rename from protocols/src/test/java/org/apache/plc4x/protocols/CotpProtocolTest.java
rename to protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java
index a18d5bc..03a4aa3 100644
--- a/protocols/src/test/java/org/apache/plc4x/protocols/CotpProtocolTest.java
+++ b/protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java
@@ -22,17 +22,23 @@ package org.apache.plc4x.protocols;
 import org.apache.daffodil.tdml.DFDLTestSuite;
 import org.apache.daffodil.tdml.Runner;
 import org.apache.daffodil.util.Misc;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-public class CotpProtocolTest {
+public class TpktProtocolTest {
 
-    private String cotpProtocolTestCases = "org/apache/plc4x/protocols/cotp-protocol.tdml";
-    private DFDLTestSuite testSuite = new DFDLTestSuite(Misc.getRequiredResource(cotpProtocolTestCases), true, true, false,
-        Runner.defaultRoundTripDefaultDefault(), Runner.defaultValidationDefaultDefault());
+    private DFDLTestSuite testSuite;
+
+    @BeforeEach
+    public void setup() {
+        String tpktProtocolTestCases = "org/apache/plc4x/protocols/tpkt-protocol.tdml";
+        testSuite = new DFDLTestSuite(Misc.getRequiredResource(tpktProtocolTestCases), true, true, false,
+            Runner.defaultRoundTripDefaultDefault(), Runner.defaultValidationDefaultDefault());
+    }
 
     @Test
-    public void simpleS7Message() {
-        testSuite.runOneTest("cotpConnectResponseInTkptPacket", scala.Option.apply(null), false);
+    public void tpktPacketContainingCotpConnectResponse() {
+        testSuite.runOneTest("tpktPacketContainingCotpConnectResponse", scala.Option.apply(null), false);
     }
 
 }
diff --git a/protocols/src/test/resources/org/apache/plc4x/protocols/cotp-protocol.tdml b/protocols/src/test/resources/org/apache/plc4x/protocols/cotp-protocol.tdml
deleted file mode 100644
index 3b70a36..0000000
--- a/protocols/src/test/resources/org/apache/plc4x/protocols/cotp-protocol.tdml
+++ /dev/null
@@ -1,46 +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.
-  -->
-
-<testSuite suiteName="dpaext"
-           description="Sample tests to post externally"
-           xmlns="http://www.ibm.com/xmlns/dfdl/testData"
-           defaultRoundTrip="true">
-
-    <parserTestCase name="cotpConnectResponseInTkptPacket"
-                    root="root"
-                    model="../../../../../classes/org/apache/plc4x/protocols/tpkt-protocol.dfdl.xsd"
-                    description="Section 1.2 General number example,  What is DFDL - binary numbers">
-
-        <document><documentPart type="byte">0300001611D00001000200C00109C1020100C2020102</documentPart></document>
-        <infoset>
-            <dfdlInfoset>
-                <TpktMessage xmlns="http://plc4x.apache.org/tpkt">
-                    <magicByte>3</magicByte>
-                    <reserved>0</reserved>
-                    <length>22</length>
-                    <userData>11D00001000200C00109C1020100C2020102</userData>
-                </TpktMessage>
-            </dfdlInfoset>
-        </infoset>
-    </parserTestCase>
-
-</testSuite>
-
-
diff --git a/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml b/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
new file mode 100644
index 0000000..652600b
--- /dev/null
+++ b/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
@@ -0,0 +1,67 @@
+<?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.
+  -->
+
+<testSuite xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+           xmlns:test="plc4x-protocol-test"
+           xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+           xmlns:tpkt="http://plc4x.apache.org/tpkt"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           suiteName="plc4x-tpkt"
+           description="Testsuite for the TPKT protocol"
+           defaultRoundTrip="true">
+
+    <tdml:defineSchema name="tkptSchema" elementFormDefault="unqualified">
+        <!-- Import the Schema -->
+        <xs:import namespace="http://plc4x.apache.org/tpkt"
+                   schemaLocation="tpkt-protocol.dfdl.xsd"/>
+
+        <!-- Import the format settings -->
+        <dfdl:format ref="tpkt:tpktFormat"/>
+
+        <!-- Define the root element name and type -->
+        <xs:element name="tpktMessage" type="tpkt:TpktMessageType"/>
+    </tdml:defineSchema>
+
+    <tdml:parserTestCase name="tpktPacketContainingCotpConnectResponse"
+                         root="tpktMessage"
+                         model="tkptSchema"
+                         description="Simple TKPT packet which contains a COTP Connection-Response as payload.">
+        <!-- Define the input -->
+        <tdml:document>
+            <tdml:documentPart type="byte">0300001611D00001000200C00109C1020100C2020102</tdml:documentPart>
+        </tdml:document>
+
+        <!-- Define the expected output -->
+        <tdml:infoset>
+            <tdml:dfdlInfoset>
+                <!-- Referencing what we defined as root element in the defineSchema section -->
+                <test:tpktMessage>
+                    <magicByte>3</magicByte>
+                    <reserved>0</reserved>
+                    <length>22</length>
+                    <userData>11D00001000200C00109C1020100C2020102</userData>
+                </test:tpktMessage>
+            </tdml:dfdlInfoset>
+        </tdml:infoset>
+    </tdml:parserTestCase>
+
+</testSuite>
+
+