Search in sources :

Example 1 with MetacardMarshaller

use of ddf.catalog.transformer.api.MetacardMarshaller in project ddf by codice.

the class TestXmlMetacardTransformer method setup.

@Before
public void setup() {
    Parser parser = new XmlParser();
    MetacardMarshaller metacardMarshaller = new MetacardMarshallerImpl(parser, new PrintWriterProviderImpl());
    transformer = new XmlMetacardTransformer(metacardMarshaller);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) XmlParser(org.codice.ddf.parser.xml.XmlParser) Parser(org.codice.ddf.parser.Parser) Before(org.junit.Before)

Example 2 with MetacardMarshaller

use of ddf.catalog.transformer.api.MetacardMarshaller in project ddf by codice.

the class IntegrationTest method testInputAndOutput.

@Test
public void testInputAndOutput() throws CatalogTransformerException, IOException {
    Parser parser = new XmlParser();
    InputTransformer inputTransformer = new XmlInputTransformer(parser);
    MetacardMarshaller metacardMarshaller = new MetacardMarshallerImpl(parser, new PrintWriterProviderImpl());
    MetacardTransformer outputTransformer = new XmlMetacardTransformer(metacardMarshaller);
    InputStream input = getClass().getResourceAsStream("/extensibleMetacard.xml");
    Metacard metacard = inputTransformer.transform(input);
    LOGGER.info("Attributes: ");
    for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
        Attribute attribute = metacard.getAttribute(descriptor.getName());
        LOGGER.info("\t" + descriptor.getName() + ": " + ((attribute == null) ? attribute : attribute.getValue()));
    }
    BinaryContent output = outputTransformer.transform(metacard, mockArguments);
    String outputString = new String(output.getByteArray());
    // TODO test equivalence with XMLUnit.
    LOGGER.info(outputString);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) Attribute(ddf.catalog.data.Attribute) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) InputStream(java.io.InputStream) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) XmlMetacardTransformer(ddf.catalog.transformer.xml.XmlMetacardTransformer) XmlInputTransformer(ddf.catalog.transformer.xml.XmlInputTransformer) InputTransformer(ddf.catalog.transform.InputTransformer) BinaryContent(ddf.catalog.data.BinaryContent) Parser(org.codice.ddf.parser.Parser) XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) Metacard(ddf.catalog.data.Metacard) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlInputTransformer(ddf.catalog.transformer.xml.XmlInputTransformer) Test(org.junit.Test)

Example 3 with MetacardMarshaller

use of ddf.catalog.transformer.api.MetacardMarshaller in project ddf by codice.

the class TestXmlResponseQueueTransformer method setup.

@Before
public void setup() throws MimeTypeParseException {
    parser = new XmlParser();
    PrintWriterProvider printWriterProvider = new PrintWriterProviderImpl();
    MetacardMarshaller metacardMarshaller = new MetacardMarshallerImpl(parser, printWriterProvider);
    mimeType = getMimeType();
    transformer = new XmlResponseQueueTransformer(parser, FJP, printWriterProvider, metacardMarshaller, mimeType);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) PrintWriterProvider(ddf.catalog.transformer.api.PrintWriterProvider) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlResponseQueueTransformer(ddf.catalog.transformer.xml.XmlResponseQueueTransformer) Before(org.junit.Before)

Example 4 with MetacardMarshaller

use of ddf.catalog.transformer.api.MetacardMarshaller in project ddf by codice.

the class TestXmlResponseQueueTransformer method testCompareSerialToFork.

