use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DateConvertTest method testMappingTimestamp.
@Test
public void testMappingTimestamp() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTimestamp()).registerConverterFunction(DateFunctionFactory.createFunctions()).build();
final Date timestamp = new Date();
String json = "{\"time\" : " + timestamp.getTime() + "}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals(JSON_DATE_FORMAT.format(timestamp), buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
System.out.println(mappedOutput);
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class JsonMappingTest method testMapping.
@Test
public void testMapping() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals(true, (Boolean) buttonFunctionblockData.getStatusProperty("digital_input_state").get().getValue());
assertEquals(2, buttonFunctionblockData.getStatusProperty("digital_input_count").get().getValue());
FunctionblockValue voltageFunctionblockData = mappedOutput.get("voltage");
assertEquals(2322f, voltageFunctionblockData.getStatusProperty("sensor_value").get().getValue());
assertEquals("mV", voltageFunctionblockData.getStatusProperty("sensor_units").get().getValue());
System.out.println(gson.toJson(mappedOutput.serialize()));
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class BinaryMappingTest method testMappingWithGattStructure.
@Test
public void testMappingWithGattStructure() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecGattConverter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
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);
InfomodelValue mapped = mapper.mapSource(gson.fromJson(json, Object.class));
assertEquals(20.00, mapped.get("button").getStatusProperty("sensor_value").get().getValue());
System.out.println(mapped);
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class BinaryMappingTest method testMapUsingBase64Converter.
@Test
public void testMapUsingBase64Converter() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithBase64Converter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).build();
String json = "{\"data\" : \"" + Base64.encodeBase64String("20".getBytes()) + "\"}";
InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
assertEquals("20", new String((byte[]) mappedOutput.get("button").getStatusProperty("digital_input_state").get().getValue()));
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class JsonMappingTest method testInvokeJsFunctionWithMultipleParams.
@Test
public void testInvokeJsFunctionWithMultipleParams() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMultipleParams()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
MyData data = new MyData("Hallo".getBytes(), "#");
InfomodelValue mappedOutput = mapper.mapSource(data);
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals("#H", buttonFunctionblockData.getStatusProperty("flag").get().getValue());
}
Aggregations