use of org.eclipse.vorto.mapping.engine.IDataMapper 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.IDataMapper in project vorto by eclipse.
the class JsonMappingTest method testMapDevicePayloadWithInitialValue.
@Test
public void testMapDevicePayloadWithInitialValue() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"0mV\"}";
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");
assertEquals(0f, voltageFunctionblockData.getStatusProperty("sensor_value").get().getValue());
assertEquals("mV", voltageFunctionblockData.getStatusProperty("sensor_units").get().getValue());
System.out.println(mappedOutput);
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class BinaryMappingTest method testMapWithCustomFunctionCondition.
@Test
public void testMapWithCustomFunctionCondition() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionFunction()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerConditionFunction(StringFunctionFactory.createFunctions()).registerConditionFunction(BinaryFunctionFactory.createFunctions()).build();
String json = "{\"data\" : \"aGFsbG8=\"}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
assertEquals("hallo", mappedOutput.get("button").getStatusProperty("sensor_value").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class BinaryMappingTest method testMappingWithBinary.
@Test
public void testMappingWithBinary() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithByteArrayConverter()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String x = "4f00630063007500700061006e0063007900200002";
String json = "{\"data\" : \"" + x + "\"}";
InfomodelValue mappedDittoOutput = mapper.mapSource(gson.fromJson(json, Object.class));
FunctionblockValue button = mappedDittoOutput.get("button");
assertEquals(2, button.getStatusProperty("sensor_value").get().getValue());
System.out.println(mappedDittoOutput);
}
use of org.eclipse.vorto.mapping.engine.IDataMapper 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()));
}
Aggregations