Search in sources :

Example 46 with InfomodelValue

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

the class BinaryMappingLoadTest method doubleNestedConverter2.

@Test
@JUnitPerfTest(threads = THREAD_AMOUNT_2, durationMs = TEST_DURATION_2, rampUpPeriodMs = RAMP_PERIOD, warmUpMs = WARMUP_DURATION_2, maxExecutionsPerSecond = EXECUTIONS_PER_SECOND_2)
public void doubleNestedConverter2() 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 47 with InfomodelValue

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

the class BinaryMappingLoadTest method doubleNestedConverter1.

// // Test Case 2 - Double Nested Converter Functions (Built-in (Java) + 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 doubleNestedConverter1() 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 48 with InfomodelValue

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

the class DataMapperTest method testMappingWithEntity.

@Test
public void testMappingWithEntity() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntity()).build();
    final String sampleDeviceData = "{\"temperature\" : 20.3 }";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
    EntityPropertyValue temperatureValue = (EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get();
    assertEquals(20.3, temperatureValue.getValue().getPropertyValue("value").get().getValue());
}
Also used : EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithNestedEntity(org.eclipse.vorto.service.mapping.spec.SpecWithNestedEntity) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 49 with InfomodelValue

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

the class DataMapperTest method testMapWithSimpleCondition.

@Test
public void testMapWithSimpleCondition() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionalProperties()).build();
    String json = "{\"count\" : 2 }";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    assertFalse(mappedOutput.get("button").getStatusProperty("sensor_value").isPresent());
    assertEquals(2.0, mappedOutput.get("button").getStatusProperty("sensor_value2").get().getValue());
    json = "{\"count\" : 0 }";
    mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    assertEquals(0.0, mappedOutput.get("button").getStatusProperty("sensor_value").get().getValue());
    assertFalse(mappedOutput.get("button").getStatusProperty("sensor_value2").isPresent());
}
Also used : 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) SpecWithConditionalProperties(org.eclipse.vorto.service.mapping.spec.SpecWithConditionalProperties) Test(org.junit.Test)

Example 50 with InfomodelValue

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

the class DataMapperTest method testStringArrayWithSimpleCondition.

@Test
public void testStringArrayWithSimpleCondition() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionFunction()).build();
    IPayloadDeserializer deserializer = new CSVDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(",2,3"));
    assertNull(mappedOutput.get("button"));
    mappedOutput = mapper.mapSource(deserializer.deserialize("1,2,3"));
    System.out.println(mappedOutput.get("button").getStatusProperty("sensor_value"));
    assertTrue(mappedOutput.get("button").getStatusProperty("sensor_value").isPresent());
}
Also used : SpecWithConditionFunction(org.eclipse.vorto.service.mapping.spec.SpecWithConditionFunction) CSVDeserializer(org.eclipse.vorto.mapping.engine.decoder.CSVDeserializer) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) 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