Search in sources :

Example 26 with FunctionblockValue

use of org.eclipse.vorto.model.runtime.FunctionblockValue 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)

Example 27 with FunctionblockValue

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

the class TwinPayloadFactoryTest method testCreateRequestSingleFbPropertyforEntireInfomodel.

@Test
public void testCreateRequestSingleFbPropertyforEntireInfomodel() {
    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("temperature", fbm).build()).build();
    FunctionblockValue fbValue = new FunctionblockValue(fbm);
    fbValue.withStatusProperty("value", 20.2);
    InfomodelValue infomodelValue = new InfomodelValue(infomodel);
    infomodelValue.withFunctionblock("temperature", fbValue);
    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)

Example 28 with FunctionblockValue

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

the class BinaryMappingLoadTest method tripleNestedConverter3.

@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_3, durationMs = TEST_DURATION_3, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_3, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_3)
public void tripleNestedConverter3() throws Exception {
    InfomodelValue mappedDittoOutput = testCaseThreeMapper.mapSource(gson.fromJson(testCaseThreeJson, Object.class));
    FunctionblockValue button = mappedDittoOutput.get("button");
    assertEquals(2, button.getStatusProperty("sensor_value").get().getValue());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest)

Example 29 with FunctionblockValue

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

the class DataMapperTest method testMapSingleFunctionblockOfInfomodel2.

@Test
public void testMapSingleFunctionblockOfInfomodel2() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionedRules()).build();
    final String sampleHomeConnectRESTResponse = "{\"data\" : { \"key\" : \"DoorState\", \"value\" : \"Locked\"}}";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleHomeConnectRESTResponse));
    System.out.println(mappedOutput);
    assertNull(mappedOutput.get("operationState"));
    FunctionblockValue doorStateFunctionblockData = mappedOutput.get("doorState");
    assertEquals("Locked", (String) doorStateFunctionblockData.getStatusProperty("sensor_value").get().getValue());
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithConditionedRules(org.eclipse.vorto.service.mapping.spec.SpecWithConditionedRules) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 30 with FunctionblockValue

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

the class JsonMappingLoadTest method builtInConverterAndJs4.

@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_4, durationMs = TEST_DURATION_4, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_4, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_4)
public void builtInConverterAndJs4() throws Exception {
    int r = new Random().nextInt(2 + 1);
    InfomodelValue mappedOutput = testCaseThreeMapper.mapSource(gson.fromJson(testCaseThreeJsonInput[r], Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals(true, (Boolean) buttonFunctionblockData.getStatusProperty("digital_input_state").get().getValue());
    assertEquals(testCaseThreeOutput[r], buttonFunctionblockData.getStatusProperty("digital_input_count").get().getValue());
    FunctionblockValue voltageFunctionblockData = mappedOutput.get("voltage");
    assertNull(voltageFunctionblockData);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) Random(java.util.Random) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest)

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