use of org.eclipse.vorto.service.mapping.ditto.Feature in project vorto by eclipse.
the class JsonMappingTest method testDittoMappingTypeConversion.
@Test
public void testDittoMappingTypeConversion() throws Exception {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTypeConversion()).buildDittoMapper();
String json = "[{\"lng\" : 0.002322},{\"lng\" : 0.002222}]";
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
assertEquals("0.002322", 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 testDittoMapping.
@Test
public void testDittoMapping() throws Exception {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
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(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.ditto.Feature in project vorto by eclipse.
the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel.
@Test
public void testMapSingleFunctionblockOfInfomodel() {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
String json = "{\"clickType\" : \"DOUBLE\"}";
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");
assertNull(voltageFeature);
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.ditto.Feature in project vorto by eclipse.
the class JsonMappingTest method testDittoMappingTimestamp.
@Test
public void testDittoMappingTimestamp() throws Exception {
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTimestamp()).buildDittoMapper();
final Date timestamp = new Date();
String json = "{\"time\" : " + timestamp.getTime() + "}";
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
assertEquals(JSON_DATE_FORMAT.format(timestamp), 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 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