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