Search in sources :

Example 1 with ClassFunction

use of org.eclipse.vorto.mapping.engine.functions.ClassFunction 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)

Example 2 with ClassFunction

use of org.eclipse.vorto.mapping.engine.functions.ClassFunction 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());
}
Also used : IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) HashMap(java.util.HashMap) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) ClassFunction(org.eclipse.vorto.mapping.engine.functions.ClassFunction) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) SpecWithConfiguration2(org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration2) Test(org.junit.Test)

Aggregations

IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)2 ClassFunction (org.eclipse.vorto.mapping.engine.functions.ClassFunction)2 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)1 PropertyValue (org.eclipse.vorto.model.runtime.PropertyValue)1 SpecWithConfiguration (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration)1 SpecWithConfiguration2 (org.eclipse.vorto.service.mapping.spec.SpecWithConfiguration2)1