use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.
the class MappingSpecJsonReaderTest method testMappingFromJson.
@Test
public void testMappingFromJson() {
IMappingSpecification spec = IMappingSpecification.newBuilder().fromInputStream(MappingSpecJsonReaderTest.class.getClassLoader().getResourceAsStream("mappingspec.json")).build();
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).build();
String json = "{\"t\" : 50}";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
assertEquals(50.0, ((EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get()).getValue().getPropertyValue("value").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.
the class DataMapperTest method testMappingWithInfoModelUsingSameFunctionblock.
@Test
public void testMappingWithInfoModelUsingSameFunctionblock() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithSameFunctionblock()).build();
String json = "{\"btnvalue1\" : 2, \"btnvalue2\": 10}";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("btn1");
assertEquals(2.0, buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
FunctionblockValue button2FunctionblockData = mappedOutput.get("btn2");
assertEquals(10.0, button2FunctionblockData.getStatusProperty("sensor_value").get().getValue());
System.out.println(mappedOutput);
}
use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.
the class DataMapperTest method testMappingUsingListInput.
@Test
public void testMappingUsingListInput() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithArrayPayload()).build();
String json = "[{\"clickType\" : \"DOUBLE\" }, {\"clickType\" : \"SINGLE\" }]";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals("DOUBLE", buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
System.out.println(mappedOutput);
}
use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.
the class DataMapperTest method testMappingWithEntityUnmapped.
@Test
public void testMappingWithEntityUnmapped() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTwoFunctionblocksWithNestedEntity()).build();
final String sampleDeviceData = "{\"temperature\" : 20.3 }";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
EntityPropertyValue temperatureValue = (EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get();
assertEquals(20.3, temperatureValue.getValue().getPropertyValue("value").get().getValue());
assertNull(mappedOutput.get("humidity"));
}
use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.
the class DataMapperTest method testMappingWithEntity.
@Test
public void testMappingWithEntity() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntity()).build();
final String sampleDeviceData = "{\"temperature\" : 20.3 }";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
EntityPropertyValue temperatureValue = (EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get();
assertEquals(20.3, temperatureValue.getValue().getPropertyValue("value").get().getValue());
}
Aggregations