use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class JsonMappingTest method testMappingWithMalicousScriptUsingJavaImports.
@Test(expected = MappingException.class)
public void testMappingWithMalicousScriptUsingJavaImports() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMaliciousFunction() {
@Override
protected String getMaliciousFunctionBody() {
return "load('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js')";
}
}).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 JsonMappingTest method testMappingWithMalicousScript.
@Test(expected = MappingException.class)
public void testMappingWithMalicousScript() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMaliciousFunction() {
@Override
protected String getMaliciousFunctionBody() {
return "return quit();";
}
}).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 JsonMappingTest method testInvokeJsFunctionWithSingleByteArrayParam.
@Test
public void testInvokeJsFunctionWithSingleByteArrayParam() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithArrayType()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
BinaryData data = new BinaryData();
data.setData("Hallo".getBytes());
InfomodelValue mappedOutput = mapper.mapSource(data);
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals("H", buttonFunctionblockData.getStatusProperty("flag").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DataMapperTest method testMappingWithEntity.
@Test
public void testMappingWithEntity() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntity()).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());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DataMapperTest method testMapWithSimpleCondition.
@Test
public void testMapWithSimpleCondition() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionalProperties()).build();
String json = "{\"count\" : 2 }";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
assertFalse(mappedOutput.get("button").getStatusProperty("sensor_value").isPresent());
assertEquals(2.0, mappedOutput.get("button").getStatusProperty("sensor_value2").get().getValue());
json = "{\"count\" : 0 }";
mappedOutput = mapper.mapSource(deserializer.deserialize(json));
assertEquals(0.0, mappedOutput.get("button").getStatusProperty("sensor_value").get().getValue());
assertFalse(mappedOutput.get("button").getStatusProperty("sensor_value2").isPresent());
}
Aggregations