Search in sources :

Example 36 with InfomodelValue

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());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 37 with InfomodelValue

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());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) BinaryData(org.eclipse.vorto.mapping.engine.model.binary.BinaryData) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 38 with InfomodelValue

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;
}
Also used : Gson(com.google.gson.Gson) TestMappingResponse(org.eclipse.vorto.repository.web.core.dto.mapping.TestMappingResponse) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 39 with 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.toShadowUpdateRequest(infomodelValue)));
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) Infomodel(org.eclipse.vorto.model.Infomodel) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 40 with 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")));
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) Infomodel(org.eclipse.vorto.model.Infomodel) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)58 Test (org.junit.Test)54 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)29 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)25 JUnitPerfTest (com.github.noconnor.junitperf.JUnitPerfTest)24 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)10 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)10 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)10 Random (java.util.Random)8 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)8 Infomodel (org.eclipse.vorto.model.Infomodel)5 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)4 HashMap (java.util.HashMap)3 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)3 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 MappingEngine (org.eclipse.vorto.mapping.engine.MappingEngine)2 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1