Search in sources :

Example 36 with FunctionblockModel

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

the class SpecWithBase64Converter method createModel.

@Override
protected void createModel() {
    FunctionblockModel buttonModel = createButtonFb();
    infomodel.getFunctionblocks().add(ModelProperty.Builder("button", buttonModel).build());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel)

Example 37 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockOperationWithObjectTypes.

@Test
public void testConvertFunctionblockOperationWithObjectTypes() {
    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")).operation(Operation.Builder("op").withParam(Param.Builder("p1", enumModel.getId()).build()).build()).operation(Operation.Builder("op2").withResult(new ReturnType(enumModel.getId(), 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).withDependency(enumModel).build(), Optional.empty());
    assertEquals(2, model.getFunctionblock().getOperations().size());
    assertEquals(1, model.getReferences().size());
    org.eclipse.vorto.core.api.model.functionblock.Operation op1 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op")).findAny().get();
    assertEquals(1, op1.getParams().size());
    assertEquals("Unit", ((Enum) ((RefParam) op1.getParams().get(0)).getType()).getName());
    assertEquals(2, ((Enum) ((RefParam) op1.getParams().get(0)).getType()).getEnums().size());
    org.eclipse.vorto.core.api.model.functionblock.Operation op2 = model.getFunctionblock().getOperations().stream().filter(p -> p.getName().equals("op2")).findAny().get();
    assertEquals("Unit", ((Enum) (((ReturnObjectType) op2.getReturnType()).getReturnType())).getName());
    assertEquals(2, ((Enum) (((ReturnObjectType) op2.getReturnType()).getReturnType())).getEnums().size());
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) ReturnType(org.eclipse.vorto.model.ReturnType) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) EnumModel(org.eclipse.vorto.model.EnumModel) Infomodel(org.eclipse.vorto.model.Infomodel) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) Test(org.junit.Test)

Example 38 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithDictionaryTypeWithPrimitiveParameters.

@Test
public void testConvertFunctionblockWithDictionaryTypeWithPrimitiveParameters() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", new DictionaryType(PrimitiveType.STRING, PrimitiveType.INT)).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);
    assertNotNull(((DictionaryPropertyType) model.getFunctionblock().getStatus().getProperties().get(0).getType()).getKeyType() instanceof PrimitivePropertyType);
    assertNotNull(((DictionaryPropertyType) model.getFunctionblock().getStatus().getProperties().get(0).getType()).getValueType() instanceof PrimitivePropertyType);
}
Also used : PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DictionaryType(org.eclipse.vorto.model.DictionaryType) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) Infomodel(org.eclipse.vorto.model.Infomodel) Test(org.junit.Test)

Example 39 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockStatusPropertiesWithoutMultiple.

/*
   * Check whether the multiple keyword is not deserialized when absent
   */
@Test
public void testConvertFunctionblockStatusPropertiesWithoutMultiple() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).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());
    List<Property> propertyList = model.getFunctionblock().getStatus().getProperties();
    boolean isMultiple = false;
    for (Property prop : propertyList) {
        isMultiple = prop.isMultiplicity();
    }
    assertEquals(false, isMultiple);
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty) Test(org.junit.Test)

Example 40 with FunctionblockModel

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

the class ValidationTest method createModel.

private FunctionblockModel createModel(PrimitiveType type) {
    FunctionblockModel fbModel = new FunctionblockModel(ModelId.fromPrettyFormat("default:TestFB:1.0.0"));
    List<ModelProperty> properties = new ArrayList<>();
    properties.add(ModelProperty.createPrimitiveProperty("prop", true, type));
    fbModel.setStatusProperties(properties);
    return fbModel;
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) ModelProperty(org.eclipse.vorto.model.ModelProperty) ArrayList(java.util.ArrayList)

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