use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class ConfigurationMappingTest method testMapSimpleConfigValue.
@Test
public void testMapSimpleConfigValue() throws Exception {
IMappingSpecification spec = new SpecWithConfiguration();
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).registerConverterFunction(new ClassFunction("button", ConfigurationMappingTest.class)).build();
PropertyValue newValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", true);
PropertyValue oldValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", false);
Object mapped = mapper.mapTarget(newValue, Optional.of(oldValue), "button");
assertEquals("1", mapped);
}
use of org.eclipse.vorto.mapping.engine.IDataMapper 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.IDataMapper 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.IDataMapper 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.IDataMapper in project vorto by eclipse.
the class BinaryMappingTest method testMappingBinaryContaining2DataPoints.
@Test
public void testMappingBinaryContaining2DataPoints() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecBinaryConverter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
// 2 byte temperature (Byte 1-2), 2 byte humidity (Byte 3-4)
byte[] dest = new byte[4];
byte[] value = Conversion.intToByteArray(2000, 0, dest, 0, 2);
value = Conversion.intToByteArray(8819, 0, dest, 2, 2);
BinaryData data = new BinaryData(value);
InfomodelValue mapped = mapper.mapSource(data);
assertEquals(20.00, mapped.get("temperature").getStatusProperty("value").get().getValue());
assertEquals(88.19, mapped.get("humidity").getStatusProperty("value").get().getValue());
}
Aggregations