Search in sources :

Example 1 with SpecWithConditionalProperties

use of org.eclipse.vorto.service.mapping.spec.SpecWithConditionalProperties in project vorto by eclipse.

the class DataMapperTest method testMapWithSimpleCondition.

@Test
public void testMapWithSimpleCondition() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionalProperties()).build();
    String json = "{\"count\" : 2 }";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    assertFalse(mappedOutput.get("button").getStatusProperty("sensor_value").isPresent());
    assertEquals(2.0, mappedOutput.get("button").getStatusProperty("sensor_value2").get().getValue());
    json = "{\"count\" : 0 }";
    mappedOutput = mapper.mapSource(deserializer.deserialize(json));
    assertEquals(0.0, mappedOutput.get("button").getStatusProperty("sensor_value").get().getValue());
    assertFalse(mappedOutput.get("button").getStatusProperty("sensor_value2").isPresent());
}
Also used : 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) SpecWithConditionalProperties(org.eclipse.vorto.service.mapping.spec.SpecWithConditionalProperties) Test(org.junit.Test)

Aggregations

IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)1 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)1 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)1 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)1 SpecWithConditionalProperties (org.eclipse.vorto.service.mapping.spec.SpecWithConditionalProperties)1 Test (org.junit.Test)1