Search in sources :

Example 11 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class ConfigurationMappingTest method testMapSimpleConfigValue.

@Test
public void testMapSimpleConfigValue() throws Exception {
    IMappingSpecification spec = new SpecWithConfiguration();
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).registerConverterFunction(new ClassFunction("button", ConfigurationMappingTest.class)).build();
    PropertyValue newValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", true);
    PropertyValue oldValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", false);
    Object mapped = mapper.mapTarget(newValue, Optional.of(oldValue), "button");
    assertEquals("1", mapped);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) ClassFunction(org.eclipse.vorto.mapping.engine.functions.ClassFunction) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) Test(org.junit.Test)

Example 12 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper 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 13 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper 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)

Example 14 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class DataMapperTest method testMappingWithEntityUnmapped.

@Test
public void testMappingWithEntityUnmapped() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTwoFunctionblocksWithNestedEntity()).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());
    assertNull(mappedOutput.get("humidity"));
}
Also used : EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithTwoFunctionblocksWithNestedEntity(org.eclipse.vorto.service.mapping.spec.SpecWithTwoFunctionblocksWithNestedEntity) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 15 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class BinaryMappingTest method testMappingBinaryContaining2DataPoints.

@Test
public void testMappingBinaryContaining2DataPoints() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecBinaryConverter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    // 2 byte temperature (Byte 1-2), 2 byte humidity (Byte 3-4)
    byte[] dest = new byte[4];
    byte[] value = Conversion.intToByteArray(2000, 0, dest, 0, 2);
    value = Conversion.intToByteArray(8819, 0, dest, 2, 2);
    BinaryData data = new BinaryData(value);
    InfomodelValue mapped = mapper.mapSource(data);
    assertEquals(20.00, mapped.get("temperature").getStatusProperty("value").get().getValue());
    assertEquals(88.19, mapped.get("humidity").getStatusProperty("value").get().getValue());
}
Also used : IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) BinaryData(org.eclipse.vorto.mapping.engine.model.binary.BinaryData) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Aggregations

IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)30 Test (org.junit.Test)30 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)25 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)13 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)12 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)10 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)9 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)4 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)4 ClassFunction (org.eclipse.vorto.mapping.engine.functions.ClassFunction)2 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)2 PropertyValue (org.eclipse.vorto.model.runtime.PropertyValue)2 SpecWithConfiguration (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration)2 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 CSVDeserializer (org.eclipse.vorto.mapping.engine.decoder.CSVDeserializer)1 GattCharacteristic (org.eclipse.vorto.mapping.engine.model.blegatt.GattCharacteristic)1 GattDevice (org.eclipse.vorto.mapping.engine.model.blegatt.GattDevice)1