Search in sources :

Example 11 with TreeMarshaller

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

the class TestCswRecordConverter method testMarshalRecord.

@Test
public void testMarshalRecord() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    assertThat(xml, containsString(CswConstants.CSW_RECORD));
    assertRecordXml(xml, metacard, FULL);
}
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 12 with TreeMarshaller

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

the class TestCswRecordConverter 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, ElementSetType.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 13 with TreeMarshaller

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

the class TestGmdConverter method convert.

private String convert(Object object, boolean writeNamespaces) {
    GmdConverter converter = new GmdConverter();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter, new NoNameCoder());
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.WRITE_NAMESPACES, writeNamespaces);
    converter.marshal(object, writer, context);
    return stringWriter.toString();
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 14 with TreeMarshaller

use of com.thoughtworks.xstream.core.TreeMarshaller 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)

Example 15 with TreeMarshaller

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

the class CswRecordConverterTest method testMarshalRecord.

@Test
public void testMarshalRecord() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    assertThat(xml, containsString(CswConstants.CSW_RECORD));
    assertRecordXml(xml, metacard, FULL);
}
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)

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