use of com.thoughtworks.xstream.converters.DataHolder in project jmeter by apache.
the class SaveService method loadTestResults.
/**
* Read results from JTL file.
*
* @param reader of the file
* @param resultCollectorHelper helper class to enable TestResultWrapperConverter to deliver the samples
* @throws IOException if an I/O error occurs
*/
public static void loadTestResults(InputStream reader, ResultCollectorHelper resultCollectorHelper) throws IOException {
// Get the InputReader to use
InputStreamReader inputStreamReader = getInputStreamReader(reader);
DataHolder dh = JTLSAVER.newDataHolder();
// Allow TestResultWrapper to feed back the samples
dh.put(RESULTCOLLECTOR_HELPER_OBJECT, resultCollectorHelper);
// This is effectively the same as saver.fromXML(InputStream) except we get to provide the DataHolder
// Don't know why there is no method for this in the XStream class
JTLSAVER.unmarshal(new XppDriver().createReader(reader), null, dh);
inputStreamReader.close();
}
use of com.thoughtworks.xstream.converters.DataHolder in project ddf by codice.
the class CswRecordConverterTest method testUnmarshalCswRecordWithProductAndThumbnail.
@Test
public void testUnmarshalCswRecordWithProductAndThumbnail() throws Exception {
XStream xstream = createXstream(new WstxDriver());
xstream.registerConverter(converter);
InputStream is = CswRecordConverterTest.class.getResourceAsStream("/Csw_Record.xml");
// get the URL to the thumbnail image and stick it in the xml string
// this makes the test filesystem independent
URL thumbnail = CswRecordConverterTest.class.getResource("/ddf_globe.png");
String xml = null;
if (thumbnail != null) {
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
xml = writer.toString();
xml = xml.replace(THUMBNAIL_URL, thumbnail.toString());
}
xstream.alias("csw:Record", MetacardImpl.class);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(IOUtils.toInputStream(xml, StandardCharsets.UTF_8));
HierarchicalStreamReader reader = new DomReader(doc);
DataHolder holder = xstream.newDataHolder();
Metacard mc = (Metacard) xstream.unmarshal(reader, null, holder);
assertThat(mc, notNullValue());
String productUrl = "http://example.com/product.pdf";
assertThat(mc.getAttribute(Core.RESOURCE_URI).getValue(), is(productUrl));
assertThat(mc.getThumbnail(), is(getThumbnailByteArray(thumbnail)));
}
use of com.thoughtworks.xstream.converters.DataHolder in project ddf by codice.
the class CswRecordConverterTest method testUnmarshalSingleCswRecordToMetacardContentTypeMapsToFormat.
@Test
public void testUnmarshalSingleCswRecordToMetacardContentTypeMapsToFormat() throws ParserConfigurationException, IOException, SAXException {
XStream xstream = createXstream(new WstxDriver());
xstream.registerConverter(converter);
xstream.alias("csw:Record", MetacardImpl.class);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(CswRecordConverterTest.class.getResource("/Csw_Record.xml").getPath());
HierarchicalStreamReader reader = new DomReader(doc);
DataHolder holder = xstream.newDataHolder();
Metacard mc = (Metacard) xstream.unmarshal(reader, null, holder);
assertThat(mc, notNullValue());
assertThat(mc.getContentTypeName(), is("IMAGE-PRODUCT"));
assertThat(mc.getAttribute(Media.FORMAT).getValue(), is("PDF"));
}
use of com.thoughtworks.xstream.converters.DataHolder in project ddf by codice.
the class CswRecordConverterTest method testUnmarshalWriteNamespaces.
@Test
public void testUnmarshalWriteNamespaces() throws Exception {
XStream xstream = createXstream(new XppDriver());
xstream.registerConverter(converter);
xstream.alias("Record", MetacardImpl.class);
xstream.alias("csw:Record", MetacardImpl.class);
InputStream is = IOUtils.toInputStream(getRecordNoNamespaceDeclaration(), StandardCharsets.UTF_8);
HierarchicalStreamReader reader = new XppReader(new InputStreamReader(is), XmlPullParserFactory.newInstance().newPullParser());
DataHolder args = xstream.newDataHolder();
Map<String, String> namespaces = new HashMap<>();
namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.CSW_NAMESPACE_PREFIX, CswConstants.CSW_OUTPUT_SCHEMA);
namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX, CswConstants.DUBLIN_CORE_SCHEMA);
namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.DUBLIN_CORE_TERMS_NAMESPACE_PREFIX, CswConstants.DUBLIN_CORE_TERMS_SCHEMA);
namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_NAMESPACE_PREFIX, CswConstants.OWS_NAMESPACE);
args.put(CswConstants.NAMESPACE_DECLARATIONS, namespaces);
Metacard mc = (Metacard) xstream.unmarshal(reader, null, args);
Metacard expectedMetacard = getTestMetacard();
assertThat(mc, notNullValue());
assertThat(mc.getContentTypeName(), is(mc.getContentTypeName()));
assertThat(mc.getCreatedDate(), is(expectedMetacard.getCreatedDate()));
assertThat(mc.getEffectiveDate(), is(expectedMetacard.getEffectiveDate()));
assertThat(mc.getId(), is(expectedMetacard.getId()));
assertThat(mc.getModifiedDate(), is(expectedMetacard.getModifiedDate()));
assertThat(mc.getTitle(), is(expectedMetacard.getTitle()));
assertThat(mc.getResourceURI(), is(expectedMetacard.getResourceURI()));
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual(mc.getMetadata(), getControlRecord());
}
Aggregations