use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class PayloadMappingSpecificationTest method testRunMappingTest.
@Test
public void testRunMappingTest() {
importModel("payloadmapping/org.eclipse.vorto_Voltage_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_Battery_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_MyDevice_1.0.0.infomodel");
IMappingSpecification specification = mappingService.getOrCreateSpecification(ModelId.fromPrettyFormat("org.eclipse.vorto:MyDevice:1.0.0"));
specification.getFunctionBlock("battery").getStatusProperty("remainingCapacity").get().getStereotype(Stereotype.SOURCE).get().setAttributes(createXpathRule("/cap"));
specification.getFunctionBlock("battery").getStatusProperty("value").get().getStereotype(Stereotype.SOURCE).get().setAttributes(createXpathRule("/voltage"));
JSONDeserializer deserializer = new JSONDeserializer();
InfomodelValue testResult = mappingService.runTest(specification, deserializer.deserialize("{\"cap\": 23 ,\"voltage\": 2242.2 }"));
assertEquals(23.0, testResult.get("battery").getStatusProperty("remainingCapacity").get().getValue());
assertEquals(2242.2, testResult.get("battery").getStatusProperty("value").get().getValue());
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class PayloadMappingSpecificationTest method testSaveMappingSpecificationWithChanges.
@Test
public void testSaveMappingSpecificationWithChanges() {
importModel("payloadmapping/org.eclipse.vorto_Voltage_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_Battery_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_MyDevice_1.0.0.infomodel");
final ModelId modelId = ModelId.fromPrettyFormat("org.eclipse.vorto:MyDevice:1.0.0");
IMappingSpecification specification = mappingService.getOrCreateSpecification(modelId);
specification.getFunctionBlock("battery").getStatusProperty("value").get().getStereotype(Stereotype.SOURCE).get().setAttributes(createXpathRule("/voltage"));
mappingService.saveSpecification(specification, createUserContext("alex", "playground"));
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class PayloadMappingSpecificationTest method testSaveMappingSpecificationWithoutChanges.
@Test
public void testSaveMappingSpecificationWithoutChanges() {
importModel("payloadmapping/org.eclipse.vorto_Voltage_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_Battery_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_MyDevice_1.0.0.infomodel");
final ModelId modelId = ModelId.fromPrettyFormat("org.eclipse.vorto:MyDevice:1.0.0");
IMappingSpecification specification = mappingService.getOrCreateSpecification(modelId);
mappingService.saveSpecification(specification, createUserContext("alex", "playground"));
assertNotNull(mappingService.resolveMappingIdForModelId(modelId).get());
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class DefaultPayloadMappingService method getOrCreateSpecification.
@Override
public IMappingSpecification getOrCreateSpecification(ModelId modelId) {
ModelContent modelContent = getModelContent(modelId, createTargetPlatformKey(modelId));
Infomodel infomodel = (Infomodel) modelContent.getModels().get(modelContent.getRoot());
MappingSpecification specification = new MappingSpecification();
specification.setInfoModel(infomodel);
addReferencesRecursive(infomodel, infomodel.getTargetPlatformKey());
return specification;
}
use of org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification in project vorto by eclipse.
the class PayloadMappingSpecificationTest method testCreateSpecification.
@Test
public void testCreateSpecification() {
importModel("payloadmapping/org.eclipse.vorto_Voltage_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_Battery_1.0.0.fbmodel");
importModel("payloadmapping/org.eclipse.vorto_MyDevice_1.0.0.infomodel");
IMappingSpecification specification = mappingService.getOrCreateSpecification(ModelId.fromPrettyFormat("org.eclipse.vorto:MyDevice:1.0.0"));
assertNotNull(specification);
assertNotNull(specification.getInfoModel().getTargetPlatformKey());
}
Aggregations