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);
}
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);
}
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));
}
Aggregations