Search in sources :

Example 11 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class BinaryMappingTest method testMappingWithBinary.

@Test
public void testMappingWithBinary() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithByteArrayConverter()).buildDittoMapper();
    String json = "{\"data\" : [0, 0, 0, -48, 7, 0]}";
    DittoData mappedDittoOutput = mapper.map(DataInputFactory.getInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(20.00, buttonFeature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithByteArrayConverter(org.eclipse.vorto.service.mapping.spec.SpecWithByteArrayConverter) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 12 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testDittoMappingFromRemoteRepository.

@Test
public void testDittoMappingFromRemoteRepository() throws Exception {
    IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("devices.aws.button.AWSIoTButton:1.0.0").targetPlatformKey("devices_aws_button_AWSIoTButton_1_0_0").build();
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
    Map<String, Object> input = new HashMap<String, Object>();
    input.put("clickType", "DOUBLE");
    input.put("batteryVoltage", "2322mV");
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(input), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
    assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
    Feature voltageFeature = mappedDittoOutput.getFeatures().get("batteryVoltage");
    assertEquals(2322f, voltageFeature.getStatusProperties().get("sensor_value"));
    assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : IMappingSpecification(org.eclipse.vorto.service.mapping.spec.IMappingSpecification) HashMap(java.util.HashMap) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 13 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testMapWithJxpathCondition.

@Test
public void testMapWithJxpathCondition() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionXpath()).buildDittoMapper();
    String json = "{\"data\" : [{\"id\": 100,\"value\": \"x\"},{\"id\": 200,\"value\": \"y\"}]}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertEquals(100.0, mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value"));
}
Also used : SpecWithConditionXpath(org.eclipse.vorto.service.mapping.spec.SpecWithConditionXpath) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 14 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testDittoMappingTypeConversion.

@Test
public void testDittoMappingTypeConversion() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTypeConversion()).buildDittoMapper();
    String json = "[{\"lng\" : 0.002322},{\"lng\" : 0.002222}]";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals("0.002322", buttonFeature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithTypeConversion(org.eclipse.vorto.service.mapping.spec.SpecWithTypeConversion) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 15 with DittoData

use of org.eclipse.vorto.service.mapping.ditto.DittoData in project vorto by eclipse.

the class JsonMappingTest method testDittoMapping.

@Test
public void testDittoMapping() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).buildDittoMapper();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
    assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
    Feature voltageFeature = mappedDittoOutput.getFeatures().get("voltage");
    assertEquals(2322f, voltageFeature.getStatusProperties().get("sensor_value"));
    assertEquals("mV", voltageFeature.getStatusProperties().get("sensor_units"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : SpecWithCustomFunction(org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Aggregations

DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)20 Test (org.junit.Test)19 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)15 SpecWithCustomFunction (org.eclipse.vorto.service.mapping.spec.SpecWithCustomFunction)4 IMappingSpecification (org.eclipse.vorto.service.mapping.spec.IMappingSpecification)3 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BleGattCharacteristic (org.eclipse.vorto.service.mapping.ble.BleGattCharacteristic)1 BleGattDevice (org.eclipse.vorto.service.mapping.ble.BleGattDevice)1 GattCharacteristic (org.eclipse.vorto.service.mapping.ble.json.GattCharacteristic)1 GattDevice (org.eclipse.vorto.service.mapping.ble.json.GattDevice)1 GattService (org.eclipse.vorto.service.mapping.ble.json.GattService)1 FunctionblockData (org.eclipse.vorto.service.mapping.normalized.FunctionblockData)1 SpecGattConverter (org.eclipse.vorto.service.mapping.spec.SpecGattConverter)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1 SpecWithBase64Converter (org.eclipse.vorto.service.mapping.spec.SpecWithBase64Converter)1 SpecWithByteArrayConverter (org.eclipse.vorto.service.mapping.spec.SpecWithByteArrayConverter)1 SpecWithCondition (org.eclipse.vorto.service.mapping.spec.SpecWithCondition)1