Search in sources :

Example 6 with SaxEventHandlerDelegate

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

the class XmlInputTransformerTest method testNormalTransform.

/*
     Tests a base XmlInputTransformer, CONTENT_TYPE is null because it is not in the base xmlToMetacard mapping
  */
@Test
public void testNormalTransform() throws FileNotFoundException, CatalogTransformerException {
    inputStream = new FileInputStream("src/test/resources/metacard2.xml");
    saxEventHandlerFactory = new XmlSaxEventHandlerFactoryImpl();
    saxEventHandler = saxEventHandlerFactory.getNewSaxEventHandler();
    assertThat(saxEventHandler.getSupportedAttributeDescriptors().size(), is(greaterThan(0)));
    GMLHandler gh = new GMLHandler(new GeometryFactory(), (ErrorHandler) null);
    gmlHandler = new GmlHandler(gh, gml3ToWkt);
    assertThat(gmlHandler.getSupportedAttributeDescriptors().size(), is(greaterThan(0)));
    saxEventHandlerDelegate = new SaxEventHandlerDelegate(Arrays.asList(saxEventHandler, gmlHandler));
    Metacard metacard = saxEventHandlerDelegate.read(inputStream).getMetacard(null);
    assertThat(metacard.getAttribute(Metacard.TITLE).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.TITLE).getValues().get(0), is("Title!"));
    assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.DESCRIPTION).getValues().get(0), is("Description!"));
    assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.POINT_OF_CONTACT).getValues().get(0), is("POC!"));
    assertThat(metacard.getAttribute(Metacard.RESOURCE_URI).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.RESOURCE_URI).getValues().get(0), is("foobar"));
    assertThat(metacard.getAttribute(Metacard.CONTENT_TYPE), is(nullValue()));
    assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValues().size(), is(1));
    assertThat(metacard.getAttribute(Metacard.GEOGRAPHY).getValues().get(0), is("POINT (100 200)"));
}
Also used : SaxEventHandlerDelegate(org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate) Metacard(ddf.catalog.data.Metacard) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) GMLHandler(org.locationtech.jts.io.gml2.GMLHandler) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

FileInputStream (java.io.FileInputStream)6 SaxEventHandlerDelegate (org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate)6 Test (org.junit.Test)6 Metacard (ddf.catalog.data.Metacard)4 GMLHandler (com.vividsolutions.jts.io.gml2.GMLHandler)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GMLHandler (org.locationtech.jts.io.gml2.GMLHandler)2 Attributes (org.xml.sax.Attributes)2 SAXException (org.xml.sax.SAXException)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1