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");
}
}
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());
}
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()));
}
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());
}
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()));
}
Aggregations