use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction in project vorto by eclipse.
the class JsonMappingTest method testDittoMappingOnlyOneFeature.
@Test
public void testDittoMappingOnlyOneFeature() 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.functionblockProperties("button"));
Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
assertNull(mappedDittoOutput.getFeatures().get("voltage"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction 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.spec.SpecWithCustomFunction 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.spec.SpecWithCustomFunction 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.spec.SpecWithCustomFunction in project vorto by eclipse.
the class CustomMapperPluginTest method testSomePlatformMapping.
@SuppressWarnings("unchecked")
@Test
public void testSomePlatformMapping() throws Exception {
IDataMapper<PlatformData> mapper = new SomePlatformMapper(new SpecWithCustomFunction());
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
PlatformData mappedData = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
Map<String, Object> reportedButton = (Map<String, Object>) mappedData.getState().getReported().get("button");
assertEquals(true, (Boolean) reportedButton.get("digital_input_state"));
assertEquals(2, reportedButton.get("digital_input_count"));
Map<String, Object> reportedVoltage = (Map<String, Object>) mappedData.getState().getReported().get("voltage");
assertEquals(2322f, reportedVoltage.get("sensor_value"));
assertEquals("mV", reportedVoltage.get("sensor_units"));
System.out.println(mappedData.toJson());
}
Aggregations