use of org.eclipse.vorto.service.mapping.ble.json.GattService 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());
}
Aggregations