Search in sources :

Example 6 with IDataMapper

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

the class JsonMappingTest method testConfigMapping.

@Test
public void testConfigMapping() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConfigMapping()).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));
    System.out.println(mappedOutput);
}
Also used : 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 7 with IDataMapper

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

the class JsonMappingTest method testMapSingleFunctionblockOfInfomodel.

@Test
public void testMapSingleFunctionblockOfInfomodel() {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCustomFunction()).registerConverterFunction(TypeFunctionFactory.createFunctions()).registerConverterFunction(StringFunctionFactory.createFunctions()).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\"}";
    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");
    assertNull(voltageFunctionblockData);
    System.out.println(gson.toJson(mappedOutput.serialize()));
}
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 8 with IDataMapper

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

the class JsonMappingTest method testMappingWithMalicousScript2.

@Test(expected = MappingException.class)
public void testMappingWithMalicousScript2() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithMaliciousFunction() {

        @Override
        protected String getMaliciousFunctionBody() {
            return "return exit();";
        }
    }).registerScriptEvalProvider(new JavascriptEvalProvider()).build();
    String json = "{\"clickType\" : \"DOUBLE\", \"batteryVoltage\": \"2322mV\"}";
    mapper.mapSource(gson.fromJson(json, Object.class));
}
Also used : IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) JavascriptEvalProvider(org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider) Test(org.junit.Test)

Example 9 with IDataMapper

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

the class ConvertTest method testMappingTypeConversion.

@Test
public void testMappingTypeConversion() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTypeConversion()).registerConverterFunction(TypeFunctionFactory.createFunctions()).build();
    String json = "[{\"lng\" : 0.002322},{\"lng\" : 0.002222}]";
    InfomodelValue mappedOutput = mapper.mapSource(gson.fromJson(json, Object.class));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals("0.002322", buttonFunctionblockData.getStatusProperty("sensor_value").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) Test(org.junit.Test)

Example 10 with IDataMapper

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

the class ConfigurationMappingTest method testNotExistFunction.

@Test(expected = MappingException.class)
public void testNotExistFunction() throws Exception {
    IMappingSpecification spec = new SpecWithConfiguration();
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).build();
    PropertyValue newValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", true);
    PropertyValue oldValue = ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "enable", false);
    Object mapped = mapper.mapTarget(newValue, Optional.of(oldValue), "button");
    assertEquals("1", mapped);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) 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