use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswTransformProvider method testUnmarshalOtherSchema.
@Test
public void testUnmarshalOtherSchema() throws Exception {
InputTransformer mockInputTransformer = mock(InputTransformer.class);
when(mockInputManager.getTransformerByProperty(TransformerManager.SCHEMA, OTHER_SCHEMA)).thenReturn(mockInputTransformer);
when(mockInputTransformer.transform(any(InputStream.class))).thenReturn(getMetacard());
// XppReader is not namespace aware so it will read the XML and ignore the namespaces
// WstxReader is namespace aware. It may fail for XML fragments.
HierarchicalStreamReader reader = new XppReader(new StringReader(getRecord()), XmlPullParserFactory.newInstance().newPullParser());
CswTransformProvider provider = new CswTransformProvider(null, mockInputManager);
UnmarshallingContext context = new TreeUnmarshaller(null, null, 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.unmarshal(reader, context);
// Verify the context arguments were set correctly
verify(mockInputManager, times(1)).getTransformerByProperty(captor.capture(), captor.capture());
String outputSchema = captor.getValue();
assertThat(outputSchema, is(OTHER_SCHEMA));
}
use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswRecordConverter method testUnmarshalSingleCswRecordToMetacardContentTypeMapsToFormat.
@Test
public void testUnmarshalSingleCswRecordToMetacardContentTypeMapsToFormat() throws ParserConfigurationException, IOException, SAXException {
XStream xstream = new XStream(new WstxDriver());
xstream.registerConverter(converter);
xstream.alias("csw:Record", MetacardImpl.class);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(TestCswRecordConverter.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.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswUnmarshallHelper method testConvertRecordPropertyToMetacardAttribute.
@Test
public void testConvertRecordPropertyToMetacardAttribute() {
valueMap.put(AttributeType.AttributeFormat.BINARY, "TEST_BINARY");
valueMap.put(AttributeType.AttributeFormat.GEOMETRY, TEST_BOUNDING_BOX);
matcherMap.put(AttributeType.AttributeFormat.BINARY, notNullValue());
matcherMap.put(AttributeType.AttributeFormat.GEOMETRY, is("POLYGON ((44.792 -6.171, 44.792 -2.228, 51.126 -2.228, 51.126 -6.171, 44.792 -6.171))"));
AttributeType.AttributeFormat[] attributeFormats = AttributeType.AttributeFormat.values();
for (AttributeType.AttributeFormat attributeFormat : attributeFormats) {
HierarchicalStreamReader reader = getReader(attributeFormat);
Serializable ser = CswUnmarshallHelper.convertRecordPropertyToMetacardAttribute(attributeFormat, reader, CswAxisOrder.LAT_LON);
Matcher m = matcherMap.get(attributeFormat);
assertThat(ser, m);
}
}
use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestXStreamAttributeCopier method testCopyXml.
@Test
public void testCopyXml() throws IOException {
// Move to the <Delete> element.
reader.moveDown();
StringWriter sw = new StringWriter();
Map<String, String> attributeMap = new HashMap<>();
attributeMap.put("foo", "bar");
HierarchicalStreamReader deleteReader = XStreamAttributeCopier.copyXml(reader, sw, attributeMap);
// Verify that the reader is at the end of <Delete>.
assertThat(reader.hasMoreChildren(), is(false));
// Move back up to <Transaction>.
reader.moveUp();
// Move down to <Insert>.
reader.moveDown();
// Verify that the reader is now at <Insert>.
assertThat(reader.getNodeName(), is("csw:Insert"));
assertThat(deleteReader.getNodeName(), is("csw:Delete"));
assertThat(deleteReader.getAttributeCount(), is(3));
// Verify that the attribute was copied to the element.
assertThat(deleteReader.getAttribute("foo"), is("bar"));
// Verify that the XML was copied correctly.
assertThat(deleteReader.getAttribute(CswConstants.TYPE_NAME_PARAMETER), is("csw:Record"));
assertThat(deleteReader.getAttribute(CswConstants.HANDLE_PARAMETER), is("something"));
deleteReader.moveDown();
assertThat(deleteReader.getNodeName(), is("csw:Constraint"));
assertThat(deleteReader.getAttribute(CswConstants.VERSION), is("2.0.0"));
deleteReader.moveDown();
assertThat(deleteReader.getNodeName(), is("ogc:Filter"));
deleteReader.moveDown();
assertThat(deleteReader.getNodeName(), is("ogc:PropertyIsEqualTo"));
deleteReader.moveDown();
assertThat(deleteReader.getNodeName(), is("ogc:PropertyName"));
assertThat(deleteReader.getValue(), is("title"));
deleteReader.moveUp();
deleteReader.moveDown();
assertThat(deleteReader.getNodeName(), is("ogc:Literal"));
assertThat(deleteReader.getValue(), is("Test Title"));
deleteReader.moveUp();
// Verify that PropertyIsEqualTo has no more children.
assertThat(deleteReader.hasMoreChildren(), is(false));
deleteReader.moveUp();
// Verify that Filter has no more children.
assertThat(deleteReader.hasMoreChildren(), is(false));
deleteReader.moveUp();
// Verify that Constraint has no more children.
assertThat(deleteReader.hasMoreChildren(), is(false));
deleteReader.moveUp();
// Verify that Delete has no more children.
assertThat(deleteReader.hasMoreChildren(), is(false));
}
use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestXstreamPathConverter method testAttributeValid.
@Test
public void testAttributeValid() throws XMLStreamException {
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(GML_XML));
HierarchicalStreamReader reader = new StaxReader(new QNameMap(), streamReader);
XstreamPathValueTracker pathValueTracker = (XstreamPathValueTracker) xstream.unmarshal(reader, null, argumentHolder);
assertThat(pathValueTracker.getFirstValue(POLYGON_GML_ID_PATH), is("p1"));
}
Aggregations