use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestBoundingBoxReader method testJTSConverterEPSG32636.
@Test
public void testJTSConverterEPSG32636() throws Exception {
// Setup
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse("src/test/resources/BoundingBoxEPSG32636.xml");
HierarchicalStreamReader hReader = new DomReader(doc);
BoundingBoxReader boundingBoxReader = new BoundingBoxReader(hReader, CswAxisOrder.LAT_LON);
// Perform Test
String wktInLonLat = boundingBoxReader.getWkt();
LOGGER.debug("WKT: {}", wktInLonLat);
// Verify
assertThat(wktInLonLat, is(POLYGON_UTM_LON_LAT));
}
use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswUnmarshallHelper method getReader.
private HierarchicalStreamReader getReader(AttributeType.AttributeFormat attributeFormat) {
HierarchicalStreamReader reader = mock(HierarchicalStreamReader.class);
if (attributeFormat.equals(AttributeType.AttributeFormat.GEOMETRY)) {
Stack<String> boundingBoxNodes = new Stack<>();
boundingBoxNodes.push(valueMap.get(attributeFormat));
boundingBoxNodes.push("-2.228 51.126");
boundingBoxNodes.push("UpperCorner");
boundingBoxNodes.push("-6.171 44.792");
boundingBoxNodes.push("LowerCorner");
boundingBoxNodes.push("BoundingBox");
boundingBoxNodes.push("BoundingBox");
boundingBoxNodes.push("BoundingBox");
Answer<String> answer = invocationOnMock -> boundingBoxNodes.pop();
when(reader.getNodeName()).thenAnswer(answer);
when(reader.getValue()).thenAnswer(answer);
} else {
when(reader.getValue()).thenReturn(valueMap.get(attributeFormat));
}
return reader;
}
use of com.thoughtworks.xstream.io.HierarchicalStreamReader in project ddf by codice.
the class TestCswRecordConverter method testUnmarshalCswRecordWithProductAndThumbnail.
@Test
public void testUnmarshalCswRecordWithProductAndThumbnail() throws URISyntaxException, IOException, JAXBException, ParserConfigurationException, SAXException {
XStream xstream = new XStream(new WstxDriver());
xstream.registerConverter(converter);
InputStream is = TestCswRecordConverter.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 = TestCswRecordConverter.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));
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.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);
}
Aggregations