use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class GeometryArrayToComplexConverterTest method testJSONConversion.
@Test
public void testJSONConversion() throws IOException, FactoryException, DataStoreException, URISyntaxException {
// Get test resource
final Geometry[] geometryArrayResource = (Geometry[]) ConvertersTestUtils.loadTestResource("/inputs/geometrycollection.json");
final Data complex = ConvertersTestUtils.initAndRunOutputConversion(Geometry[].class, Data.class, geometryArrayResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
// Test complex
ConvertersTestUtils.assertFormatMatch(complex, WPSEncoding.UTF8.getValue(), WPSMimeType.APP_GEOJSON.val(), null);
ConvertersTestUtils.useDataContentAsFile(complex, file -> {
try {
final Geometry[] geometryArrayToTest = ConvertersTestUtils.getGeometryArrayFromInputStream(Files.newInputStream(file));
assertEquals(geometryArrayResource.length, geometryArrayToTest.length);
ConvertersTestUtils.assertGeometryArrayIsValid(geometryArrayResource);
ConvertersTestUtils.assertGeometryArrayIsValid(geometryArrayToTest);
} catch (FactoryException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class RenderedImageToComplexConverterTest method testConversion.
@Test
public void testConversion() throws UnconvertibleObjectException, IOException {
final WPSObjectConverter<RenderedImage, Data> converter = WPSConverterRegistry.getInstance().getConverter(RenderedImage.class, Data.class);
final RenderedImage img = ConvertersTestUtils.makeRendredImage();
final Map<String, Object> param = new HashMap<String, Object>();
param.put(WPSObjectConverter.MIME, WPSMimeType.IMG_TIFF.val());
param.put(WPSObjectConverter.ENCODING, "base64");
final Data complex = converter.convert(img, param);
final List<Object> content = complex.getContent();
final String encodedImage = (String) content.get(0);
final InputStream expectedStream = RenderedImageToComplexConverterTest.class.getResourceAsStream("/expected/image_base64");
assertNotNull(expectedStream);
String expectedString = IOUtilities.toString(expectedStream);
expectedString = expectedString.trim();
assertEquals(expectedString, encodedImage);
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class ComplexToRenderedImageConvereterTest method testConversion.
@Test
public void testConversion() throws UnconvertibleObjectException, IOException {
final WPSObjectConverter<Data, RenderedImage> converter = WPSConverterRegistry.getInstance().getConverter(Data.class, RenderedImage.class);
final InputStream expectedStream = ComplexToRenderedImageConvereterTest.class.getResourceAsStream("/expected/image_base64");
assertNotNull(expectedStream);
final String encodedImage = IOUtilities.toString(expectedStream);
final Map<String, Object> param = new HashMap<String, Object>();
param.put(WPSObjectConverter.MIME, "img/tiff");
param.put(WPSObjectConverter.ENCODING, "base64");
final Format format = new Format("base64", "image/tiff", null, null);
final Data complex = new Data(format, encodedImage);
final RenderedImage convertedImage = converter.convert(complex, param);
assertNotNull(convertedImage);
final RenderedImage expectedImage = ConvertersTestUtils.makeRendredImage();
assertRasterEquals(expectedImage, convertedImage);
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class ZipAdaptor method toWPS2Input.
@Override
public DataInput toWPS2Input(Path candidate) throws UnconvertibleObjectException {
if (candidate instanceof ReferenceProxy)
return super.toWPS2Input(candidate);
final byte[] bytes;
try {
bytes = Files.readAllBytes(candidate);
} catch (IOException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
}
final String base64 = Base64.getEncoder().encodeToString(bytes);
final DataInput dit = new DataInput();
final Data data = new Data();
data.setEncoding("base64");
data.getContent().add(base64);
dit.setData(data);
return dit;
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class FeatureSetToComplexConverter method convert.
/**
* {@inheritDoc}
*/
@Override
public Data convert(final FeatureSet source, final Map<String, Object> params) throws UnconvertibleObjectException {
if (source == null) {
throw new UnconvertibleObjectException("The output data should be defined.");
} else if (params == null) {
throw new UnconvertibleObjectException("Not enough information about data format");
}
final Object tmpMime = params.get(MIME);
final String mime;
if (tmpMime instanceof String) {
mime = (String) tmpMime;
} else {
throw new UnconvertibleObjectException("No valid mime type given. We cannot determine output image format");
}
final Data complex = new Data();
complex.setMimeType(mime);
final Object tmpEncoding = params.get(ENCODING);
if (tmpEncoding instanceof String) {
complex.setEncoding((String) tmpEncoding);
}
final FeatureType ft;
try {
ft = source.getType();
} catch (DataStoreException ex) {
throw new UnconvertibleObjectException("Can't write acess FeatureSet type.", ex);
}
final String namespace = NamesExt.getNamespace(ft.getName());
final Map<String, String> schemaLocation = new HashMap<>();
if (WPSMimeType.APP_GEOJSON.val().equalsIgnoreCase(mime)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
try (GeoJSONStreamWriter writer = new GeoJSONStreamWriter(baos, ft, WPSConvertersUtils.FRACTION_DIGITS);
Stream<Feature> st = source.features(false)) {
Iterator<Feature> iterator = st.iterator();
while (iterator.hasNext()) {
Feature next = iterator.next();
Feature neww = writer.next();
FeatureExt.copy(next, neww, false);
writer.write();
}
}
WPSConvertersUtils.addCDATAToComplex(baos.toString("UTF-8"), complex);
complex.setSchema(null);
} catch (DataStoreException e) {
throw new UnconvertibleObjectException("Can't write Feature into GeoJSON output stream.", e);
} catch (UnsupportedEncodingException e) {
throw new UnconvertibleObjectException("Can't convert output stream into String.", e);
}
} else if (WPSMimeType.APP_GML.val().equalsIgnoreCase(mime) || WPSMimeType.TEXT_XML.val().equalsIgnoreCase(mime) || WPSMimeType.TEXT_GML.val().equalsIgnoreCase(mime)) {
try {
complex.setSchema(WPSConvertersUtils.writeSchema(ft, params));
schemaLocation.put(namespace, complex.getSchema());
} catch (JAXBException ex) {
throw new UnconvertibleObjectException("Can't write FeatureType into xsd schema.", ex);
} catch (IOException ex) {
throw new UnconvertibleObjectException("Can't create xsd schema file.", ex);
}
try {
final ElementFeatureWriter efw = new ElementFeatureWriter(schemaLocation);
complex.getContent().add(efw.writeFeatureCollection(source, null, true, false, null, true));
} catch (DataStoreException | ParserConfigurationException ex) {
throw new UnconvertibleObjectException("Can't write FeatureSet into ResponseDocument.", ex);
}
} else
throw new UnconvertibleObjectException("Unsupported mime-type for " + this.getClass().getName() + " : " + complex.getMimeType());
return complex;
}
Aggregations