use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DataMapperTest method testStringArrayWithSimpleCondition.
@Test
public void testStringArrayWithSimpleCondition() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionFunction()).build();
IPayloadDeserializer deserializer = new CSVDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(",2,3"));
assertNull(mappedOutput.get("button"));
mappedOutput = mapper.mapSource(deserializer.deserialize("1,2,3"));
System.out.println(mappedOutput.get("button").getStatusProperty("sensor_value"));
assertTrue(mappedOutput.get("button").getStatusProperty("sensor_value").isPresent());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DataMapperTest method testMapWithJxpathCondition.
@Test
public void testMapWithJxpathCondition() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithPropertyConditionXpath()).build();
String json = "{\"data\" : [{\"id\": 100,\"value\": \"x\"},{\"id\": 200,\"value\": \"y\"}]}";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(json));
assertEquals(100.0, mappedOutput.get("button").getStatusProperty("sensor_value").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DataMapperTest method testMapSingleFunctionblockOfInfomodel2.
@Test
public void testMapSingleFunctionblockOfInfomodel2() {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithConditionedRules()).build();
final String sampleHomeConnectRESTResponse = "{\"data\" : { \"key\" : \"DoorState\", \"value\" : \"Locked\"}}";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleHomeConnectRESTResponse));
System.out.println(mappedOutput);
assertNull(mappedOutput.get("operationState"));
FunctionblockValue doorStateFunctionblockData = mappedOutput.get("doorState");
assertEquals("Locked", (String) doorStateFunctionblockData.getStatusProperty("sensor_value").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class ConfigurationMappingTest method testMapConfigurationSource.
@Test
public void testMapConfigurationSource() throws Exception {
IMappingSpecification spec = new SpecWithConfiguration2();
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).registerConverterFunction(new ClassFunction("button", ConfigurationMappingTest.class)).build();
Map<String, Object> source = new HashMap<String, Object>(1);
source.put("e", true);
InfomodelValue mapped = mapper.mapSource(source);
assertEquals(1, mapped.get("button").getConfiguration().size());
assertEquals(true, mapped.get("button").getConfiguration().get(0).getValue());
}
use of org.eclipse.vorto.mapping.engine.IDataMapper in project vorto by eclipse.
the class DataMapperTest method testMappingWithEnum.
@Test
public void testMappingWithEnum() throws Exception {
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEnum()).build();
final String sampleDeviceData = "{\"temperature\" : 20.3 }";
IPayloadDeserializer deserializer = new JSONDeserializer();
InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
assertEquals(20.3, mappedOutput.get("outdoorTemperature").getStatusProperty("value").get().getValue());
assertEquals("Celcius", mappedOutput.get("outdoorTemperature").getStatusProperty("unit").get().getValue());
}
Aggregations