use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class FeatureToComplexConverterTest method testJSONConversion.
@Test
public void testJSONConversion() throws DataStoreException, IOException, URISyntaxException, FactoryException {
// Get test resource
final Object testResource = ConvertersTestUtils.loadTestResource("/inputs/feature.json");
final Data complex = ConvertersTestUtils.initAndRunOutputConversion(Feature.class, Data.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
ConvertersTestUtils.assertFormatMatch(complex, WPSEncoding.UTF8.getValue(), WPSMimeType.APP_GEOJSON.val(), null);
ConvertersTestUtils.useDataContentAsFile(complex, file -> {
try {
final Feature readFeature = WPSConvertersUtils.readFeatureFromJson(file.toUri());
ConvertersTestUtils.assertFeatureIsValid(readFeature);
} catch (DataStoreException | URISyntaxException 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 GeometryToComplexConverterTest method testJSONConversion.
@Test
public void testJSONConversion() throws DataStoreException, IOException, FactoryException, URISyntaxException {
// Get test resource
Geometry geometryResource = (Geometry) ConvertersTestUtils.loadTestResource("/inputs/geometry.json");
ConvertersTestUtils.assertGeometryIsValid(geometryResource);
Data complex = ConvertersTestUtils.initAndRunOutputConversion(Geometry.class, Data.class, geometryResource, 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 {
Geometry geometry = getGeometry(file);
ConvertersTestUtils.assertGeometryIsValid(geometry);
} 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 CoverageToComplexConverter method convert.
@Override
public Data convert(GridCoverage source, 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 WPSMimeType wpsMime = WPSMimeType.customValueOf((String) tmpMime);
if (!wpsMime.equals(WPSMimeType.IMG_GEOTIFF) && !wpsMime.equals(WPSMimeType.IMG_GEOTIFF_BIS)) {
throw new UnconvertibleObjectException("Only support GeoTiff Base64 encoding.");
}
final Object tmpEncoding = params.get(ENCODING);
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
CoverageIO.write(source, "GEOTIFF", baos);
baos.flush();
byte[] bytesOut = baos.toByteArray();
return new Data(new Format((String) ((tmpEncoding instanceof String) ? tmpEncoding : null), mime, null, null), Base64.getEncoder().encodeToString(bytesOut));
} catch (DataStoreException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
} catch (IOException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
}
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class FeatureTypeToComplexConverter method convert.
/**
* {@inheritDoc}
*/
@Override
public Data convert(final FeatureType source, final Map<String, Object> params) throws UnconvertibleObjectException {
if (source == null) {
throw new UnconvertibleObjectException("The output data should be defined.");
}
final Data complex = new Data();
final Object tmpEncoding = params == null ? null : params.get(ENCODING);
if (tmpEncoding instanceof String) {
complex.setEncoding((String) tmpEncoding);
}
complex.setMimeType(WPSMimeType.TEXT_GML.val());
try {
final JAXBFeatureTypeWriter xmlWriter = new JAXBFeatureTypeWriter();
complex.getContent().add(xmlWriter.writeToElement(source));
} catch (JAXBException | ParserConfigurationException ex) {
throw new UnconvertibleObjectException("Can't write FeatureType into ResponseDocument.", ex);
}
return complex;
}
use of com.microsoft.applicationinsights.smoketest.schemav2.Data in project geotoolkit by Geomatys.
the class RenderedImageToComplexConverter method convert.
@Override
public Data convert(RenderedImage source, 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 String formatName = mime.substring(mime.indexOf("/") + 1).toUpperCase();
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(source, formatName, baos);
baos.flush();
byte[] bytesOut = baos.toByteArray();
complex.getContent().add(Base64.getEncoder().encodeToString(bytesOut));
baos.close();
} catch (IOException ex) {
throw new UnconvertibleObjectException(ex.getMessage(), ex);
}
return complex;
}
Aggregations