use of org.apache.plc4x.test.driver.exceptions.DriverTestsuiteException in project plc4x by apache.
the class DriverTestsuite method parseTestsuite.
public static DriverTestsuite parseTestsuite(URI suiteUri, InputStream testsuiteDocumentXml, boolean autoMigrate) throws DriverTestsuiteException {
try {
SAXReader reader = new LocationAwareSAXReader();
reader.setDocumentFactory(new LocationAwareDocumentFactory());
Document document = reader.read(testsuiteDocumentXml);
Element testsuiteXml = document.getRootElement();
// Force the driver to not wait for the connection before returning the connection.
System.setProperty(GeneratedDriverBase.PROPERTY_PLC4X_FORCE_AWAIT_SETUP_COMPLETE, "false");
// Force the driver to not wait for the disconnection before returning closing the channel.
System.setProperty(GeneratedDriverBase.PROPERTY_PLC4X_FORCE_AWAIT_DISCONNECT_COMPLETE, "false");
// TODO: replace with signal
Delay.delay(200);
// Shared instance for synchronizing
Synchronizer synchronizer = new Synchronizer();
DriverTestsuiteBuilder driverTestsuiteBuilder = new DriverTestsuiteBuilder(suiteUri, testsuiteXml, synchronizer, autoMigrate);
return driverTestsuiteBuilder.build();
} catch (DocumentException e) {
throw new DriverTestsuiteException("Error parsing testsuite xml", e);
}
}
use of org.apache.plc4x.test.driver.exceptions.DriverTestsuiteException in project plc4x by apache.
the class TestStep method parseTestStep.
public static TestStep parseTestStep(Element curElement, Synchronizer synchronizer, DriverTestsuiteConfiguration driverTestsuiteConfiguration) throws DriverTestsuiteException {
final String elementName = curElement.getName();
final StepType stepType = StepType.valueOf(elementName.toUpperCase().replace("-", "_"));
final String stepName = curElement.attributeValue(new QName("name"));
Element parserArgumentsNode = null;
Element definitionNode = null;
for (Element element : curElement.elements()) {
if (element.getName().equals("parser-arguments")) {
parserArgumentsNode = element;
} else if (definitionNode == null) {
definitionNode = element;
} else {
throw new DriverTestsuiteException("Error processing the xml. Only one content node allowed.");
}
}
final List<String> parserArguments = new ArrayList<>();
if (parserArgumentsNode != null) {
for (Element parserArgumentNode : parserArgumentsNode.elements()) {
parserArguments.add(parserArgumentNode.getTextTrim());
}
}
Location location = null;
if (curElement instanceof LocationAwareElement) {
location = ((LocationAwareElement) curElement).getLocation();
}
return new TestStep(stepType, stepName, location, parserArguments, definitionNode, synchronizer, driverTestsuiteConfiguration);
}
use of org.apache.plc4x.test.driver.exceptions.DriverTestsuiteException in project plc4x by apache.
the class IncomingPlcMessageHandler method getBytesFromXml.
@SuppressWarnings({ "rawtypes", "unchecked" })
public byte[] getBytesFromXml(Element referenceXml, ByteOrder byteOrder) throws DriverTestsuiteException {
final WriteBufferByteBased writeBuffer = new WriteBufferByteBased(1024, byteOrder);
MessageInput messageInput = MessageResolver.getMessageInput(driverTestsuiteConfiguration.getOptions(), referenceXml.getName());
// Get Message and Validate
Message message = MessageValidatorAndMigrator.validateInboundMessageAndGet(messageInput, referenceXml, parserArguments);
// Get Bytes
try {
message.serialize(writeBuffer);
final byte[] data = new byte[message.getLengthInBytes()];
System.arraycopy(writeBuffer.getData(), 0, data, 0, writeBuffer.getPos());
return data;
} catch (SerializationException e) {
throw new DriverTestsuiteException("Error serializing message", e);
}
}
use of org.apache.plc4x.test.driver.exceptions.DriverTestsuiteException in project plc4x by apache.
the class MessageResolver method getMessageIOType.
@SuppressWarnings("unchecked")
private static TypeMessageInput getMessageIOType(Map<String, String> options, String typeName) throws DriverTestsuiteException, ClassNotFoundException {
String extraMessage = "";
if (options.containsKey("package")) {
try {
return lookup(options.get("package"), typeName);
} catch (NoSuchMethodException e) {
extraMessage = "custom package '" + options.get("package") + "' and ";
}
}
String protocolName = options.get("protocolName");
String outputFlavor = options.get("outputFlavor");
String classPackage = String.format("org.apache.plc4x.java.%s.%s", protocolName, StringUtils.replace(outputFlavor, "-", ""));
try {
return lookup(classPackage, typeName);
} catch (NoSuchMethodException e) {
throw new DriverTestsuiteException("Could not find " + typeName + " in " + extraMessage + "standard package '" + classPackage + "'");
}
}
use of org.apache.plc4x.test.driver.exceptions.DriverTestsuiteException in project plc4x by apache.
the class ChannelUtil method getOutboundBytes.
public static byte[] getOutboundBytes(Plc4xEmbeddedChannel embeddedChannel) throws DriverTestsuiteException {
ByteBuf byteBuf = null;
for (int i = 0; i < MAX_TRIES; i++) {
byteBuf = embeddedChannel.readOutbound();
if (byteBuf != null) {
break;
}
Delay.delay(10);
}
if (byteBuf == null) {
throw new DriverTestsuiteException(String.format("No outbound message available within %dms", 10 * MAX_TRIES));
}
final byte[] data = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(data);
return data;
}
Aggregations