Search in sources :

Example 11 with InfomodelValue

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

the class Example method main.

public static void main(String[] args) throws Exception {
    MappingEngine engine = MappingEngine.createFromInputStream(FileUtils.openInputStream(new File("src/test/resources/mappingspec.json")));
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("distance", "100m");
    InfomodelValue result = engine.mapSource(data);
    if (result.validate().isValid()) {
        JsonObject dittoPayloadToUpdateAllFeatures = TwinPayloadFactory.toDittoProtocol(result, "org.eclipse.vorto", "deviceid-123");
        System.out.println(gson.toJson(dittoPayloadToUpdateAllFeatures));
        JsonObject dittoPayloadToUpdateSingleFeature = TwinPayloadFactory.toDittoProtocol(result.get("distance"), "distance", "org.eclipse.vorto", "deviceid-123");
        System.out.println(gson.toJson(dittoPayloadToUpdateSingleFeature));
    } else {
        System.err.println("Mapped data is not valid to Vorto Model");
    }
}
Also used : HashMap(java.util.HashMap) MappingEngine(org.eclipse.vorto.mapping.engine.MappingEngine) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) File(java.io.File)

Example 12 with InfomodelValue

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

the class BinaryMappingLoadTest method tripleNestedConverter1.

// // Test Case 3: Triple Nested Converter Functions (Built-in + Built-in + Javascript)
@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_1, durationMs = TEST_DURATION_1, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_1, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_1)
public void tripleNestedConverter1() 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 13 with InfomodelValue

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

the class BinaryMappingLoadTest method builtInConverter1.

// // Test Case 1: 1 Built-in (Java) Converter Function
@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_1, durationMs = TEST_DURATION_1, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_1, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_1)
public void builtInConverter1() throws Exception {
    InfomodelValue mappedOutput = testCaseOneMapper.mapSource(gson.fromJson(testCaseOneJson, Object.class));
    assertEquals("20", new String((byte[]) mappedOutput.get("button").getStatusProperty("digital_input_state").get().getValue()));
}
Also used : InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest)

Example 14 with InfomodelValue

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

the class BinaryMappingLoadTest method doubleNestedConverter3.

@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_3, durationMs = TEST_DURATION_3, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_3, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_3)
public void doubleNestedConverter3() throws Exception {
    InfomodelValue mapped = testCaseTwoMapper.mapSource(testCaseTwoInput);
    assertEquals(20.00, mapped.get("temperature").getStatusProperty("value").get().getValue());
    assertEquals(88.19, mapped.get("humidity").getStatusProperty("value").get().getValue());
}
Also used : InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest)

Example 15 with InfomodelValue

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

the class BinaryMappingLoadTest method builtInConverter4.

@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_4, durationMs = TEST_DURATION_4, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_4, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_4)
public void builtInConverter4() throws Exception {
    InfomodelValue mappedOutput = testCaseOneMapper.mapSource(gson.fromJson(testCaseOneJson, Object.class));
    assertEquals("20", new String((byte[]) mappedOutput.get("button").getStatusProperty("digital_input_state").get().getValue()));
}
Also used : InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest) JUnitPerfTest(com.github.noconnor.junitperf.JUnitPerfTest)

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