From 630e46ef816ea2d16d358ed3fab0d9ebed884c19 Mon Sep 17 00:00:00 2001 From: vasraz Date: Fri, 25 Nov 2022 12:48:58 +0000 Subject: Fix issues while importing a Service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The import service was ignoring the selected model for imported nodes. It was also trying to set a different icon for resources that already exist in the database, creating a validation error. There was also a nullpointer in relation to not found capability. Change-Id: Ifa9320c5554bbf5e8fed0cc2e2dea6b05503d213 Issue-ID: SDC-4266 Signed-off-by: André Schmid Signed-off-by: Vasyl Razinkov --- .../be/components/ResourceImportManagerTest.java | 2 +- .../be/components/csar/ServiceCsarInfoTest.java | 3 +- .../impl/ServiceImportBusinessLogicTest.java | 15 ++-- .../ServiceImportBussinessLogicBaseTestSetup.java | 80 +--------------------- .../impl/ServiceImportParseLogicTest.java | 2 +- .../config/catalog-be/error-configuration.yaml | 8 +++ 6 files changed, 23 insertions(+), 87 deletions(-) (limited to 'catalog-be/src/test') 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 9c583729f0..5c981e3b8b 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 @@ -770,7 +770,7 @@ class ResourceImportManagerTest { assertNotNull(mainTemplateService); final String mainTemplateContent = new String(mainTemplateService); - return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false); } catch (URISyntaxException | ZipException e) { fail(e); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java index add427d164..a51c406be8 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java @@ -62,8 +62,7 @@ class ServiceCsarInfoTest { final File csarFile = new File(ServiceCsarInfoTest.class.getClassLoader().getResource(csarFileName).toURI()); final Map payload = ZipUtils.readZip(csarFile, false); String mainTemplateContent = new String(payload.get(mainTemplateName)); - -return new ServiceCsarInfo(user, CSAR_UUID, payload, SERVICE_NAME, mainTemplateName, mainTemplateContent, true); + return new ServiceCsarInfo(user, CSAR_UUID, payload, SERVICE_NAME, null, mainTemplateName, mainTemplateContent, true); } @SuppressWarnings("unchecked") 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 83bcf81178..dc8e6176b0 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 @@ -192,8 +192,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest String resourceUniqueId = "extcp_resource"; resource.setUniqueId(resourceUniqueId); resource.setToscaArtifacts(toscaArtifacts); + resource.getComponentMetadataDefinition().getMetadataDataDefinition().setState(LifecycleStateEnum.CERTIFIED.name()); + resource.setResourceType(ResourceTypeEnum.VF); + ImmutablePair resourceTemplate = getNodeType(); String updatedNodeType = "org.openecomp.resource.cp.extCP"; + resource.setToscaResourceName(updatedNodeType); newService.setComponentInstancesProperties( Collections.singletonMap(COMPONENT_ID + "." + "zxjTestImportServiceAb", Collections.singletonList(componentInstanceProperty))); @@ -218,7 +222,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(serviceImportParseLogic.getNodeTypesFromTemplate(anyMap())).thenReturn(getNodeTypes()); when(serviceImportParseLogic.createNodeTypeResourceFromYaml(anyString(), any(Map.Entry.class), any(User.class), anyMap(), any(Service.class), anyBoolean(), any(), anyList(), anyBoolean(), any(CsarInfo.class), anyBoolean())).thenReturn( - new ImmutablePair<>(new Resource(), ActionStatus.OK)); + new ImmutablePair<>(resource, ActionStatus.OK)); when(serviceImportParseLogic.getComponentWithInstancesFilter()).thenReturn(new ComponentParametersView()); when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(newService)); when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(new ComponentParametersView()); @@ -270,7 +274,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(toscaOperationFacade.getLatestByToscaResourceName(contains(updatedNodeType), isNull())).thenReturn(Either.left(resource)); + when(toscaOperationFacade.getLatestByToscaResourceName(updatedNodeType, null)).thenReturn(Either.left(resource)); 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)); @@ -1796,12 +1800,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest originResource.setComponentType(ComponentTypeEnum.RESOURCE); originResource.setToscaResourceName("toscaResourceName"); originResource.setResourceType(ResourceTypeEnum.VF); - originResource.setResourceType(ResourceTypeEnum.VF); Map nodeNamespaceMap = new HashMap<>(); nodeNamespaceMap.put("resources", originResource); - when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(originResource)); + when(toscaOperationFacade.getLatestByToscaResourceName(RESOURCE_TOSCA_NAME, null)).thenReturn(Either.left(originResource)); Assertions.assertNotNull( - sIBL.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap)); + sIBL.validateResourceInstanceBeforeCreate(yamlName, null, uploadComponentInstanceInfo, nodeNamespaceMap)); } @Test @@ -2497,7 +2500,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest assertNotNull(mainTemplateService); final String mainTemplateContent = new String(mainTemplateService); - return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false); } catch (URISyntaxException | ZipException e) { fail(e); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java index ecec834599..45e7f4a7ad 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java @@ -30,10 +30,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; @@ -68,7 +66,6 @@ import org.openecomp.sdc.be.components.validation.service.ServiceValidator; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.externalapi.servlet.representation.AbstractResourceInfo; import org.openecomp.sdc.be.externalapi.servlet.representation.AbstractTemplateInfo; @@ -118,15 +115,10 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM protected static final String SERVICE_CATEGORY = "Mobility"; protected static final String INSTANTIATION_TYPE = "A-la-carte"; - protected static final String CERTIFIED_VERSION = "1.0"; - protected static final String UNCERTIFIED_VERSION = "0.2"; protected static final String COMPONENT_ID = "myUniqueId"; protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service"; - protected static final String SERVICE_ROLE = JsonPresentationFields.SERVICE_ROLE.getPresentation(); - protected static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation(); - protected static final String SERVICE_FUNCTION = JsonPresentationFields.SERVICE_FUNCTION.getPresentation(); private static final String RESOURCE_NAME = "My-Resource_Name with space"; - private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name"; + protected static final String RESOURCE_TOSCA_NAME = "org.openecomp.resource.cp.extCP"; private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; private static final String RESOURCE_SUBCATEGORY = "Router"; @@ -374,74 +366,8 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM protected UploadComponentInstanceInfo getUploadComponentInstanceInfo() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); - uploadComponentInstanceInfo.setType("My-Resource_Tosca_Name"); - Collection directives = new Collection() { - @Override - public int size() { - return 0; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public boolean contains(Object o) { - return false; - } - - @Override - public Iterator iterator() { - return null; - } - - @Override - public Object[] toArray() { - return new Object[0]; - } - - @Override - public T[] toArray(T[] ts) { - return null; - } - - @Override - public boolean add(String s) { - return false; - } - - @Override - public boolean remove(Object o) { - return false; - } - - @Override - public boolean containsAll(Collection collection) { - return false; - } - - @Override - public boolean addAll(Collection collection) { - return false; - } - - @Override - public boolean removeAll(Collection collection) { - return false; - } - - @Override - public boolean retainAll(Collection collection) { - return false; - } - - @Override - public void clear() { - - } - }; - uploadComponentInstanceInfo.setDirectives(directives); + uploadComponentInstanceInfo.setType(RESOURCE_TOSCA_NAME); + uploadComponentInstanceInfo.setDirectives(new ArrayList<>()); UploadNodeFilterInfo uploadNodeFilterInfo = new UploadNodeFilterInfo(); Map> requirements = new HashMap<>(); List uploadReqInfoList = new ArrayList<>(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java index b3154efe62..66ba214ae3 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java @@ -2091,7 +2091,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet assertNotNull(mainTemplateService); final String mainTemplateContent = new String(mainTemplateService); - return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false); } catch (URISyntaxException | ZipException e) { fail(e); } diff --git a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml index ad40131f28..b3df674126 100644 --- a/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml +++ b/catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml @@ -2841,3 +2841,11 @@ errors: message: "An unexpected error occurred while %1." messageId: "SVC4013" + + + # %1 - The capability name + # %2 - The model + CAPABILITY_NOT_FOUND: + code: 404 + message: "Capability '%1' was not found for model '%2'." + messageId: "SVC4014" \ No newline at end of file -- cgit 1.2.3-korg