Search in sources :

Example 11 with Infomodel

use of org.eclipse.vorto.model.Infomodel in project vorto by eclipse.

the class ModelContentToEcoreConverterTest method testConvertInformationModel.

@Test
public void testConvertInformationModel() throws Exception {
    FunctionblockModel fbModel1 = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).build();
    FunctionblockModel fbModel2 = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).build();
    Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:TestDevice:1.0.0")).withProperty(ModelProperty.Builder("sensor", fbModel1.getId()).build()).withProperty(ModelProperty.Builder("temperature", fbModel2.getId()).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.informationmodel.InformationModel model = (org.eclipse.vorto.core.api.model.informationmodel.InformationModel) converter.convert(ModelContent.Builder(infomodel).withDependency(fbModel1).withDependency(fbModel2).build(), Optional.empty());
    assertEquals(infomodel.getId().getNamespace(), model.getNamespace());
    assertEquals(infomodel.getId().getName(), model.getName());
    assertEquals(infomodel.getId().getVersion(), model.getVersion());
    assertEquals(infomodel.getDescription(), model.getDescription());
    assertEquals(infomodel.getDisplayName(), model.getDisplayname());
    assertEquals(infomodel.getCategory(), model.getCategory());
    assertEquals(2, model.getReferences().size());
    FunctionblockProperty property = model.getProperties().stream().filter(p -> p.getName().equals("sensor")).findAny().get();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel fb = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) property.getType();
    assertEquals(fbModel1.getId().getName(), fb.getName());
    assertEquals(fbModel1.getId().getNamespace(), fb.getNamespace());
    assertEquals(fbModel1.getId().getVersion(), fb.getVersion());
    assertTrue(property.eContainer() instanceof InformationModel);
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Infomodel(org.eclipse.vorto.model.Infomodel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Test(org.junit.Test)

Aggregations

Infomodel (org.eclipse.vorto.model.Infomodel)11 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)7 Test (org.junit.Test)6 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)5 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)5 ModelId (org.eclipse.vorto.model.ModelId)3 ModelProperty (org.eclipse.vorto.model.ModelProperty)3 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)2 MappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.MappingSpecification)2 ModelContent (org.eclipse.vorto.model.ModelContent)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Base64 (java.util.Base64)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 Logger (org.apache.log4j.Logger)1 InformationModelBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.InformationModelBuilder)1 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)1 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1