use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory in project ddf by codice.
the class TestXmlInputTransformer method testDescribableGettersSetters.
/*
* The methods in tested in this Test are either simple getters/setters or NOOPS
* If any of them ever get implemented, they need to have better, more descriptive tests written.
*/
@Test
public void testDescribableGettersSetters() throws SAXException {
SaxEventHandlerFactory factory = new XmlSaxEventHandlerFactoryImpl();
assertThat(factory.getDescription(), is(notNullValue()));
assertThat(factory.getId(), is(notNullValue()));
assertThat(factory.getOrganization(), is(notNullValue()));
assertThat(factory.getTitle(), is(notNullValue()));
assertThat(factory.getVersion(), is(notNullValue()));
SaxEventHandler handler = factory.getNewSaxEventHandler();
handler.setDocumentLocator(null);
handler.endDocument();
handler.startPrefixMapping(null, null);
handler.endPrefixMapping(null);
handler.ignorableWhitespace(null, 0, 0);
handler.processingInstruction(null, null);
handler.skippedEntity(null);
factory = new GmlHandlerFactory();
assertThat(factory.getDescription(), is(notNullValue()));
assertThat(factory.getId(), is(notNullValue()));
assertThat(factory.getOrganization(), is(notNullValue()));
assertThat(factory.getTitle(), is(notNullValue()));
assertThat(factory.getVersion(), is(notNullValue()));
handler = factory.getNewSaxEventHandler();
handler.setDocumentLocator(null);
handler.endDocument();
handler.endPrefixMapping(null);
handler.ignorableWhitespace(null, 0, 0);
handler.processingInstruction(null, null);
handler.skippedEntity(null);
}
use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory in project ddf by codice.
the class TestXmlInputTransformer method testBadGml3Converter.
@Test
public void testBadGml3Converter() throws FileNotFoundException, CatalogTransformerException, ValidationException {
inputStream = new FileInputStream("src/test/resources/metacard1.xml");
xmlInputTransformer = new XmlInputTransformer();
xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("gml-handler"));
GmlHandlerFactory factory = new GmlHandlerFactory();
Gml3ToWkt badGml3toWkt = mock(Gml3ToWkt.class);
when(badGml3toWkt.convert(anyString())).thenThrow(new ValidationExceptionImpl());
factory.setGml3ToWkt(badGml3toWkt);
xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList((SaxEventHandlerFactory) factory));
Metacard metacard = xmlInputTransformer.transform(inputStream);
assertThat(metacard.getAttribute(Validation.VALIDATION_ERRORS).getValue(), is("geospatial-handler"));
}
use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory in project ddf by codice.
the class TestGenericXmlLib method testExceptionHappyHandler.
@Test
public void testExceptionHappyHandler() throws SAXException, 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.SaxEventHandlerFactory in project ddf by codice.
the class TestGenericXmlLib method testBadInputTransform.
@Test(expected = CatalogTransformerException.class)
public void testBadInputTransform() throws FileNotFoundException, CatalogTransformerException {
InputStream inputStream = new FileInputStream("src/test/resources/metacard3InvalidXml.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));
try {
xmlInputTransformer.transform(inputStream, "test");
} catch (IOException e) {
fail();
}
}
use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory in project ddf by codice.
the class TestGenericXmlLib method testNoConfigTransform.
@Test
public void testNoConfigTransform() throws IOException, CatalogTransformerException {
SaxEventHandlerFactory saxEventHandlerFactory = mock(SaxEventHandlerFactory.class);
when(saxEventHandlerFactory.getId()).thenReturn("test");
SaxEventHandler handler = getNewHandler();
when(saxEventHandlerFactory.getNewSaxEventHandler()).thenReturn(handler);
XmlInputTransformer xmlInputTransformer = new XmlInputTransformer();
xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList(saxEventHandlerFactory));
xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("test"));
SaxEventHandlerDelegate delegate = xmlInputTransformer.create();
MetacardType metacardType = delegate.getMetacardType(xmlInputTransformer.getId());
assertThat(metacardType.getAttributeDescriptors(), is(BasicTypes.BASIC_METACARD.getAttributeDescriptors()));
}
Aggregations