Search in sources :

Example 6 with SaxEventHandlerFactory

use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory 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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) SaxEventHandler(org.codice.ddf.transformer.xml.streaming.SaxEventHandler) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 7 with SaxEventHandlerFactory

use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory 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();
    }
}
Also used : SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) SaxEventHandler(org.codice.ddf.transformer.xml.streaming.SaxEventHandler) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with SaxEventHandlerFactory

use of org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory 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

SaxEventHandlerFactory (org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory)8 Test (org.junit.Test)8 SaxEventHandler (org.codice.ddf.transformer.xml.streaming.SaxEventHandler)6 FileInputStream (java.io.FileInputStream)5 Metacard (ddf.catalog.data.Metacard)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 XmlInputTransformer (org.codice.ddf.transformer.xml.streaming.lib.XmlInputTransformer)2 MetacardType (ddf.catalog.data.MetacardType)1 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 Gml3ToWkt (org.codice.ddf.transformer.xml.streaming.Gml3ToWkt)1