Hi all, I just finished a first version of some tooling to test PLC4X generated Java drivers. It’s greatly inspired by the way I could specify tests with Daffodil. Here is an example test:
<test:testsuite xmlns:test="https://plc4x.apache.org/schemas/testsuite.xsd"> <name>KNXNet/IP</name> <testcase> <name>Default</name> <raw>0610020500180801c0a82a46c4090801c0a82a46c40a0203</raw> <root-type>KNXNetIPMessage</root-type> <xml> <ConnectionRequest className="org.apache.plc4x.java.knxnetip.ConnectionRequest"> <protocolVersion>16</protocolVersion> <hpaiDiscoveryEndpoint> <hostProtocolCode>1</hostProtocolCode> <ipAddress> <addr> <addr>192</addr> <addr>168</addr> <addr>42</addr> <addr>70</addr> </addr> </ipAddress> <ipPort>50185</ipPort> </hpaiDiscoveryEndpoint> <hpaiDataEndpoint> <hostProtocolCode>1</hostProtocolCode> <ipAddress> <addr> <addr>192</addr> <addr>168</addr> <addr>42</addr> <addr>70</addr> </addr> </ipAddress> <ipPort>50186</ipPort> </hpaiDataEndpoint> <connectionRequestInformation className="org.apache.plc4x.java.knxnetip.ConnectionRequestInformationDeviceManagement"/> </ConnectionRequest> </xml> </testcase> </test:testsuite> This automatically iterates over all “testcase” elements, takes the hex encoded byte data in “raw” and parses this. After that it serializes the parsed data to XML and compares it to the reference in the “xml” element. For this I had to fine-tune the code generation quite a bit, but now I’m even happier with the results. In order to add tests to a module, all you need to do, is to add a class that extends from “ProtocolTestsuiteRunner”: package org.apache.plc4x.java.knxnetip; import org.apache.plc4x.protocol.test.ProtocolTestsuiteRunner; public class KNXNetIpTestsuite extends ProtocolTestsuiteRunner { public KNXNetIpTestsuite() { super("/testsuite/KNXNetIPTestsuite.xml"); } } Feedback welcome :-) At least now I can start mass-producing tests for the stuff I do. And I think it’s a great basis for even building diagnosis utils that could help us inspect issues which users report. Chris
