use of org.knime.core.data.xml.XMLCell in project knime-core by knime.
the class JavaToDataCellConversionTest method testToXMLCell.
/**
* Test String -> XMLCell, Document -> XMLCell and InputStream -> XMLCell conversions.
*
* @throws Exception When something went wrong
*/
@Test
public void testToXMLCell() throws Exception {
final String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<KNIME>\n</KNIME>";
/* from String */
{
final XMLCell xmlCell = testSimpleConversion(String.class, XMLCell.TYPE, XMLCell.class, new String("<KNIME />"));
assertEquals(xmlString, xmlCell.getStringValue().replace('\'', '"'));
}
/* from Document */
{
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
assertNotNull(documentBuilderFactory);
final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
final XMLCell xmlCell = testSimpleConversion(Document.class, XMLCell.TYPE, XMLCell.class, builder.parse(new InputSource(new StringReader(xmlString))));
assertEquals(xmlString, xmlCell.getStringValue().replace('\'', '"'));
}
/* from InputStream */
try (final InputStream stream = getClass().getResourceAsStream("test.xml")) {
assertTrue(stream.available() > 0);
final XMLCell xmlCell = testSimpleConversion(InputStream.class, XMLCell.TYPE, XMLCell.class, stream);
assertEquals(xmlString, xmlCell.getStringValue().replace('\'', '"'));
}
}
Aggregations