From 5e8464585f07210ad4b20ddfee2c23b1cf2d8b2a Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 4 Mar 2020 16:28:05 +0000 Subject: Config. allowed instances in component composition During the creation of Resource and Services components, the allowed types to add in its composition are hard-coded. This change allows those types to be configurable using the configuration.yaml backend file. Change-Id: If48849b57fe5124468db3d55f2f06391348935fb Issue-ID: SDC-3177 Signed-off-by: andre.schmid --- .../impl/ArtifactsBusinessLogicTest.java | 6 +- .../impl/ComponentInstanceBusinessLogicTest.java | 88 +++++++++++++--------- .../servlet/ExternalRefServletTest.java | 5 ++ .../sdc/be/servlets/ArchiveEndpointTest.java | 6 ++ 4 files changed, 68 insertions(+), 37 deletions(-) (limited to 'catalog-be/src/test/java') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java index c51456547c..d6995d1750 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java @@ -1182,7 +1182,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock { assertThat(artifactConfiguration1.getCategories()).contains(ArtifactGroupTypeEnum.INFORMATIONAL); assertThat(artifactConfiguration1.getComponentTypes()).hasSize(1); assertThat(artifactConfiguration1.getComponentTypes()).contains(ComponentType.RESOURCE); - assertThat(artifactConfiguration1.getResourceTypes()).hasSize(7); + assertThat(artifactConfiguration1.getResourceTypes()).hasSize(11); assertThat(artifactConfiguration1.getResourceTypes()) .contains(ResourceTypeEnum.VFC.getValue(), ResourceTypeEnum.CP.getValue(), ResourceTypeEnum.VL.getValue(), ResourceTypeEnum.VF.getValue(), ResourceTypeEnum.VFCMT.getValue(), "Abstract", @@ -1946,8 +1946,8 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock { @Test(expected = ComponentException.class) public void validateDeploymentArtifact_unsupportedResourceType() { final ArtifactDefinition artifactDefinition = new ArtifactDefinition(); - artifactDefinition.setArtifactType(ArtifactTypeEnum.YANG.getType()); - artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL); + artifactDefinition.setArtifactType(ArtifactTypeEnum.ANSIBLE_PLAYBOOK.getType()); + artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); final Resource resourceComponent = new Resource(); resourceComponent.setComponentType(ComponentTypeEnum.RESOURCE); resourceComponent.setResourceType(ResourceTypeEnum.ServiceProxy); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index 8a005ff9aa..127e1d9aba 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -66,7 +66,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.datamodel.utils.ContainerInstanceTypesData; import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition; @@ -102,6 +101,7 @@ import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; +import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; @@ -653,11 +653,11 @@ class ComponentInstanceBusinessLogicTest { createProperties(); createInputs(); createService(); - createResource(); + resource = createResource(); } - private void createResource() { - resource = new Resource(); + private Resource createResource() { + final Resource resource = new Resource(); resource.setUniqueId(COMPONENT_ID); resource.setComponentInstancesRelations(Lists.newArrayList(relation)); resource.setComponentInstances(Lists.newArrayList(toInstance, fromInstance)); @@ -665,6 +665,7 @@ class ComponentInstanceBusinessLogicTest { resource.setRequirements(fromInstance.getRequirements()); resource.setComponentType(ComponentTypeEnum.RESOURCE); resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + return resource; } private void createService() { @@ -879,7 +880,7 @@ class ComponentInstanceBusinessLogicTest { @Test void testValidateParent() { ComponentInstanceBusinessLogic testSubject; - createResource(); + resource = createResource(); String nodeTemplateId = ""; boolean result; @@ -945,7 +946,7 @@ class ComponentInstanceBusinessLogicTest { void testCreateOrUpdatePropertiesValues() { ComponentInstanceBusinessLogic testSubject; ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE; - createResource(); + resource = createResource(); String componentId = resource.getUniqueId(); String resourceInstanceId = ""; List properties = new ArrayList<>(); @@ -979,7 +980,7 @@ class ComponentInstanceBusinessLogicTest { ComponentInstanceBusinessLogic testSubject; ComponentInstanceProperty property = new ComponentInstanceProperty(); String newValue = ""; - createResource(); + resource = createResource(); createInstances(); String capabilityType = ""; String capabilityName = ""; @@ -995,7 +996,7 @@ class ComponentInstanceBusinessLogicTest { void testCreateOrUpdateInstanceInputValues() { ComponentInstanceBusinessLogic testSubject; ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE; - createResource(); + resource = createResource(); String componentId = resource.getUniqueId(); String resourceInstanceId = ""; List inputs = new ArrayList<>(); @@ -1027,7 +1028,7 @@ class ComponentInstanceBusinessLogicTest { void testCreateOrUpdateGroupInstancePropertyValue() { ComponentInstanceBusinessLogic testSubject; ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE; - createResource(); + resource = createResource(); String componentId = resource.getUniqueId(); String resourceInstanceId = ""; String groupInstanceId = ""; @@ -1099,7 +1100,7 @@ class ComponentInstanceBusinessLogicTest { @Test void testGetResourceInstanceById() { ComponentInstanceBusinessLogic testSubject; - createResource(); + resource = createResource(); String instanceId = ""; Either result; @@ -1113,7 +1114,7 @@ class ComponentInstanceBusinessLogicTest { void testUpdateInstanceCapabilityProperties_1() { ComponentInstanceBusinessLogic testSubject; ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE; - createResource(); + resource = createResource(); String containerComponentId = resource.getUniqueId(); String componentInstanceUniqueId = ""; String capabilityType = ""; @@ -1664,7 +1665,7 @@ class ComponentInstanceBusinessLogicTest { when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID))) .thenReturn(Either.left(originComponent)); - ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> { + final ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> { componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci); }); assertThat(e.getActionStatus()).isEqualTo(ActionStatus.INVALID_CONTENT); @@ -1672,9 +1673,9 @@ class ComponentInstanceBusinessLogicTest { @Test void testCreateComponentInstanceFailureCannotContainInstance() { - Pair p = prepareResourcesForCreateComponentInstanceTest(); - ComponentInstance ci = p.getLeft(); - Resource originComponent = p.getRight(); + final Pair p = prepareResourcesForCreateComponentInstanceTest(); + final ComponentInstance ci = p.getLeft(); + final Resource originComponent = p.getRight(); // Stub for getting component when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))) @@ -1682,21 +1683,38 @@ class ComponentInstanceBusinessLogicTest { when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID))) .thenReturn(Either.left(originComponent)); // Assume services cannot contain VF resource - when(containerInstanceTypeData.getServiceContainerList()) - .thenReturn(Collections.singletonList(ResourceTypeEnum.VL)); + when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF))) + .thenReturn(false); - ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> { + ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class, () -> { componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci); }); - assertThat(e.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE); - verify(containerInstanceTypeData, times(1)).getServiceContainerList(); + assertThat(actualException.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE); + verify(containerInstanceTypeData, times(1)).isAllowedForServiceComponent(eq(ResourceTypeEnum.VF)); + + //given + final Resource resource = createResource(); + resource.setResourceType(ResourceTypeEnum.VF); + resource.setLastUpdaterUserId(USER_ID); + //when + when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))) + .thenReturn(Either.left(resource)); + when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID))) + .thenReturn(Either.left(originComponent)); + when(containerInstanceTypeData.isAllowedForResourceComponent(eq(ResourceTypeEnum.VF), eq(ResourceTypeEnum.VF))) + .thenReturn(false); + actualException = assertThrows(ByActionStatusComponentException.class, () -> { + componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME, COMPONENT_ID, USER_ID, ci); + }); + //then + assertThat(actualException.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE); } @Test void testCreateComponentInstanceFailureAddToGraph() { - Pair p = prepareResourcesForCreateComponentInstanceTest(); - ComponentInstance ci = p.getLeft(); - Resource originComponent = p.getRight(); + final Pair p = prepareResourcesForCreateComponentInstanceTest(); + final ComponentInstance ci = p.getLeft(); + final Resource originComponent = p.getRight(); // TODO Refactor createComponentInstance() method and reduce these mocks // not to target the internal details too much @@ -1704,8 +1722,8 @@ class ComponentInstanceBusinessLogicTest { .thenReturn(Either.left(service)); when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID))) .thenReturn(Either.left(originComponent)); - when(containerInstanceTypeData.getServiceContainerList()) - .thenReturn(Collections.singletonList(ResourceTypeEnum.VF)); + when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF))) + .thenReturn(true); Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(ci); when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)) .thenReturn(StorageOperationStatus.OK); @@ -1722,7 +1740,8 @@ class ComponentInstanceBusinessLogicTest { assertThrows(ByResponseFormatComponentException.class, () -> { componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci); }); - verify(containerInstanceTypeData, times(1)).getServiceContainerList(); + verify(containerInstanceTypeData, times(1)) + .isAllowedForServiceComponent(eq(ResourceTypeEnum.VF)); verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(ci); verify(toscaOperationFacade, times(1)) .addComponentInstanceToTopologyTemplate(service, originComponent, ci, false, user); @@ -1731,11 +1750,11 @@ class ComponentInstanceBusinessLogicTest { @Test void testCreateComponentInstanceSuccess() { - Pair p = prepareResourcesForCreateComponentInstanceTest(); - ComponentInstance instanceToBeCreated = p.getLeft(); - Resource originComponent = p.getRight(); + final Pair p = prepareResourcesForCreateComponentInstanceTest(); + final ComponentInstance instanceToBeCreated = p.getLeft(); + final Resource originComponent = p.getRight(); - Service updatedService = new Service(); + final Service updatedService = new Service(); updatedService.setComponentInstances(Collections.singletonList(instanceToBeCreated)); updatedService.setUniqueId(service.getUniqueId()); @@ -1745,8 +1764,8 @@ class ComponentInstanceBusinessLogicTest { .thenReturn(Either.left(service)); when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID))) .thenReturn(Either.left(originComponent)); - when(containerInstanceTypeData.getServiceContainerList()) - .thenReturn(Collections.singletonList(ResourceTypeEnum.VF)); + when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF))) + .thenReturn(true); Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(instanceToBeCreated); when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)) .thenReturn(StorageOperationStatus.OK); @@ -1762,12 +1781,13 @@ class ComponentInstanceBusinessLogicTest { when(graphLockOperation.unlockComponent(COMPONENT_ID, NodeTypeEnum.Service)) .thenReturn(StorageOperationStatus.OK); - ComponentInstance result = componentInstanceBusinessLogic.createComponentInstance( + final ComponentInstance result = componentInstanceBusinessLogic.createComponentInstance( ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, instanceToBeCreated); assertThat(result).isEqualTo(instanceToBeCreated); assertThat(instanceToBeCreated.getComponentVersion()).isEqualTo(originComponent.getVersion()); assertThat(instanceToBeCreated.getIcon()).isEqualTo(originComponent.getIcon()); - verify(containerInstanceTypeData, times(1)).getServiceContainerList(); + verify(containerInstanceTypeData, times(1)) + .isAllowedForServiceComponent(eq(ResourceTypeEnum.VF)); verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(instanceToBeCreated); verify(toscaOperationFacade, times(1)) .addComponentInstanceToTopologyTemplate(service, originComponent, instanceToBeCreated, false, user); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java index bdf986cc07..7482c69c05 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java @@ -52,6 +52,7 @@ import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArchiveOperation; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.CategoryOperation; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ExternalReferencesOperation; @@ -268,6 +269,10 @@ public class ExternalRefServletTest extends JerseyTest { return healingPipelineDao; } + @Bean + ContainerInstanceTypesData containerInstanceTypesData() { + return new ContainerInstanceTypesData(); + } private void initGraphForTest() { if (!setupDone) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java index c670b517ba..009fa82b9e 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java @@ -60,6 +60,7 @@ import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.catalog.CatalogComponent; +import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArchiveOperation; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.CategoryOperation; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.GroupsOperation; @@ -251,6 +252,11 @@ public class ArchiveEndpointTest extends JerseyTest { return HEALING_PIPELINE_DAO; } + @Bean + ContainerInstanceTypesData containerInstanceTypesData() { + return new ContainerInstanceTypesData(); + } + private void initGraphForTest() { //Create Catalog Root catalogVertex = GraphTestUtils.createRootCatalogVertex(janusGraphDao); -- cgit 1.2.3-korg