use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification 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());
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSpecJsonReaderTest method testReadFromJson.
@Test
public void testReadFromJson() {
IMappingSpecification spec = IMappingSpecification.newBuilder().fromInputStream(MappingSpecJsonReaderTest.class.getClassLoader().getResourceAsStream("mappingspec.json")).build();
assertNotNull(spec);
assertNotNull(spec.getInfoModel());
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class ConfigurationMappingTest method testUnknownConfigProperty.
@Test(expected = IllegalArgumentException.class)
public void testUnknownConfigProperty() throws Exception {
IMappingSpecification spec = new SpecWithConfiguration();
ModelValueFactory.createFBPropertyValue(spec.getFunctionBlock("button"), "notExistProperty", true);
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification 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);
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class ConfigurationMappingTest method testMapSimpleConfigValue.
@Test
public void testMapSimpleConfigValue() throws Exception {
IMappingSpecification spec = new SpecWithConfiguration();
IDataMapper mapper = IDataMapper.newBuilder().withSpecification(spec).registerConverterFunction(new ClassFunction("button", ConfigurationMappingTest.class)).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);
}
Aggregations