use of org.eclipse.vorto.service.mapping.ditto.Feature in project vorto by eclipse.
the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel2.
@Test
public void testMapSingleFunctionblockOfInfomodel2() {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionedRules()).buildDittoMapper();
final String sampleHomeConnectRESTResponse = "{\"data\" : { \"key\" : \"DoorState\", \"value\" : \"Locked\"}}";
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(sampleHomeConnectRESTResponse), MappingContext.empty());
System.out.println(mappedDittoOutput.toJson());
assertFalse(mappedDittoOutput.getFeatures().containsKey("operationState"));
Feature doorStateFeature = mappedDittoOutput.getFeatures().get("doorState");
assertEquals("Locked", (String) doorStateFeature.getStatusProperties().get("sensor_value"));
}
use of org.eclipse.vorto.service.mapping.ditto.Feature in project vorto by eclipse.
the class JsonMappingTest method testCreateDynamicMappingSpec.
@Test
public void testCreateDynamicMappingSpec() 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"));
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
Map<String, Object> input = new HashMap<String, Object>();
input.put("dist", 5.3);
input.put("incl", 38.8);
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(input), MappingContext.empty());
Feature distance = mappedDittoOutput.getFeatures().get("distancesensor");
assertEquals(5.3, distance.getStatusProperties().get("distance"));
Feature incline = mappedDittoOutput.getFeatures().get("inclinesensor");
assertEquals(38.8, incline.getStatusProperties().get("degree"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.ditto.Feature in project vorto by eclipse.
the class JsonMappingTest method testDittoMappingWithInfoModelUsingSameFunctionblock.
@Test
public void testDittoMappingWithInfoModelUsingSameFunctionblock() throws Exception {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithSameFunctionblock()).buildDittoMapper();
String json = "{\"btnvalue1\" : 2, \"btnvalue2\": 10}";
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
Feature buttonFeature = mappedDittoOutput.getFeatures().get("btn1");
assertEquals(2, buttonFeature.getStatusProperties().get("sensor_value"));
Feature button2Feature = mappedDittoOutput.getFeatures().get("btn2");
assertEquals(10, button2Feature.getStatusProperties().get("sensor_value"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.ditto.Feature in project vorto by eclipse.
the class BinaryMappingTest method testMappingWithBinary.
@Test
public void testMappingWithBinary() throws Exception {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithByteArrayConverter()).buildDittoMapper();
String json = "{\"data\" : [0, 0, 0, -48, 7, 0]}";
DittoData mappedDittoOutput = mapper.map(DataInputFactory.getInstance().fromJson(json), MappingContext.empty());
Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
assertEquals(20.00, buttonFeature.getStatusProperties().get("sensor_value"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.ditto.Feature 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());
}
Aggregations