Search in sources :

Example 86 with Data

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);
        }
    });
}
Also used : 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 87 with Data

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);
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) Data(org.geotoolkit.wps.xml.v200.Data) RenderedImage(java.awt.image.RenderedImage) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Example 88 with Data

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);
}
Also used : Format(org.geotoolkit.wps.xml.v200.Format) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Data(org.geotoolkit.wps.xml.v200.Data) RenderedImage(java.awt.image.RenderedImage) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Example 89 with Data

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

Example 90 with Data

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;
}
Also used : FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) Data(org.geotoolkit.wps.xml.v200.Data) Feature(org.opengis.feature.Feature) ElementFeatureWriter(org.geotoolkit.feature.xml.jaxp.ElementFeatureWriter) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) GeoJSONStreamWriter(org.geotoolkit.storage.geojson.GeoJSONStreamWriter)

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