use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class JsonMappingTest method testConfigMapping.
@Test
public void testConfigMapping() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConfigMapping()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
System.out.println(mappedOutput);
}
use of org.eclipse.vorto.mapping.engine.IDataMapper 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.mapping.engine.IDataMapper in project vorto by eclipse.
the class JsonMappingTest method testMappingWithMalicousScript2.
@Test(expected = MappingException.class)
public void testMappingWithMalicousScript2() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMaliciousFunction() {
@Override
protected String getMaliciousFunctionBody() {
return "return exit();";
}
}).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
mapper.mapSource(gson.fromJson(json, Object.class));
}
use of org.eclipse.vorto.mapping.engine.IDataMapper 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.mapping.engine.IDataMapper in project vorto by eclipse.
the class ConfigurationMappingTest method testNotExistFunction.
@Test(expected = MappingException.class)
public void testNotExistFunction() throws Exception {
IMappingSpecification spec = new SpecWithConfiguration();
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).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);
}
Aggregations