use of org.eclipse.vorto.mapping.engine.model.binary.BinaryData in project vorto by eclipse.
the class BinaryMappingTest method testMappingBinaryContaining2DataPoints.
@Test
public void testMappingBinaryContaining2DataPoints() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecBinaryConverter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
// 2 byte temperature (Byte 1-2), 2 byte humidity (Byte 3-4)
byte[] dest = new byte[4];
byte[] value = Conversion.intToByteArray(2000, 0, dest, 0, 2);
value = Conversion.intToByteArray(8819, 0, dest, 2, 2);
BinaryData data = new BinaryData(value);
InfomodelValue mapped = mapper.mapSource(data);
assertEquals(20.00, mapped.get("temperature").getStatusProperty("value").get().getValue());
assertEquals(88.19, mapped.get("humidity").getStatusProperty("value").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.model.binary.BinaryData in project vorto by eclipse.
the class JsonMappingTest method testInvokeJsFunctionWithSingleByteArrayParam.
@Test
public void testInvokeJsFunctionWithSingleByteArrayParam() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithArrayType()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
BinaryData data = new BinaryData();
data.setData("Hallo".getBytes());
InfomodelValue mappedOutput = mapper.mapSource(data);
FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
assertEquals("H", buttonFunctionblockData.getStatusProperty("flag").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.model.binary.BinaryData in project vorto by eclipse.
the class BinaryMappingLoadTest method init.
@BeforeClass
public static void init() {
// Test Case 1
testCaseOneMapper = IDataMapper.newBuilder().withSpecification(new SpecWithBase64Converter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).build();
testCaseOneJson = "{\"data\" : \"" + Base64.encodeBase64String("20".getBytes()) + "\"}";
// Test Case 2
testCaseTwoMapper = IDataMapper.newBuilder().withSpecification(new SpecBinaryConverter()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
// 2 byte temperature (Byte 1-2), 2 byte humidity (Byte 3-4)
byte[] dest = new byte[4];
byte[] value = Conversion.intToByteArray(2000, 0, dest, 0, 2);
value = Conversion.intToByteArray(8819, 0, dest, 2, 2);
testCaseTwoInput = new BinaryData(value);
// Test Case 3
testCaseThreeMapper = IDataMapper.newBuilder().withSpecification(new SpecWithByteArrayConverter()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
String x = "4f00630063007500700061006e0063007900200002";
testCaseThreeJson = "{\"data\" : \"" + x + "\"}";
}
Aggregations