diff options
author | vasraz <vasyl.razinkov@est.tech> | 2023-09-22 14:51:31 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-09-25 11:03:32 +0000 |
commit | f4668df71072c8ecd4b9d05423006265b36a6ef7 (patch) | |
tree | 91c147e039b45b91e65eecea174f94a3b96ad27d /catalog-be/src/test/java/org | |
parent | ceaf83e0f29c10e4521321abcd6dd17080d2db60 (diff) |
Fix 'Substitution Node not updated during import'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I3b99e4c60a5971916ed593b8d4161da58ddab6d6
Issue-ID: SDC-4633
Diffstat (limited to 'catalog-be/src/test/java/org')
2 files changed, 37 insertions, 18 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java index 0d6922e3f2..d64aaf8cd0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java @@ -477,7 +477,7 @@ class ResourceImportManagerTest { NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList(); List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>(); Map<String, Object> allTypesToCreate = new HashMap<>(); - ServiceCsarInfo csarInfo= getCsarInfo(); + ServiceCsarInfo csarInfo = getCsarInfo(); List<NodeTypeDefinition> nodeTypesToCreate = csarInfo.getNodeTypesUsed(); nodeTypesToCreate.stream().forEach(nodeType -> { allTypesToCreate.put(nodeType.getMappedNodeType().getKey(), nodeType.getMappedNodeType().getValue()); @@ -487,15 +487,26 @@ class ResourceImportManagerTest { when(toscaOperationFacade.getLatestByName(any(), any())).thenReturn(Either.left(null)).thenReturn(Either.left(null)); when(toscaOperationFacade.getLatestByToscaResourceName("org.openecomp.resource.VFC-root", "ETSI SOL001 v2.5.1")) - .thenReturn(Either.left(null)); - when(resourceBusinessLogic - .createOrUpdateResourceByImport(any(Resource.class), any(User.class), eq(true), eq(true), eq(false), eq(null), eq(null), eq(false))) - .thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)).thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)); + .thenReturn(Either.left(null)); + when(toscaOperationFacade.getLatestByToscaResourceName("tosca.nodes.nfv.NS", "")) + .thenReturn(Either.left(createResourceNS())); + when(toscaOperationFacade.getLatestByToscaResourceName("org.openecomp.service.Etsiwithchild", "")) + .thenReturn(Either.right(null)); + when(resourceBusinessLogic.createOrUpdateResourceByImport(any(Resource.class), any(User.class), eq(true), eq(true), eq(false), eq(null), + eq(null), eq(false))).thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)) + .thenReturn(new ImmutablePair<>(new Resource(), ActionStatus.OK)); + when(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(mock(ResponseFormat.class)); importManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, null, user, "", false, false); verify(janusGraphDao).commit(); } + private Resource createResourceNS() { + Resource ns = new Resource(); + ns.setName("tosca.nodes.nfv.NS"); + return ns; + } + private void setResourceBusinessLogicMock() { when(resourceBusinessLogic.getUserAdmin()).thenReturn(userAdmin); when(resourceBusinessLogic.createOrUpdateResourceByImport(any(Resource.class), any(User.class), anyBoolean(), anyBoolean(), anyBoolean(), @@ -768,7 +779,8 @@ class ResourceImportManagerTest { assertNotNull(mainTemplateService); final String mainTemplateContent = new String(mainTemplateService); - return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false, mock(ModelOperation.class)); + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false, + mock(ModelOperation.class)); } catch (URISyntaxException | ZipException e) { fail(e); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java index fc709ceaea..c6ba0ba9ac 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java @@ -212,11 +212,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString(), any())).thenReturn(csarInfo); when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class))) .thenReturn(Either.left(new HashMap<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>())); - doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic).getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)); + doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic) + .getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)); doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic).getParsedToscaYamlInfo(any(ServiceCsarInfo.class), any(Service.class)); when(serviceBusinessLogic.lockComponentByName(newService.getSystemName(), oldService, CREATE_RESOURCE)).thenReturn(Either.left(true)); when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource())); - when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false, AuditingActionEnum.CREATE_RESOURCE)).thenReturn(newService); + when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false, + AuditingActionEnum.CREATE_RESOURCE)).thenReturn(newService); when(serviceImportParseLogic.createInputsOnService(eq(oldService), anyMap())).thenReturn(newService); Assertions.assertDoesNotThrow(() -> { when(serviceImportParseLogic.createSubstitutionFilterOnService(eq(oldService), any())).thenReturn(newService); @@ -258,14 +260,16 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest properties.add(versionProperty); typeToBeUpdated.setProperties(properties); when(applicationDataTypeCache.get(any(), eq("onap.datatypes.ToscaConceptIdentifier.datatype"))).thenReturn(Either.left(typeToBeUpdated)); - when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn(Either.left(new DataTypeDefinition())); + when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn( + Either.left(new DataTypeDefinition())); - when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn( + Either.right(StorageOperationStatus.NOT_FOUND)); when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.artifacts"))).thenReturn(Either.left(null)); when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces"))).thenReturn(Either.left(new InterfaceDefinition())); - when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces.test"))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - + when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces.test"))).thenReturn( + Either.right(StorageOperationStatus.NOT_FOUND)); when(capabilityTypeOperation.getCapabilityType(anyString())) .thenReturn(Either.left(new CapabilityTypeDefinition())); @@ -273,12 +277,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull())) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull())) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(updatedNodeType, null)).thenReturn(Either.left(resource)); - when(artifactsBusinessLogic.handleDownloadRequestById(resourceUniqueId, artifactUniqueId, user.getUserId(), ComponentTypeEnum.RESOURCE, null, null)) - .thenReturn(resourceTemplate); + when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.service."), isNull())) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(artifactsBusinessLogic.handleDownloadRequestById(resourceUniqueId, artifactUniqueId, user.getUserId(), ComponentTypeEnum.RESOURCE, null, + null)) + .thenReturn(resourceTemplate); when(toscaOperationFacade.updatePropertyOfComponent(eq(oldService), any(PropertyDefinition.class))).thenReturn(Either.left(null)); when(toscaOperationFacade.updateComponentInstancePropsToComponent(anyMap(), anyString())).thenReturn(Either.left(null)); when(groupTypeOperation.getGroupTypeByUid(anyString())).thenReturn(Either.left(new GroupTypeDefinition())); @@ -304,7 +311,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest assertNotNull(yamlMap.get("onap.datatypes.ToscaConceptIdentifier")); ArgumentCaptor<String> artifactTypes = ArgumentCaptor.forClass(String.class); - verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(),isNull(), anyBoolean()); + verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(), isNull(), anyBoolean()); Map<String, Object> artifactTypesMap = new Yaml().load(artifactTypes.getValue()); assertEquals(1, artifactTypesMap.size()); assertNotNull(artifactTypesMap.get("tosca.testartifacts.Name")); @@ -320,7 +327,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest ArgumentCaptor<Map<String, Object>> nodeTypes = ArgumentCaptor.forClass(Map.class); verify(resourceImportManager).importAllNormativeResource(nodeTypes.capture(), any(), any(), any(), any(), - anyBoolean(), anyBoolean()); + anyBoolean(), anyBoolean()); Map<String, Object> nodeTypesMap = nodeTypes.getValue(); Map<String, Object> newUpdatedNodeType = (Map<String, Object>) nodeTypesMap.get(updatedNodeType); assertEquals(8, ((Map<String, Object>) newUpdatedNodeType.get("properties")).size()); |