use of com.thoughtworks.xstream.converters.MarshallingContext 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.converters.MarshallingContext 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));
}
use of com.thoughtworks.xstream.converters.MarshallingContext in project workflow-cps-plugin by jenkinsci.
the class CpsThreadGroup method asXml.
@CpsVmThreadOnly
String asXml() {
XStream xs = new XStream();
// (and anyway these Describable objects would be serialized fine by XStream, just not JBoss Marshalling).
for (SingleTypedPickleFactory<?> stpf : ExtensionList.lookup(SingleTypedPickleFactory.class)) {
Class<?> factoryType = Functions.getTypeParameter(stpf.getClass(), SingleTypedPickleFactory.class, 0);
xs.registerConverter(new Converter() {
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Pickle p = stpf.writeReplace(source);
assert p != null : "failed to pickle " + source + " using " + stpf;
context.convertAnother(p);
}
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
// unused
throw new UnsupportedOperationException();
}
@SuppressWarnings("rawtypes")
@Override
public boolean canConvert(Class type) {
return factoryType.isAssignableFrom(type);
}
});
}
// Could also register a convertor for FlowExecutionOwner, though it seems harmless.
return xs.toXML(this);
}
Aggregations