use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class JsonMappingTest method testCreateDynamicMappingSpec.
@Test
public void testCreateDynamicMappingSpec() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
IDataMapper<DittoData> mapper = IDataMapper.newBuilder().withSpecification(mappingSpecification).buildDittoMapper();
Map<String, Object> input = new HashMap<String, Object>();
input.put("dist", 5.3);
input.put("incl", 38.8);
DittoData mappedDittoOutput = mapper.map(DataInput.newInstance().fromObject(input), MappingContext.empty());
Feature distance = mappedDittoOutput.getFeatures().get("distancesensor");
assertEquals(5.3, distance.getStatusProperties().get("distance"));
Feature incline = mappedDittoOutput.getFeatures().get("inclinesensor");
assertEquals(38.8, incline.getStatusProperties().get("degree"));
System.out.println(mappedDittoOutput.toJson());
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSerializerTest method testCreateAndSerializeMappingSpecContainingDoubleQuotesCondition.
@Test
public void testCreateAndSerializeMappingSpecContainingDoubleQuotesCondition() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("sensor_units").get().addStereotype(Stereotype.createWithXpath(""));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithConditionalXpath("xpath:eval(\"value/x\",this) == 2", "/@incl"));
MappingSpecificationSerializer.create(mappingSpecification).iterator().forEachRemaining(p -> System.out.println(p.serialize()));
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSerializerTest method testCreateAndSerializeMappingSpec2.
@Test
public void testCreateAndSerializeMappingSpec2() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("sensor_units").get().addStereotype(Stereotype.createWithXpath(""));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
MappingSpecificationSerializer.create(mappingSpecification).iterator().forEachRemaining(p -> System.out.println(p.serialize()));
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSerializerTest method testCreateAndSerializeMappingSpecContainingDoubleQuotesFunction.
@Test
public void testCreateAndSerializeMappingSpecContainingDoubleQuotesFunction() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("sensor_units").get().addStereotype(Stereotype.createWithXpath(""));
mappingSpecification.getFunctionBlock("distancesensor").addStereotype(Stereotype.createWithFunction("convert", "function convert(value) { return \"\"}"));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
MappingSpecificationSerializer.create(mappingSpecification).iterator().forEachRemaining(p -> System.out.println(p.serialize()));
}
use of org.eclipse.vorto.service.mapping.spec.IMappingSpecification in project vorto by eclipse.
the class MappingSerializerTest method testCreateAndSerializeMappingSpecContainingEmptyFunctions.
@Test
public void testCreateAndSerializeMappingSpecContainingEmptyFunctions() throws Exception {
IMappingSpecification mappingSpecification = MappingSpecificationBuilder.create().infomodelId("com.bosch.BoschGLM100C:1.0.0").build();
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("distance").get().addStereotype(Stereotype.createWithXpath("/@dist"));
mappingSpecification.getFunctionBlock("distancesensor").getStatusProperty("sensor_units").get().addStereotype(Stereotype.createWithXpath(""));
mappingSpecification.getFunctionBlock("distancesensor").addStereotype(Stereotype.create("functions", Collections.emptyMap()));
mappingSpecification.getFunctionBlock("inclinesensor").getStatusProperty("degree").get().addStereotype(Stereotype.createWithXpath("/@incl"));
MappingSpecificationSerializer.create(mappingSpecification).iterator().forEachRemaining(p -> System.out.println(p.serialize()));
}
Aggregations