Search in sources :

Example 1 with IPayloadDeserializer

use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer 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 IPayloadDeserializer

use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.

the class DataMapperTest method testMappingWithInfoModelUsingSameFunctionblock.

@Test
public void testMappingWithInfoModelUsingSameFunctionblock() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithSameFunctionblock()).build();
    String json = "{\"btnvalue1\" : 2, \"btnvalue2\": 10}";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("btn1");
    assertEquals(2.0, buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    FunctionblockValue button2FunctionblockData = mappedOutput.get("btn2");
    assertEquals(10.0, button2FunctionblockData.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithSameFunctionblock(org.eclipse.vorto.service.mapping.spec.SpecWithSameFunctionblock) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 3 with IPayloadDeserializer

use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.

the class DataMapperTest method testMappingUsingListInput.

@Test
public void testMappingUsingListInput() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithArrayPayload()).build();
    String json = "[{\"clickType\" : \"DOUBLE\" }, {\"clickType\" : \"SINGLE\" }]";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    FunctionblockValue buttonFunctionblockData = mappedOutput.get("button");
    assertEquals("DOUBLE", buttonFunctionblockData.getStatusProperty("sensor_value").get().getValue());
    System.out.println(mappedOutput);
}
Also used : FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) SpecWithArrayPayload(org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload) 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 4 with IPayloadDeserializer

use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.

the class DataMapperTest method testMappingWithEntityUnmapped.

@Test
public void testMappingWithEntityUnmapped() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithTwoFunctionblocksWithNestedEntity()).build();
    final String sampleDeviceData = "{\"temperature\" : 20.3 }";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
    EntityPropertyValue temperatureValue = (EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get();
    assertEquals(20.3, temperatureValue.getValue().getPropertyValue("value").get().getValue());
    assertNull(mappedOutput.get("humidity"));
}
Also used : EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithTwoFunctionblocksWithNestedEntity(org.eclipse.vorto.service.mapping.spec.SpecWithTwoFunctionblocksWithNestedEntity) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 5 with IPayloadDeserializer

use of org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer in project vorto by eclipse.

the class DataMapperTest method testMappingWithEntity.

@Test
public void testMappingWithEntity() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEntity()).build();
    final String sampleDeviceData = "{\"temperature\" : 20.3 }";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
    EntityPropertyValue temperatureValue = (EntityPropertyValue) mappedOutput.get("outdoorTemperature").getStatusProperty("value").get();
    assertEquals(20.3, temperatureValue.getValue().getPropertyValue("value").get().getValue());
}
Also used : EntityPropertyValue(org.eclipse.vorto.model.runtime.EntityPropertyValue) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) SpecWithNestedEntity(org.eclipse.vorto.service.mapping.spec.SpecWithNestedEntity) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)10 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)10 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)10 Test (org.junit.Test)10 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)9 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)3 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)3 CSVDeserializer (org.eclipse.vorto.mapping.engine.decoder.CSVDeserializer)1 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1 SpecWithConditionFunction (org.eclipse.vorto.service.mapping.spec.SpecWithConditionFunction)1 SpecWithConditionalProperties (org.eclipse.vorto.service.mapping.spec.SpecWithConditionalProperties)1 SpecWithConditionedRules (org.eclipse.vorto.service.mapping.spec.SpecWithConditionedRules)1 SpecWithNestedEntity (org.eclipse.vorto.service.mapping.spec.SpecWithNestedEntity)1 SpecWithNestedEnum (org.eclipse.vorto.service.mapping.spec.SpecWithNestedEnum)1 SpecWithPropertyConditionXpath (org.eclipse.vorto.service.mapping.spec.SpecWithPropertyConditionXpath)1 SpecWithSameFunctionblock (org.eclipse.vorto.service.mapping.spec.SpecWithSameFunctionblock)1 SpecWithTwoFunctionblocksWithNestedEntity (org.eclipse.vorto.service.mapping.spec.SpecWithTwoFunctionblocksWithNestedEntity)1