use of com.thoughtworks.xstream.converters.MarshallingContext 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();
}
use of com.thoughtworks.xstream.converters.MarshallingContext 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.converters.MarshallingContext in project ddf by codice.
the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetSummary.
@Ignore
public void testMarshalRecordCollectionGetSummary() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.SUMMARY);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.SUMMARY);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.SUMMARY));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.SUMMARY));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of com.thoughtworks.xstream.converters.MarshallingContext in project drools by kiegroup.
the class ContextConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Context c = (Context) parent;
for (ContextEntry ce : c.getContextEntry()) {
writeChildrenNode(writer, context, ce, CONTEXT_ENTRY);
}
}
use of com.thoughtworks.xstream.converters.MarshallingContext in project drools by kiegroup.
the class ContextConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Context c = (Context) parent;
for (ContextEntry ce : c.getContextEntry()) {
writeChildrenNode(writer, context, ce, CONTEXT_ENTRY);
}
}
Aggregations