Search in sources :

Example 16 with TreeMarshaller

use of com.thoughtworks.xstream.core.TreeMarshaller in project ddf by codice.

the class CswRecordConverterTest method testMarshalSummaryRecord.

@Test
public void testMarshalSummaryRecord() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.ELEMENT_SET_TYPE, SUMMARY);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    assertThat(xml, containsString(CswConstants.CSW_SUMMARY_RECORD));
    assertRecordXml(xml, metacard, SUMMARY);
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 17 with TreeMarshaller

use of com.thoughtworks.xstream.core.TreeMarshaller in project ddf by codice.

the class CswTransformProviderTest method testMarshalNoTransformers.

@Test(expected = ConversionException.class)
public void testMarshalNoTransformers() throws Exception {
    when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(null);
    StringWriter stringWriter = new StringWriter();
    HierarchicalStreamWriter writer = new WstxDriver().createWriter(stringWriter);
    CswTransformProvider provider = new CswTransformProvider(mockMetacardManager, null);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    provider.marshal(getMetacard(), writer, context);
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) StringWriter(java.io.StringWriter) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Test(org.junit.Test)

Example 18 with TreeMarshaller

use of com.thoughtworks.xstream.core.TreeMarshaller in project ddf by codice.

the class CswTransformProviderTest method testMarshalOtherSchema.

@Test
public void testMarshalOtherSchema() throws Exception {
    when(mockMetacardManager.getTransformerByProperty(TransformerManager.SCHEMA, OTHER_SCHEMA)).thenReturn(mockMetacardTransformer);
    when(mockMetacardTransformer.transform(any(Metacard.class), any(Map.class))).thenReturn(new BinaryContentImpl(IOUtils.toInputStream(getRecord(), StandardCharsets.UTF_8), new MimeType(MediaType.APPLICATION_XML)));
    StringWriter stringWriter = new StringWriter();
    HierarchicalStreamWriter writer = new WstxDriver().createWriter(stringWriter);
    CswTransformProvider provider = new CswTransformProvider(mockMetacardManager, null);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.SCHEMA);
    context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, OTHER_SCHEMA);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    provider.marshal(getMetacard(), writer, context);
    // Verify the context arguments were set correctly
    verify(mockMetacardManager, times(1)).getTransformerByProperty(captor.capture(), captor.capture());
    String outputSchema = captor.getValue();
    assertThat(outputSchema, is(OTHER_SCHEMA));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Aggregations

MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)18 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)18 StringWriter (java.io.StringWriter)18 Test (org.junit.Test)14 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)12 Metacard (ddf.catalog.data.Metacard)12 Matchers.containsString (org.hamcrest.Matchers.containsString)8 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)6 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)6 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MimeType (javax.activation.MimeType)4 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Matchers.anyString (org.mockito.Matchers.anyString)2 XStreamException (com.thoughtworks.xstream.XStreamException)1 BinaryContent (ddf.catalog.data.BinaryContent)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1