use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class JsonMappingTest method testMapNestedEntityWithCustomFunction.
@Test
public void testMapNestedEntityWithCustomFunction() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntityAndCustomFunction()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String json = "{\"clickType\" : \"DOUBLE\"}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals(2, ((EntityPropertyValue) buttonFunctionblockData.getStatusProperty("count").get()).getValue().getPropertyValue("value").get().getValue());
System.out.println(gson.toJson(mappedOutput.serialize()));
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel.
@Test
public void testMapSingleFunctionblockOfInfomodel() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String json = "{\"clickType\" : \"DOUBLE\"}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals(true, (Boolean) buttonFunctionblockData.getStatusProperty("digital_input_state").get().getValue());
assertEquals(2, buttonFunctionblockData.getStatusProperty("digital_input_count").get().getValue());
FunctionblockValue voltageFunctionblockData = mappedOutput.get("voltage");
assertNull(voltageFunctionblockData);
System.out.println(gson.toJson(mappedOutput.serialize()));
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.
the class ConvertTest method testMappingTypeConversion.
@Test
public void testMappingTypeConversion() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTypeConversion()).registerConverterFunction(TypeFunctionFactory.createFunctions()).build();
String json = "[{\"lng\" : 0.002322},{\"lng\" : 0.002222}]";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals("0.002322", buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
System.out.println(mappedOutput);
}
use of org.eclipse.vorto.model.runtime.FunctionblockValue 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.FunctionblockValue 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);
}
Aggregations