Search in sources :

Example 6 with IMappingSpecification

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

Example 7 with IMappingSpecification

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

Example 8 with IMappingSpecification

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

Example 9 with IMappingSpecification

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

Example 10 with IMappingSpecification

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