use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.
the class LiteralAdaptorTest method booleanWPS2.
@Test
public void booleanWPS2() {
final DomainMetadataType metaType = new DomainMetadataType(null, "xs:boolean");
final LiteralDataDomain domain = new LiteralDataDomain();
domain.setDataType(metaType);
final LiteralAdaptor adaptor = LiteralAdaptor.create(domain);
assertEquals(Boolean.class, adaptor.getValueClass());
final DataOutput output = new DataOutput();
final LiteralValue lit = new LiteralValue();
lit.setValue("true");
final Data data = new Data(lit);
output.setData(data);
final Object result = adaptor.fromWPS2Input(output);
assertEquals(true, result);
}
use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.
the class ConvertersTestUtils method initAndRunOutputConversion.
/**
* Helper method to initialize a converter and run with its parameters.
*
* The converters are the one that convert Geometry or Feature types to
* Complex or Reference.
*
* The method is in charge of setting up the parameters map, the resource
* (either a java URL or String containg json datas) and calling conversion
* method.
*
* @param <SourceType> type of the input data in the conversion
* @param <TargetType> type of the output data in the conversion
* @param sourceClass class of the input data in the conversion
* @param targetClass class of the output dat in the conversion
* @param resource resource to give as input to the converter (must be of the
* same type as SourceType)
* @param mimeType mime type of the input data
* @param encoding encoding of the input data
*
* @return an instance of TargetType which is the result of a call to the converter
*
* @throws IOException on reading the test resource
* @throws IllegalArgumentException when mimeType or encoding is empty
* @throws NullArgumentException when an argument is null
*/
public static <SourceType, TargetType> TargetType initAndRunOutputConversion(Class sourceClass, Class targetClass, Object resource, String mimeType, String encoding) throws IOException {
ArgumentChecks.ensureNonNull("sourceClass", sourceClass);
ArgumentChecks.ensureNonNull("targetClass", targetClass);
ArgumentChecks.ensureNonNull("resource", resource);
ArgumentChecks.ensureNonEmpty("mimeType", mimeType);
ArgumentChecks.ensureNonEmpty("encoding", encoding);
// Get converter
final WPSObjectConverter<SourceType, TargetType> converter = WPSConverterRegistry.getInstance().getConverter(sourceClass, targetClass);
// Setup the parameters map
Path tmpDirPath;
Map<String, Object> parametersMap = null;
if (targetClass.equals(Data.class))
parametersMap = ConvertersTestUtils.createParameters(mimeType, encoding);
else if (targetClass.equals(Reference.class)) {
tmpDirPath = Files.createTempDirectory(UUID.randomUUID().toString());
parametersMap = ConvertersTestUtils.createParameters(mimeType, encoding, tmpDirPath.toUri().toString(), WPSIO.IOType.OUTPUT.toString());
} else
fail();
return converter.convert((SourceType) resource, parametersMap);
}
use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.
the class ConvertersTestUtils method initAndRunInputConversion.
/**
* Helper method to initialize a converter and run with its parameters.
*
* The converters are the ones that convert Complex or reference to Geometry
* or Feature types.
*
* The method is in charge of setting up the parameters map, the resource
* (either a java URL or String containg json datas) and calling conversion
* method.
*
* @param <SourceType> type of the input data in the conversion
* @param <TargetType> type of the output data in the conversion
* @param sourceClass class of the input data in the conversion
* @param targetClass class of the output dat in the conversion
* @param resourcePath url to the resource file to read
* @param mimeType mime type of the input data
* @param encoding encoding of the input data
* @param schema schema for the input data (only arguments that can be null)
* @return an instance of TargetType which is the result of a call to the converter
* @throws IOException on reading the test resource
* @throws IllegalArgumentException when one of the String arguments is null
* @throws NullArgumentException when one of the arguments is null
*/
public static <SourceType, TargetType> TargetType initAndRunInputConversion(Class sourceClass, Class targetClass, String resourcePath, String mimeType, String encoding, String schema) throws IOException {
ArgumentChecks.ensureNonNull("sourceClass", sourceClass);
ArgumentChecks.ensureNonNull("targetClass", targetClass);
ArgumentChecks.ensureNonEmpty("resourcePath", resourcePath);
ArgumentChecks.ensureNonEmpty("mimeType", mimeType);
ArgumentChecks.ensureNonEmpty("encoding", encoding);
// Get the converter to test
final WPSObjectConverter<SourceType, TargetType> converter = WPSConverterRegistry.getInstance().getConverter(sourceClass, targetClass);
// Setup parameters map
final Map<String, Object> param = ConvertersTestUtils.createParameters(mimeType, encoding);
// Setup the resource and run conversion
if (sourceClass.equals(Data.class)) {
final String resource = ConvertersTestUtils.getTestResource(ConvertersTestUtils.class, resourcePath);
final Data complex = ConvertersTestUtils.createComplex(mimeType, encoding, schema, resource);
return converter.convert((SourceType) complex, param);
} else if (sourceClass.equals(Reference.class)) {
final URL resource = ConvertersTestUtils.class.getResource(resourcePath);
final Reference reference = ConvertersTestUtils.createReference("1.0.0", mimeType, encoding, schema, resource);
return converter.convert((SourceType) reference, param);
} else {
fail();
return null;
}
}
use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.
the class ComplexToCoverageConverterTest method testConversion.
@Test
@org.junit.Ignore("Fails randomly because of GeoTIFF reader not found.")
public void testConversion() throws UnconvertibleObjectException, IOException, InterruptedException {
final WPSObjectConverter<Data, GridCoverage> converter = WPSConverterRegistry.getInstance().getConverter(Data.class, GridCoverage.class);
final InputStream expectedStream = ComplexToRenderedImageConvereterTest.class.getResourceAsStream("/expected/coverage_base64");
assertNotNull(expectedStream);
final String encodedCoverage = IOUtilities.toString(expectedStream);
final Map<String, Object> param = new HashMap<String, Object>();
param.put(WPSObjectConverter.MIME, "image/x-geotiff");
param.put(WPSObjectConverter.ENCODING, "base64");
final Format format = new Format("base64", "image/x-geotiff", null, null);
final Data complex = new Data(format, encodedCoverage);
complex.getContent().add(encodedCoverage);
final GridCoverage convertedCoverage = converter.convert(complex, param);
assertNotNull(convertedCoverage);
final GridCoverage expectedCoverage = ConvertersTestUtils.makeCoverage();
final Envelope convertedEnvelope = convertedCoverage.getGridGeometry().getEnvelope();
final Envelope expectedEnvelope = expectedCoverage.getGridGeometry().getEnvelope();
assertTrue(Utilities.equalsIgnoreMetadata(expectedEnvelope.getCoordinateReferenceSystem(), convertedEnvelope.getCoordinateReferenceSystem()));
assertTrue(expectedEnvelope.getMinimum(0) == convertedEnvelope.getMinimum(0));
assertTrue(expectedEnvelope.getMinimum(1) == convertedEnvelope.getMinimum(1));
assertTrue(expectedEnvelope.getMaximum(0) == convertedEnvelope.getMaximum(0));
assertTrue(expectedEnvelope.getMaximum(1) == convertedEnvelope.getMaximum(1));
Assert.assertRasterEquals(expectedCoverage.render(null), convertedCoverage.render(null));
}
use of org.geotoolkit.wps.xml.v200.Data in project geotoolkit by Geomatys.
the class FeatureCollectionToComplexConverterTest method testJSONConversion.
@Test
public void testJSONConversion() throws Exception {
// Get test resource
Object testResource = ConvertersTestUtils.loadTestResource("/inputs/featurecollection.json");
Data complex = ConvertersTestUtils.initAndRunOutputConversion(FeatureCollection.class, Data.class, testResource, WPSMimeType.APP_GEOJSON.val(), WPSEncoding.UTF8.getValue());
// Test complex
ConvertersTestUtils.assertFormatMatch(complex, WPSEncoding.UTF8.getValue(), WPSMimeType.APP_GEOJSON.val(), null);
ConvertersTestUtils.useDataContentAsFile(complex, file -> {
// that we gave as input to the converter
try {
FeatureSet readFeatureCollection = WPSConvertersUtils.readFeatureCollectionFromJson(file.toUri());
ConvertersTestUtils.assertFeatureCollectionIsValid(readFeatureCollection);
} catch (DataStoreException | URISyntaxException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
Aggregations