Search in sources :

Example 1 with DittoData

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

the class BinaryMappingTest method testMappingWithGattStructure.

@Test
public void testMappingWithGattStructure() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecGattConverter()).buildDittoMapper();
    GattDevice gattDevice = new GattDevice();
    GattService gattService = new GattService();
    List<GattCharacteristic> characteristics = new ArrayList<GattCharacteristic>();
    byte[] dest = new byte[6];
    byte[] value = Conversion.intToByteArray(2000, 0, dest, 3, 3);
    characteristics.add(new GattCharacteristic("23-D1-13-EF-5F-78-23-15-DE-EF-12-12-0D-F0-00-00", value));
    gattService.setCharacteristics(characteristics);
    List<GattService> services = new ArrayList<GattService>();
    services.add(gattService);
    gattDevice.setModelNumber("23-23-23");
    gattDevice.setServices(services);
    gattDevice.setCharacteristics(characteristics);
    String json = new Gson().toJson(gattDevice);
    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 : GattCharacteristic(org.eclipse.vorto.service.mapping.ble.json.GattCharacteristic) GattDevice(org.eclipse.vorto.service.mapping.ble.json.GattDevice) ArrayList(java.util.ArrayList) SpecGattConverter(org.eclipse.vorto.service.mapping.spec.SpecGattConverter) Gson(com.google.gson.Gson) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) GattService(org.eclipse.vorto.service.mapping.ble.json.GattService) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 2 with DittoData

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

the class BleGattMappingTest method testBleGattMapping.

@Test
public void testBleGattMapping() throws Exception {
    // SETUP
    TestMappingSpecification mapping = new TestMappingSpecification();
    BleGattDevice bleGattDevice = BleGattDeviceBuilder.newBuilder().withSpecification(mapping).build();
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mapping).buildDittoMapper();
    // RUNTIME
    BleGattCharacteristic barometerValue = bleGattDevice.getCharacteristics().get("f000aa41-0451-4000-b000-000000000000");
    barometerValue.setData(new Short[] { 0x00, 0x00, 0x00, 0xD0, 0x07, 0x00 });
    BleGattCharacteristic accelerometerValue = bleGattDevice.getCharacteristics().get("f000aa81-0451-4000-b000-000000000000");
    accelerometerValue.setData(new Short[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X Value = 1.0 */
    0x00, 0x40, /* Y Value = -1 */
    0x00, 0xC0, /* Z Value  = 0.0 */
    0x00, 0x00 });
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(bleGattDevice), MappingContext.empty());
    // TEST
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("accelerometer");
    assertEquals(1.0, buttonFeature.getStatusProperties().get("x_value"));
    assertEquals(-1.0, buttonFeature.getStatusProperties().get("y_value"));
    Feature voltageFeature = mappedDittoOutput.getFeatures().get("barometer");
    assertEquals(20.00, voltageFeature.getStatusProperties().get("sensor_value"));
    System.out.println(mappedDittoOutput.toJson());
}
Also used : BleGattDevice(org.eclipse.vorto.service.mapping.ble.BleGattDevice) BleGattCharacteristic(org.eclipse.vorto.service.mapping.ble.BleGattCharacteristic) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 3 with DittoData

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

the class JsonMappingTest method testMapWithCustomFunctionCondition.

@Test
public void testMapWithCustomFunctionCondition() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionFunction()).buildDittoMapper();
    String json = "{\"data\" : \"aGFsbG8=\"}";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertEquals("hallo", mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value"));
}
Also used : SpecWithConditionFunction(org.eclipse.vorto.service.mapping.spec.SpecWithConditionFunction) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 4 with DittoData

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

the class JsonMappingTest method testDittoMappingUsingListInput.

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

Example 5 with DittoData

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

the class JsonMappingTest method testDittoMappingOnlyOneFeature.

@Test
public void testDittoMappingOnlyOneFeature() 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.functionblockProperties("button"));
    Feature buttonFeature = mappedDittoOutput.getFeatures().get("button");
    assertEquals(true, (Boolean) buttonFeature.getStatusProperties().get("digital_input_state"));
    assertEquals(2, buttonFeature.getStatusProperties().get("digital_input_count"));
    assertNull(mappedDittoOutput.getFeatures().get("voltage"));
    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