Search in sources :

Example 1 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class MappingSpecJsonReaderTest method testMappingFromJson.

@Test
public void testMappingFromJson() {
    IMappingSpecification spec = IMappingSpecification.newBuilder().fromInputStream(MappingSpecJsonReaderTest.class.getClassLoader().getResourceAsStream("mappingspec.json")).build();
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).build();
    String json = "{\"t\" : 50}";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    assertEquals(50.0, ((EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get()).getValue().getPropertyValue("value").get().getValue());
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 2 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class JsonMappingTest method testMapDevicePayloadWithInitialValue.

@Test
public void testMapDevicePayloadWithInitialValue() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"0mV\"}";
    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(0f, voltageFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    assertEquals("mV", voltageFunctionblockData.getStatusProperty("sensor_units").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 3 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class BinaryMappingTest method testMapWithCustomFunctionCondition.

@Test
public void testMapWithCustomFunctionCondition() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionFunction()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerConditionFunction(StringFunctionFactory.createFunctions()).registerConditionFunction(BinaryFunctionFactory.createFunctions()).build();
    String json = "{\"data\" : \"aGFsbG8=\"}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    assertEquals("hallo", mappedOutput.get("button").getStatusProperty("sensor_value").get().getValue());
}
Also used : IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 4 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class BinaryMappingTest method testMappingWithBinary.

@Test
public void testMappingWithBinary() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithByteArrayConverter()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(BinaryFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String x = "4f00630063007500700061006e0063007900200002";
    String json = "{\"data\" : \"" + x + "\"}";
    InfomodelValue mappedDittoOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue button = mappedDittoOutput.get("button");
    assertEquals(2, button.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedDittoOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 5 with IDataMapper

use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.

the class JsonMappingTest method testMapNestedEntityWithCustomFunction.

@Test
public void testMapNestedEntityWithCustomFunction() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntityAndCustomFunction()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\"}";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals(2, ((EntityPropertyValue) buttonFunctionblockData.getStatusProperty("count").get()).getValue().getPropertyValue("value").get().getValue());
    System.out.println(gson.toJson(mappedOutput.serialize()));
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Aggregations

IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)30 Test (org.junit.Test)30 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)25 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)13 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)12 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)10 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)9 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)4 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)4 ClassFunction (org.eclipse.vorto.mapping.engine.functions.ClassFunction)2 BinaryData (org.eclipse.vorto.mapping.engine.model.binary.BinaryData)2 PropertyValue (org.eclipse.vorto.model.runtime.PropertyValue)2 SpecWithConfiguration (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration)2 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 CSVDeserializer (org.eclipse.vorto.mapping.engine.decoder.CSVDeserializer)1 GattCharacteristic (org.eclipse.vorto.mapping.engine.model.blegatt.GattCharacteristic)1 GattDevice (org.eclipse.vorto.mapping.engine.model.blegatt.GattDevice)1