use of org.apache.beam.sdk.io.Source.Reader in project beam by apache.
the class XmlSourceTest method testReadXMLInvalidRecordClassWithCustomEventHandler.
@Test
public void testReadXMLInvalidRecordClassWithCustomEventHandler() throws IOException {
File file = tempFolder.newFile("trainXMLSmall");
Files.write(file.toPath(), trainXML.getBytes(StandardCharsets.UTF_8));
ValidationEventHandler validationEventHandler = event -> {
throw new RuntimeException("MyCustomValidationEventHandler failure mesage");
};
BoundedSource<WrongTrainType> source = XmlIO.<WrongTrainType>read().from(file.toPath().toString()).withRootElement("trains").withRecordElement("train").withRecordClass(WrongTrainType.class).withValidationEventHandler(validationEventHandler).createSource();
exception.expect(RuntimeException.class);
// JAXB internationalizes the error message. So this is all we can match for.
exception.expectMessage("MyCustomValidationEventHandler failure mesage");
try (Reader<WrongTrainType> reader = source.createReader(null)) {
for (boolean available = reader.start(); available; available = reader.advance()) {
reader.getCurrent();
}
}
}
Aggregations