use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.
the class JsonMappingTest method testMapDevicePayloadWithInitialValue.
@Test
public void testMapDevicePayloadWithInitialValue() {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"0mV\"}";
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), 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("voltage");
assertEquals(0f, voltageFeature.getStatusProperties().get("sensor_value"));
assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.ditto.DittoData 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.DittoData 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.DittoData 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.DittoData in project vorto by eclipse.
the class DittoMapper method doMap.
@Override
protected DittoData doMap(InfomodelData input, MappingContext mappingContext) {
DittoData output = new DittoData();
for (FunctionblockData fbData : input.getFunctionblockData()) {
FeatureBuilder featureBuilder = Feature.newBuilder(fbData.getId());
featureBuilder.withStatus(fbData.getStatus());
output.withFeature(featureBuilder.build());
}
return output;
}
Aggregations