Search in sources :

Example 1 with IMappingSpecification

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());
}
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 IMappingSpecification

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());
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) Test(org.junit.Test)

Example 3 with IMappingSpecification

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);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) Test(org.junit.Test)

Example 4 with IMappingSpecification

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);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) Test(org.junit.Test)

Example 5 with IMappingSpecification

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);
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) ClassFunction(org.eclipse.vorto.mapping.engine.functions.ClassFunction) PropertyValue(org.eclipse.vorto.model.runtime.PropertyValue) SpecWithConfiguration(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration) Test(org.junit.Test)

Aggregations

IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)11 Test (org.junit.Test)10 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)4 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)3 SpecWithConfiguration (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration)3 JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)2 ClassFunction (org.eclipse.vorto.mapping.engine.functions.ClassFunction)2 ModelId (org.eclipse.vorto.model.ModelId)2 PropertyValue (org.eclipse.vorto.model.runtime.PropertyValue)2 HashMap (java.util.HashMap)1 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)1 MappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.MappingSpecification)1 Infomodel (org.eclipse.vorto.model.Infomodel)1 ModelContent (org.eclipse.vorto.model.ModelContent)1 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)1 SpecWithConfiguration2 (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration2)1