use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswRecordConverter method testSetMetacardContentTypeToCswRecordType.
/**
* Test to verify that a metacard's content type is set to the CSW Record's type field.
*/
@Test
public void testSetMetacardContentTypeToCswRecordType() throws ParserConfigurationException, SAXException, IOException {
// Setup
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(TestCswRecordConverter.class.getResource("/Csw_Record.xml").getPath());
HierarchicalStreamReader reader = new DomReader(doc);
UnmarshallingContext context = new TreeUnmarshaller(null, null, null, null);
// Perform test
Metacard metacard = (Metacard) converter.unmarshal(reader, context);
// Verify
LOGGER.debug("metacard id: {}", metacard.getId());
LOGGER.debug("metacard content type: {}", metacard.getContentTypeName());
assertThat(metacard.getContentTypeName(), is("IMAGE-PRODUCT"));
}
use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswTransformProvider method testUnmarshalNoTransformers.
@Test(expected = ConversionException.class)
public void testUnmarshalNoTransformers() throws Exception {
when(mockInputManager.getTransformerBySchema(anyString())).thenReturn(null);
HierarchicalStreamReader reader = new WstxDriver().createReader(new StringReader(getRecord()));
CswTransformProvider provider = new CswTransformProvider(null, mockInputManager);
UnmarshallingContext context = new TreeUnmarshaller(null, null, null, null);
provider.unmarshal(reader, context);
}
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);
}
}
Aggregations