Search in sources :

Example 1 with SpecWithCondition

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

the class JsonMappingTest method testMapWithSimpleCondition.

@Test
public void testMapWithSimpleCondition() throws Exception {
    IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(new SpecWithCondition()).buildDittoMapper();
    String json = "{\"count\" : 2 }";
    DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertNull(mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value"));
    assertEquals(2, mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value2"));
    json = "{\"count\" : 0 }";
    mappedDittoOutput = mapper.map(DataInput.newInstance().fromJson(json), MappingContext.empty());
    assertEquals(0, mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value"));
    assertNull(mappedDittoOutput.getFeatures().get("button").getStatusProperties().get("sensor_value2"));
}
Also used : SpecWithCondition(org.eclipse.vorto.service.mapping.spec.SpecWithCondition) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Aggregations

DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)1 SpecWithCondition (org.eclipse.vorto.service.mapping.spec.SpecWithCondition)1 Test (org.junit.Test)1