Search in sources :

Example 1 with SaxEventHandlerFactory

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

the class TestXmlInputTransformer method testDescribableGettersSetters.

/*
     * The methods in tested in this Test are either simple getters/setters or NOOPS
     * If any of them ever get implemented, they need to have better, more descriptive tests written.
     */
@Test
public void testDescribableGettersSetters() throws SAXException {
    SaxEventHandlerFactory factory = new XmlSaxEventHandlerFactoryImpl();
    assertThat(factory.getDescription(), is(notNullValue()));
    assertThat(factory.getId(), is(notNullValue()));
    assertThat(factory.getOrganization(), is(notNullValue()));
    assertThat(factory.getTitle(), is(notNullValue()));
    assertThat(factory.getVersion(), is(notNullValue()));
    SaxEventHandler handler = factory.getNewSaxEventHandler();
    handler.setDocumentLocator(null);
    handler.endDocument();
    handler.startPrefixMapping(null, null);
    handler.endPrefixMapping(null);
    handler.ignorableWhitespace(null, 0, 0);
    handler.processingInstruction(null, null);
    handler.skippedEntity(null);
    factory = new GmlHandlerFactory();
    assertThat(factory.getDescription(), is(notNullValue()));
    assertThat(factory.getId(), is(notNullValue()));
    assertThat(factory.getOrganization(), is(notNullValue()));
    assertThat(factory.getTitle(), is(notNullValue()));
    assertThat(factory.getVersion(), is(notNullValue()));
    handler = factory.getNewSaxEventHandler();
    handler.setDocumentLocator(null);
    handler.endDocument();
    handler.endPrefixMapping(null);
    handler.ignorableWhitespace(null, 0, 0);
    handler.processingInstruction(null, null);
    handler.skippedEntity(null);
}
Also used : SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) SaxEventHandler(org.codice.ddf.transformer.xml.streaming.SaxEventHandler) Test(org.junit.Test)

Example 2 with SaxEventHandlerFactory

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

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

the class TestGenericXmlLib method testExceptionHappyHandler.

@Test
public void testExceptionHappyHandler() throws SAXException, 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 4 with SaxEventHandlerFactory

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

the class TestGenericXmlLib method testBadInputTransform.

@Test(expected = CatalogTransformerException.class)
public void testBadInputTransform() throws FileNotFoundException, CatalogTransformerException {
    InputStream inputStream = new FileInputStream("src/test/resources/metacard3InvalidXml.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));
    try {
        xmlInputTransformer.transform(inputStream, "test");
    } catch (IOException e) {
        fail();
    }
}
Also used : 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 5 with SaxEventHandlerFactory

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

the class TestGenericXmlLib method testNoConfigTransform.

@Test
public void testNoConfigTransform() throws IOException, CatalogTransformerException {
    SaxEventHandlerFactory saxEventHandlerFactory = mock(SaxEventHandlerFactory.class);
    when(saxEventHandlerFactory.getId()).thenReturn("test");
    SaxEventHandler handler = getNewHandler();
    when(saxEventHandlerFactory.getNewSaxEventHandler()).thenReturn(handler);
    XmlInputTransformer xmlInputTransformer = new XmlInputTransformer();
    xmlInputTransformer.setSaxEventHandlerFactories(Collections.singletonList(saxEventHandlerFactory));
    xmlInputTransformer.setSaxEventHandlerConfiguration(Collections.singletonList("test"));
    SaxEventHandlerDelegate delegate = xmlInputTransformer.create();
    MetacardType metacardType = delegate.getMetacardType(xmlInputTransformer.getId());
    assertThat(metacardType.getAttributeDescriptors(), is(BasicTypes.BASIC_METACARD.getAttributeDescriptors()));
}
Also used : SaxEventHandlerFactory(org.codice.ddf.transformer.xml.streaming.SaxEventHandlerFactory) SaxEventHandler(org.codice.ddf.transformer.xml.streaming.SaxEventHandler) MetacardType(ddf.catalog.data.MetacardType) 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