Search in sources :

Example 1 with IMappingSpecification

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());
}
Also used : IMappingSpecification(org.eclipse.vorto.service.mapping.spec.IMappingSpecification) HashMap(java.util.HashMap) Feature(org.eclipse.vorto.service.mapping.ditto.Feature) DittoData(org.eclipse.vorto.service.mapping.ditto.DittoData) Test(org.junit.Test)

Example 2 with IMappingSpecification

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

Example 3 with IMappingSpecification

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

Example 4 with IMappingSpecification

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

Example 5 with IMappingSpecification

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

Aggregations

IMappingSpecification (org.eclipse.vorto.service.mapping.spec.IMappingSpecification)9 Test (org.junit.Test)9 DittoData (org.eclipse.vorto.service.mapping.ditto.DittoData)3 Feature (org.eclipse.vorto.service.mapping.ditto.Feature)3 HashMap (java.util.HashMap)2