ModelContentToEcoreConverter implements IModelConverter<ModelContent, Model> { private InformationModel convertInformationModel(Infomodel model, ModelContent context) { InformationModelBuilder builder = BuilderUtils.newInformationModel(new ModelId(ModelType.InformationModel, model.getId().getName(), model.getId().getNamespace(), model.getId().getVersion())); builder.withCategory(model.getCategory()); builder.withDescription(model.getDescription()); builder.withDisplayName(model.getDisplayName()); builder.withVortolang(model.getVortolang()); for (ModelProperty property : model.getFunctionblocks()) { FunctionblockModel fbModel = (FunctionblockModel) context.getModels() .get((org.eclipse.vorto.model.ModelId) property.getType()); org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel convertedFb = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) convertFunctionblock( fbModel, context); builder.withReference(ModelIdFactory.newInstance(convertedFb)); builder.withFunctionBlock(convertedFb, property.getName(), property.getDescription(), property.isMandatory()); } return builder.build(); }  @Override Model convert(ModelContent source, Optional<String> platformKey);  }
@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); }