Search in sources :

Example 1 with XmlInputTransformer

use of org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer 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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) XmlInputTransformer(org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer) SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) FileInputStream(java.io.FileInputStream) Gml3ToWkt(org.codice.ddf.transformer.xml.streaming.Gml3ToWkt) Test(org.junit.Test)

Example 2 with XmlInputTransformer

use of org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer in project ddf by codice.

the class TestXmlInputTransformer method testGml3Conversion.

@Test
public void testGml3Conversion() throws FileNotFoundException, CatalogTransformerException {
    inputStream = new FileInputStream("src/test/resources/metacard1.xml");
    xmlInputTransformer = new XmlInputTransformer();
    xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("gml-handler"));
    GmlHandlerFactory factory = new GmlHandlerFactory();
    factory.setGml3ToWkt(gml3ToWkt);
    xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList((SaxEventHandlerFactory) factory));
    Metacard metacard = xmlInputTransformer.transform(inputStream);
    assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValue(), is("POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10), (20 30, 35 35, 30 20, 20 30))"));
}
Also used : Metacard(ddf.catalog.data.Metacard) XmlInputTransformer(org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer) SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)2 FileInputStream (java.io.FileInputStream)2 SaxEventHandlerFactory (org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory)2 XmlInputTransformer (org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer)2 Test (org.junit.Test)2 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 Gml3ToWkt (org.codice.ddf.transformer.xml.streaming.Gml3ToWkt)1