use of org.locationtech.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)"));
}
use of org.locationtech.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);
}
use of org.locationtech.jts.io.gml2.GMLHandler in project ddf by codice.
the class XmlInputTransformerTest 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);
}
use of org.locationtech.jts.io.gml2.GMLHandler 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)"));
}
Aggregations