use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class JsonMappingTest method testDittoMappingFromRemoteRepository.
@Test
public void testDittoMappingFromRemoteRepository() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("devices.aws.button.AWSIoTButton:1.0.0").targetPlatformKey("devices_aws_button_AWSIoTButton_1_0_0").build();
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
Map<String, Object> input = new HashMap<String, Object>();
input.put("clickType", "DOUBLE");
input.put("batteryVoltage", "2322mV");
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(input), MappingContext.empty());
Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
Feature voltageFeature = mappedDittoOutput.getFeatures().get("batteryVoltage");
assertEquals(2322f, voltageFeature.getStatusProperties().get("sensor_value"));
assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSerializerTest method testCreateAndSerializeMappingSpecContainingCustomFunctions.
@Test
public void testCreateAndSerializeMappingSpecContainingCustomFunctions() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("sensor_units").get().addStereotype(Stereotype.createWithXpath(""));
mappingSpecification.getFunctionBlock("distancesensor").addStereotype(Stereotype.createWithFunction("convert", "function convert() {}"));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
MappingSpecificationSerializer.create(mappingSpecification).iterator().forEachRemaining(p -> System.out.println(p.serialize()));
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSerializerTest method testCreateAndSerializeMappingSpec.
@Test
public void testCreateAndSerializeMappingSpec() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
MappingSpecificationSerializer.create(mappingSpecification).iterator().forEachRemaining(p -> System.out.println(p.serialize()));
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class UnideMappingTest method testMapUnideMessageToDitto.
@Test
public void testMapUnideMessageToDitto() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("org.eclipse.unide.devices.MobilePhone:1.0.0").targetPlatformKey("org_eclipse_unide_devices_MobilePhone_1_0_0").build();
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
final String unideMessage = IOUtils.toString(UnideMappingTest.class.getClassLoader().getResourceAsStream("unide.json"));
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(unideMessage), MappingContext.empty());
Feature directionFeature = mappedDittoOutput.getFeatures().get("direction");
assertEquals(45.4231, directionFeature.getStatusProperties().get("compass_direction"));
System.out.println(mappedDittoOutput.toJson());
}
Aggregations