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());
}
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());
}
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);
}
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);
}
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;
}
Aggregations