Search in sources :

Example 6 with FunctionblockModel

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

the class SpecWithNestedEntity method createModel.

@Override
protected void createModel() {
    EntityModel sensorValueEntity = EntityModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:SensorValue:1.0.0")).property(ModelProperty.Builder("value", PrimitiveType.FLOAT).withXPathStereotype("/temperature", "iotbutton").build()).build();
    FunctionblockModel temperatureModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.Builder("value", sensorValueEntity).build()).build();
    infomodel.getFunctionblocks().add(ModelProperty.Builder("outdoorTemperature", temperatureModel).build());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) EntityModel(org.eclipse.vorto.model.EntityModel)

Example 7 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockOperationWithPrimitiveTypes.

@Test
public void testConvertFunctionblockOperationWithPrimitiveTypes() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).operation(Operation.Builder("op").description("some operation").withParam(Param.Builder("p1", PrimitiveType.INT).build()).build()).operation(Operation.Builder("op2").withResult(new ReturnType(PrimitiveType.BOOLEAN, false)).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
    assertEquals(2, model.getFunctionblock().getOperations().size());
    org.eclipse.vorto.core.api.model.functionblock.Operation op1 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op")).findAny().get();
    assertEquals("some operation", op1.getDescription());
    assertEquals(1, op1.getParams().size());
    assertEquals("p1", op1.getParams().get(0).getName());
    assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.INT, ((PrimitiveParam) op1.getParams().get(0)).getType());
    org.eclipse.vorto.core.api.model.functionblock.Operation op2 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op2")).findAny().get();
    assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.BOOLEAN, ((ReturnPrimitiveType) op2.getReturnType()).getReturnType());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) ReturnType(org.eclipse.vorto.model.ReturnType) Test(org.junit.Test)

Example 8 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithEvents.

@Test
public void testConvertFunctionblockWithEvents() {
    EnumModel enumModel = EnumModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Unit:1.0.0")).literal("celcius", null).literal("kg", null).build();
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).event(ModelEvent.Builder("Exceeded").withProperty(ModelProperty.Builder("unit", enumModel.getId()).build()).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).withDependency(enumModel).build(), Optional.empty());
    assertEquals(1, model.getReferences().size());
    assertEquals(1, model.getFunctionblock().getEvents().size());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) EnumModel(org.eclipse.vorto.model.EnumModel) Infomodel(org.eclipse.vorto.model.Infomodel) Test(org.junit.Test)

Example 9 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockBasic.

@Test
public void testConvertFunctionblockBasic() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
    assertEquals(fbModel.getId().getNamespace(), model.getNamespace());
    assertEquals(fbModel.getId().getName(), model.getName());
    assertEquals(fbModel.getId().getVersion(), model.getVersion());
    assertEquals(fbModel.getDescription(), model.getDescription());
    assertEquals(fbModel.getDisplayName(), model.getDisplayname());
    assertEquals(fbModel.getCategory(), model.getCategory());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) Test(org.junit.Test)

Example 10 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithDictionaryTypeWithoutParameters.

@Test
public void testConvertFunctionblockWithDictionaryTypeWithoutParameters() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", new DictionaryType(null, null)).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
    assertEquals(1, model.getFunctionblock().getStatus().getProperties().size());
    assertTrue(model.getFunctionblock().getStatus().getProperties().get(0).getType() instanceof DictionaryPropertyType);
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Infomodel(org.eclipse.vorto.model.Infomodel) DictionaryType(org.eclipse.vorto.model.DictionaryType) Test(org.junit.Test)

Aggregations

FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)61 ModelProperty (org.eclipse.vorto.model.ModelProperty)32 Infomodel (org.eclipse.vorto.model.Infomodel)17 Test (org.junit.Test)17 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)6 EntityModel (org.eclipse.vorto.model.EntityModel)5 EnumModel (org.eclipse.vorto.model.EnumModel)5 ArrayList (java.util.ArrayList)3 DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)3 Property (org.eclipse.vorto.core.api.model.datatype.Property)3 DictionaryType (org.eclipse.vorto.model.DictionaryType)3 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)3 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)2 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)2 InformationModelBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.InformationModelBuilder)2 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)2 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)2 MappingException (org.eclipse.vorto.mapping.engine.MappingException)2 Constraint (org.eclipse.vorto.model.Constraint)2 ModelContent (org.eclipse.vorto.model.ModelContent)2