use of org.eclipse.winery.model.tosca.TPolicyTemplate in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final Definitions definitions = createWrapperDefinitions(id);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.model.tosca.TPolicyTemplate in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(PolicyTemplateId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
final TPolicyTemplate element = this.getElement(id);
ids.add(new PolicyTypeId(element.getType()));
return ids;
}
use of org.eclipse.winery.model.tosca.TPolicyTemplate in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method initializePropertiesDoesNothingInTheCaseOfXmlElemenetPropperties.
@Test
public void initializePropertiesDoesNothingInTheCaseOfXmlElemenetPropperties() throws Exception {
this.setRevisionTo("origin/plain");
PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://www.example.org", "policytemplate", false);
// create prepared policy template
final IRepository repository = RepositoryFactory.getRepository();
final Definitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repository, policyTemplateId);
final TPolicyTemplate policyTemplate = (TPolicyTemplate) definitions.getElement();
QName policyTypeQName = new QName("http://plain.winery.opentosca.org/policytypes", "PolicyTypeWithXmlElementProperty");
policyTemplate.setType(policyTypeQName);
BackendUtils.initializeProperties(repository, policyTemplate);
Assert.assertNull(policyTemplate.getProperties());
}
use of org.eclipse.winery.model.tosca.TPolicyTemplate in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method initializePropertiesGeneratesCorrectKvProperties.
@Test
public void initializePropertiesGeneratesCorrectKvProperties() throws Exception {
this.setRevisionTo("origin/plain");
PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://www.example.org", "policytemplate", false);
// create prepared policy template
final IRepository repository = RepositoryFactory.getRepository();
final Definitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repository, policyTemplateId);
final TPolicyTemplate policyTemplate = (TPolicyTemplate) definitions.getElement();
QName policyTypeQName = new QName("http://plain.winery.opentosca.org/policytypes", "PolicyTypeWithTwoKvProperties");
policyTemplate.setType(policyTypeQName);
BackendUtils.initializeProperties(repository, policyTemplate);
Assert.assertNotNull(policyTemplate.getProperties());
LinkedHashMap<String, String> kvProperties = policyTemplate.getProperties().getKVProperties();
LinkedHashMap<String, String> expectedPropertyKVS = new LinkedHashMap<>();
expectedPropertyKVS.put("key1", "");
expectedPropertyKVS.put("key2", "");
Assert.assertEquals(expectedPropertyKVS, kvProperties);
}
Aggregations