Search in sources :

Example 11 with HierarchicalStreamWriter

use of com.thoughtworks.xstream.io.HierarchicalStreamWriter in project ddf by codice.

the class TestCswTransformProvider method testMarshalCswRecord.

@Test
public void testMarshalCswRecord() throws Exception {
    when(mockMetacardManager.getTransformerBySchema(CswConstants.CSW_OUTPUT_SCHEMA)).thenReturn(mockCswRecordConverter);
    when(mockCswRecordConverter.transform(any(Metacard.class), any(Map.class))).thenReturn(new BinaryContentImpl(IOUtils.toInputStream(getRecord()), 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);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    provider.marshal(getMetacard(), writer, context);
    // Verify the context arguments were set correctly
    verify(mockMetacardManager, times(1)).getTransformerBySchema(captor.capture());
    String outputSchema = captor.getValue();
    assertThat(outputSchema, is(CswConstants.CSW_OUTPUT_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) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Aggregations

HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)11 Test (org.junit.Test)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)6 XStream (com.thoughtworks.xstream.XStream)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)3 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)3 XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)3 Map (java.util.Map)3 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)2 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)2 Metacard (ddf.catalog.data.Metacard)2 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 HashMap (java.util.HashMap)2 MimeType (javax.activation.MimeType)2 DateTimeConverter (org.apache.camel.component.salesforce.api.utils.DateTimeConverter)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1