Search in sources :

Example 1 with GMLHandler

use of com.vividsolutions.jts.io.gml2.GMLHandler in project ddf by codice.

the class TestXmlInputTransformer 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(com.vividsolutions.jts.geom.GeometryFactory) GMLHandler(com.vividsolutions.jts.io.gml2.GMLHandler) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with GMLHandler

use of com.vividsolutions.jts.io.gml2.GMLHandler in project ddf by codice.

the class TestXmlInputTransformer method testBadGHTransform.

@Test(expected = NullPointerException.class)
public void testBadGHTransform() throws FileNotFoundException, CatalogTransformerException, SAXException {
    inputStream = new FileInputStream("src/test/resources/metacard2.xml");
    saxEventHandler = new XmlSaxEventHandlerFactoryImpl().getNewSaxEventHandler();
    GMLHandler gh = mock(GMLHandler.class);
    doThrow(new SAXException()).when(gh).characters(any(char[].class), anyInt(), anyInt());
    doThrow(new SAXException()).when(gh).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
    doThrow(new SAXException()).when(gh).endElement(anyString(), anyString(), anyString());
    gmlHandler = new GmlHandler(gh, gml3ToWkt);
    saxEventHandlerDelegate = new SaxEventHandlerDelegate(Arrays.asList(saxEventHandler, gmlHandler));
    saxEventHandlerDelegate.read(inputStream);
}
Also used : SaxEventHandlerDelegate(org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate) GMLHandler(com.vividsolutions.jts.io.gml2.GMLHandler) Attributes(org.xml.sax.Attributes) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Aggregations

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