Search in sources :

Example 6 with Data

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);
        }
    });
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Data(org.geotoolkit.wps.xml.v200.Data) UncheckedIOException(java.io.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 7 with Data

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);
        }
    });
}
Also used : GeoJSONGeometry(org.geotoolkit.internal.geojson.binding.GeoJSONGeometry) Geometry(org.locationtech.jts.geom.Geometry) FactoryException(org.opengis.util.FactoryException) Data(org.geotoolkit.wps.xml.v200.Data) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.Test)

Example 8 with Data

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);
    }
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) DataStoreException(org.apache.sis.storage.DataStoreException) Format(org.geotoolkit.wps.xml.v200.Format) WPSMimeType(org.geotoolkit.wps.io.WPSMimeType) Data(org.geotoolkit.wps.xml.v200.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 9 with Data

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;
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) JAXBException(javax.xml.bind.JAXBException) Data(org.geotoolkit.wps.xml.v200.Data) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) JAXBFeatureTypeWriter(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeWriter)

Example 10 with Data

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;
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Data(org.geotoolkit.wps.xml.v200.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)65 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)53 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)45 Data (org.geotoolkit.wps.xml.v200.Data)42 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)26 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)20 IOException (java.io.IOException)16 DataInput (org.geotoolkit.wps.xml.v200.DataInput)15 Format (org.geotoolkit.wps.xml.v200.Format)12 AiSmokeTest (com.microsoft.applicationinsights.smoketest.AiSmokeTest)10 TargetUri (com.microsoft.applicationinsights.smoketest.TargetUri)10 MessageData (com.microsoft.applicationinsights.smoketest.schemav2.MessageData)10 ComplexData (org.geotoolkit.wps.xml.v200.ComplexData)10 ExceptionData (com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData)9 ReferenceProxy (org.geotoolkit.wps.xml.ReferenceProxy)9 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)8 DataStoreException (org.apache.sis.storage.DataStoreException)8 LiteralValue (org.geotoolkit.wps.xml.v200.LiteralValue)7 EventData (com.microsoft.applicationinsights.smoketest.schemav2.EventData)6 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)6