use of org.eclipse.vorto.model.runtime.InfomodelValue in project vorto by eclipse.
the class JsonMappingTest method testInvokeJsFunctionWithMultipleParams.
@Test
public void testInvokeJsFunctionWithMultipleParams() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMultipleParams()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
MyData data = new MyData("Hallo".getBytes(), "#");
InfomodelValue mappedOutput = mapper.mapSource(data);
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals("#H", buttonFunctionblockData.getStatusProperty("flag").get().getValue());
}
use of org.eclipse.vorto.model.runtime.InfomodelValue 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.model.runtime.InfomodelValue in project vorto by eclipse.
the class PayloadMappingController method testMapping.
@PutMapping(value = "/test")
@PreAuthorize("hasAuthority('model_viewer')")
public TestMappingResponse testMapping(@RequestBody TestMappingRequest testRequest) throws Exception {
Object content = null;
if (testRequest.getContentType().equals(TestContentType.csv)) {
content = CSV_DESERIALIZER.deserialize(testRequest.getContent());
} else {
content = JSON_DESERIALIZER.deserialize(testRequest.getContent());
}
InfomodelValue mappedOutput = mappingService.runTest(testRequest.getSpecification(), content);
TestMappingResponse response = new TestMappingResponse();
response.setCanonical(new ObjectMapper().writeValueAsString(mappedOutput.serialize()));
response.setDitto(new Gson().toJson(org.eclipse.vorto.mapping.targetplatform.ditto.TwinPayloadFactory.toDittoProtocol(mappedOutput, "com.acme:4711")));
response.setAwsiot(new Gson().toJson(org.eclipse.vorto.mapping.targetplatform.awsiot.TwinPayloadFactory.toShadowUpdateRequest(mappedOutput)));
response.setReport(mappedOutput.validate());
return response;
}
use of org.eclipse.vorto.model.runtime.InfomodelValue in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleMultipleFbProperties.
@Test
public void testCreateRequestSingleMultipleFbProperties() {
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")).withProperty(ModelProperty.Builder("indoorTemperature", fbm).build()).withProperty(ModelProperty.Builder("outdoorTemperature", fbm).build()).build();
FunctionblockValue indoorTemperature = new FunctionblockValue(fbm);
indoorTemperature.withStatusProperty("value", 20.2);
FunctionblockValue outdoorTemperature = new FunctionblockValue(fbm);
outdoorTemperature.withStatusProperty("value", 9.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("indoorTemperature", indoorTemperature);
infomodelValue.withFunctionblock("outdoorTemperature", outdoorTemperature);
System.out.println(gson.toJson(TwinPayloadFactory.toShadowUpdateRequest(infomodelValue)));
}
use of org.eclipse.vorto.model.runtime.InfomodelValue in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleMultipleFbProperties.
@Test
public void testCreateRequestSingleMultipleFbProperties() {
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")).withProperty(ModelProperty.Builder("indoorTemperature", fbm).build()).withProperty(ModelProperty.Builder("outdoorTemperature", fbm).build()).build();
FunctionblockValue indoorTemperature = new FunctionblockValue(fbm);
indoorTemperature.withStatusProperty("value", 20.2);
FunctionblockValue outdoorTemperature = new FunctionblockValue(fbm);
outdoorTemperature.withStatusProperty("value", 9.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("indoorTemperature", indoorTemperature);
infomodelValue.withFunctionblock("outdoorTemperature", outdoorTemperature);
System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(infomodelValue, "com.acme:Sensor-1")));
}
Aggregations