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));
}
use of com.thoughtworks.xstream.core.TreeMarshaller in project ddf by codice.
the class TestCswRecordConverter method testMarshalBriefRecord.
@Test
public void testMarshalBriefRecord() 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.BRIEF);
converter.marshal(metacard, writer, context);
String xml = stringWriter.toString();
assertThat(xml, containsString(CswConstants.CSW_BRIEF_RECORD));
assertRecordXml(xml, metacard, BRIEF);
}
use of com.thoughtworks.xstream.core.TreeMarshaller in project ddf by codice.
the class TestCswRecordConverter method testMarshalRecordWithNamespaces.
@Test
public void testMarshalRecordWithNamespaces() 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.WRITE_NAMESPACES, true);
converter.marshal(metacard, writer, context);
String xml = stringWriter.toString();
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual(getControlRecord(), xml);
}
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);
}
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);
}
Aggregations