use of org.eclipse.vorto.model.runtime.InfomodelValue 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.model.runtime.InfomodelValue 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.model.runtime.InfomodelValue 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.model.runtime.InfomodelValue in project vorto by eclipse.
the class PayloadMappingSpecificationTest method testRunMappingTest.
@Test
public void testRunMappingTest() {
importModel("payloadmapping/org.eclipse.vorto_Voltage_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_Battery_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_MyDevice_1.0.0.infomodel");
IMappingSpecification specification = mappingService.getOrCreateSpecification(ModelId.fromPrettyFormat("org.eclipse.vorto:MyDevice:1.0.0"));
specification.getFunctionBlock("battery").getStatusProperty("remainingCapacity").get().getStereotype(Stereotype.SOURCE).get().setAttributes(createXpathRule("/cap"));
specification.getFunctionBlock("battery").getStatusProperty("value").get().getStereotype(Stereotype.SOURCE).get().setAttributes(createXpathRule("/voltage"));
JSONDeserializer deserializer = new JSONDeserializer();
InfomodelValue testResult = mappingService.runTest(specification, deserializer.deserialize("{\"cap\": 23 ,\"voltage\": 2242.2 }"));
assertEquals(23.0, testResult.get("battery").getStatusProperty("remainingCapacity").get().getValue());
assertEquals(2242.2, testResult.get("battery").getStatusProperty("value").get().getValue());
}
use of org.eclipse.vorto.model.runtime.InfomodelValue 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