Search in sources :

Example 16 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue 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()));
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) 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 17 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue 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()));
}
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 18 with FunctionblockValue

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

Example 19 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.

the class DataMapperTest method testMappingWithInfoModelUsingSameFunctionblock.

@Test
public void testMappingWithInfoModelUsingSameFunctionblock() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithSameFunctionblock()).build();
    String json = "{\"btnvalue1\" : 2, \"btnvalue2\": 10}";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("btn1");
    assertEquals(2.0, buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    FunctionblockValue button2FunctionblockData = mappedOutput.get("btn2");
    assertEquals(10.0, button2FunctionblockData.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithSameFunctionblock(org.eclipse.vorto.service.mapping.spec.SpecWithSameFunctionblock) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 20 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue in project vorto by eclipse.

the class DataMapperTest method testMappingUsingListInput.

@Test
public void testMappingUsingListInput() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithArrayPayload()).build();
    String json = "[{\"clickType\" : \"DOUBLE\" }, {\"clickType\" : \"SINGLE\" }]";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals("DOUBLE", buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) SpecWithArrayPayload(org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)32 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)29 Test (org.junit.Test)29 JUnitPerfTest (com.github.noconnor.junitperf.JUnitPerfTest)12 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)12 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)7 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)6 Infomodel (org.eclipse.vorto.model.Infomodel)5 Random (java.util.Random)4 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)3 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)3 ModelProperty (org.eclipse.vorto.model.ModelProperty)2 Date (java.util.Date)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 MappingException (org.eclipse.vorto.mapping.engine.MappingException)1 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)1 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1