use of org.codice.ddf.transformer.xml.streaming.SaxEventHandler in project ddf by codice.
the class TestGenericXmlLib method testNormalTransform.
@Test
public void testNormalTransform() throws FileNotFoundException, CatalogTransformerException {
InputStream inputStream = new FileInputStream("src/test/resources/metacard2.xml");
SaxEventHandlerFactory saxEventHandlerFactory = mock(SaxEventHandlerFactory.class);
when(saxEventHandlerFactory.getId()).thenReturn("test");
SaxEventHandler handler = getNewHandler();
when(saxEventHandlerFactory.getNewSaxEventHandler()).thenReturn(handler);
XmlInputTransformer xmlInputTransformer = new XmlInputTransformer();
xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("test"));
xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList(saxEventHandlerFactory));
Metacard metacard = null;
try {
metacard = xmlInputTransformer.transform(inputStream, "test");
} catch (IOException e) {
fail();
}
assertThat(metacard.getAttribute(Metacard.METADATA).getValue(), notNullValue());
assertThat(metacard.getAttribute(Metacard.ID).getValue(), is("test"));
}
use of org.codice.ddf.transformer.xml.streaming.SaxEventHandler in project ddf by codice.
the class TestGenericXmlLib method testNullInputTransform.
@Test(expected = CatalogTransformerException.class)
public void testNullInputTransform() throws FileNotFoundException, CatalogTransformerException {
SaxEventHandlerFactory saxEventHandlerFactory = mock(SaxEventHandlerFactory.class);
when(saxEventHandlerFactory.getId()).thenReturn("test");
SaxEventHandler handler = getNewHandler();
when(saxEventHandlerFactory.getNewSaxEventHandler()).thenReturn(handler);
XmlInputTransformer xmlInputTransformer = new XmlInputTransformer();
xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("test"));
xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList(saxEventHandlerFactory));
try {
xmlInputTransformer.transform(null, "test");
} catch (IOException e) {
fail();
}
}
use of org.codice.ddf.transformer.xml.streaming.SaxEventHandler in project ddf by codice.
the class TestGenericXmlLib method getNewHandler.
private SaxEventHandler getNewHandler() {
Attribute attribute = new AttributeImpl(Metacard.TITLE, "foo");
Attribute attribute2 = new AttributeImpl(Metacard.TITLE, "bar");
SaxEventHandler handler = mock(SaxEventHandler.class);
when(handler.getAttributes()).thenReturn(Arrays.asList(attribute, attribute2));
return handler;
}
Aggregations