@Test
public void testCompareSerialToFork() throws IOException, CatalogTransformerException, MimeTypeParseException {
    SourceResponse response = givenSourceResponse(new MetacardStub("source1", "id1"), new MetacardStub("source2", "id2"), new MetacardStub("source3", "id3"), new MetacardStub("source4", "id4"));
    PrintWriterProvider pwp = new PrintWriterProviderImpl();
    MetacardMarshaller mcm = new MetacardMarshallerImpl(parser, pwp);
    XmlResponseQueueTransformer serialXform = new XmlResponseQueueTransformer(parser, FJP, pwp, mcm, getMimeType());
    serialXform.setThreshold(2);
    XmlResponseQueueTransformer forkXForm = new XmlResponseQueueTransformer(parser, FJP, pwp, mcm, getMimeType());
    forkXForm.setThreshold(10);
    BinaryContent serialBc = serialXform.transform(response, null);
    BinaryContent forkBc = forkXForm.transform(response, null);
    String serialOutput = new String(serialBc.getByteArray());
    String forkOutput = new String(forkBc.getByteArray());
    // There are expected whitespace differences between the outputs.
    // This is an overly aggressive conversion; a better test would be to unmarshal the
    // xml metacards back into Metacard instances and compare equality.
    assertEquals(serialOutput.replaceAll("\\s", ""), forkOutput.replaceAll("\\s", ""));
}
Also used : MetacardMarshallerImpl(ddf.catalog.transformer.xml.MetacardMarshallerImpl) PrintWriterProvider(ddf.catalog.transformer.api.PrintWriterProvider) SourceResponse(ddf.catalog.operation.SourceResponse) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlResponseQueueTransformer(ddf.catalog.transformer.xml.XmlResponseQueueTransformer) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 5 with MetacardMarshaller

use of ddf.catalog.transformer.api.MetacardMarshaller in project ddf by codice.

the class TestXmlResponseQueueTransformer method testMimeTypeInitException.

@Test(expected = ExceptionInInitializerError.class)
public void testMimeTypeInitException() throws IOException, CatalogTransformerException, XmlPullParserException, MimeTypeParseException {
    SourceResponse response = givenSourceResponse(new MetacardStub("source1", "id1"));
    PrintWriterProvider pwp = new PrintWriterProviderImpl();
    MetacardMarshaller mockMetacardMarshaller = mock(MetacardMarshaller.class);
    MimeType mockMimeType = mock(MimeType.class);
    doThrow(new MimeTypeParseException("")).when(mockMimeType).setSubType(anyString());
    XmlResponseQueueTransformer xrqt = new XmlResponseQueueTransformer(parser, FJP, pwp, mockMetacardMarshaller, mockMimeType);
    xrqt.setThreshold(2);
    BinaryContent bc = xrqt.transform(response, null);
// then exception
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) PrintWriterProvider(ddf.catalog.transformer.api.PrintWriterProvider) SourceResponse(ddf.catalog.operation.SourceResponse) MetacardMarshaller(ddf.catalog.transformer.api.MetacardMarshaller) PrintWriterProviderImpl(ddf.catalog.transformer.xml.PrintWriterProviderImpl) XmlResponseQueueTransformer(ddf.catalog.transformer.xml.XmlResponseQueueTransformer) BinaryContent(ddf.catalog.data.BinaryContent) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Aggregations

MetacardMarshaller (ddf.catalog.transformer.api.MetacardMarshaller)6 PrintWriterProviderImpl (ddf.catalog.transformer.xml.PrintWriterProviderImpl)6 BinaryContent (ddf.catalog.data.BinaryContent)4 PrintWriterProvider (ddf.catalog.transformer.api.PrintWriterProvider)4 MetacardMarshallerImpl (ddf.catalog.transformer.xml.MetacardMarshallerImpl)4 XmlResponseQueueTransformer (ddf.catalog.transformer.xml.XmlResponseQueueTransformer)4 Test (org.junit.Test)4 SourceResponse (ddf.catalog.operation.SourceResponse)3 XmlParser (org.codice.ddf.parser.xml.XmlParser)3 Metacard (ddf.catalog.data.Metacard)2 XmlMetacardTransformer (ddf.catalog.transformer.xml.XmlMetacardTransformer)2 Parser (org.codice.ddf.parser.Parser)2 Before (org.junit.Before)2 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 InputTransformer (ddf.catalog.transform.InputTransformer)1 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)1 XmlInputTransformer (ddf.catalog.transformer.xml.XmlInputTransformer)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1