Search in sources :

Example 41 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class FeatureCollectionToReferenceConverterTest method testJSONConversion.

@Test
public void testJSONConversion() throws DataStoreException, MalformedURLException, IOException, URISyntaxException, FactoryException {
    // Get the test resource
    final Object testResource = ConvertersTestUtils.loadTestResource("/inputs/featurecollection.json");
    final Reference reference = ConvertersTestUtils.initAndRunOutputConversion(FeatureCollection.class, Reference.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
    // Test reference
    assertEquals(WPSMimeType.APP_GEOJSON.val(), reference.getMimeType());
    assertEquals(WPSEncoding.UTF8.getValue(), reference.getEncoding());
    assertNull(reference.getSchema());
    assertNotNull(reference.getHref());
    final FeatureSet featureCollection = WPSConvertersUtils.readFeatureCollectionFromJson(URI.create(reference.getHref()));
    ConvertersTestUtils.assertFeatureCollectionIsValid((FeatureSet) testResource);
    ConvertersTestUtils.assertFeatureCollectionIsValid(featureCollection);
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference) FeatureSet(org.apache.sis.storage.FeatureSet) Test(org.junit.Test)

Example 42 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class FeatureToReferenceConverterTest method testJSONConversion.

@Test
public void testJSONConversion() throws DataStoreException, IOException, URISyntaxException, FactoryException {
    // Get the test resource
    final Object testResource = ConvertersTestUtils.loadTestResource("/inputs/feature.json");
    final Reference reference = ConvertersTestUtils.initAndRunOutputConversion(Feature.class, Reference.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
    // Test reference
    assertEquals(WPSMimeType.APP_GEOJSON.val(), reference.getMimeType());
    assertEquals(WPSEncoding.UTF8.getValue(), reference.getEncoding());
    assertNull(reference.getSchema());
    assertNotNull(reference.getHref());
    Feature feature = WPSConvertersUtils.readFeatureFromJson(URI.create(reference.getHref()));
    ConvertersTestUtils.assertFeatureIsValid((Feature) testResource);
    ConvertersTestUtils.assertFeatureIsValid(feature);
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 43 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class GeometryToReferenceConverterTest method testJSONConversion.

@Test
public void testJSONConversion() throws DataStoreException, IOException, URISyntaxException, FactoryException {
    // Get test resource
    final Object testResource = ConvertersTestUtils.loadTestResource("/inputs/geometry.json");
    Reference reference = ConvertersTestUtils.initAndRunOutputConversion(Geometry.class, Reference.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
    // Test reference
    assertEquals(WPSMimeType.APP_GEOJSON.val(), reference.getMimeType());
    assertEquals(WPSEncoding.UTF8.getValue(), reference.getEncoding());
    assertNull(reference.getSchema());
    assertNotNull(reference.getHref());
    Geometry geometry = ConvertersTestUtils.getGeometryFromGeoJsonContent(Paths.get(URI.create(reference.getHref())));
    ConvertersTestUtils.assertGeometryIsValid((Geometry) testResource);
    ConvertersTestUtils.assertGeometryIsValid(geometry);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Reference(org.geotoolkit.wps.xml.v200.Reference) Test(org.junit.Test)

Example 44 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class ReferenceToRenderedImageConverterTest method testConversion.

@Test
public void testConversion() throws UnconvertibleObjectException, IOException {
    final WPSObjectConverter<Reference, RenderedImage> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, RenderedImage.class);
    final URL image = ReferenceToRenderedImageConverterTest.class.getResource("/inputs/image.tiff");
    assertNotNull(image);
    final Map<String, Object> parameters = new HashMap<>();
    parameters.put(AbstractReferenceInputConverter.IOTYPE, WPSIO.IOType.INPUT);
    final Reference reference = new Reference();
    reference.setHref(image.toString());
    reference.setMimeType("image/tiff");
    reference.setEncoding(null);
    final RenderedImage convertedImage = converter.convert(reference, parameters);
    assertNotNull(convertedImage);
    final RenderedImage expectedImage = ConvertersTestUtils.makeRendredImage();
    assertRasterEquals(expectedImage, convertedImage);
}
Also used : HashMap(java.util.HashMap) Reference(org.geotoolkit.wps.xml.v200.Reference) RenderedImage(java.awt.image.RenderedImage) URL(java.net.URL) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Example 45 with Reference

use of com.google.api.expr.v1alpha1.Reference in project geotoolkit by Geomatys.

the class ReferenceToUrlConnectionConverterTest method convert.

@Test
public void convert() throws Exception {
    final WPSObjectConverter<Reference, URLConnection> converter = WPSConverterRegistry.getInstance().getConverter(Reference.class, URLConnection.class);
    final Reference ref = new Reference();
    ref.setHref("https://my.domain/context");
    final Reference.Header header = new Reference.Header();
    header.setKey("myKey");
    header.setValue("myValue");
    ref.getHeader().add(header);
    final URLConnection con = converter.convert(ref, Collections.singletonMap(WPSObjectConverter.IOTYPE, (Object) WPSIO.IOType.INPUT.name()));
    Assert.assertEquals("HRef differs !", ref.getHref(), con.getURL().toExternalForm());
    Assert.assertEquals("No header has been copied !", header.getValue(), con.getRequestProperty(header.getKey()));
}
Also used : Reference(org.geotoolkit.wps.xml.v200.Reference) URLConnection(java.net.URLConnection) AbstractWPSConverterTest(org.geotoolkit.wps.converters.AbstractWPSConverterTest) Test(org.junit.Test)

Aggregations

Reference (org.geotoolkit.wps.xml.v200.Reference)34 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)17 Path (java.nio.file.Path)14 Test (org.junit.Test)11 IOException (java.io.IOException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 JAXBException (javax.xml.bind.JAXBException)6 AbstractWPSConverterTest (org.geotoolkit.wps.converters.AbstractWPSConverterTest)6 ArrayList (java.util.ArrayList)5 Feature (org.opengis.feature.Feature)5 BufferedReader (java.io.BufferedReader)4 Geometry (org.locationtech.jts.geom.Geometry)4 Type (com.google.api.expr.v1alpha1.Type)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DataStoreException (org.apache.sis.storage.DataStoreException)3 Reference (org.dishevelled.bio.assembly.gfa1.Reference)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)2 Decl (com.google.api.expr.v1alpha1.Decl)2