aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-11-25 12:48:58 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-11-25 12:51:37 +0000
commit630e46ef816ea2d16d358ed3fab0d9ebed884c19 (patch)
treebe58e61d4fd5d0cae30ea65e3f53c339043b6ba7 /catalog-be/src/test/java/org
parent5e71c18416adc5c136ea9053a6bbac819da18c60 (diff)
Fix issues while importing a Service
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 <andre.schmid@est.tech> Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ResourceImportManagerTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfoTest.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java80
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java2
5 files changed, 15 insertions, 87 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 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<String, byte[]> 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<String, byte[]> 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<String, Resource> 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<String> directives = new Collection<String>() {
- @Override
- public int size() {
- return 0;
- }
-
- @Override
- public boolean isEmpty() {
- return false;
- }
-
- @Override
- public boolean contains(Object o) {
- return false;
- }
-
- @Override
- public Iterator<String> iterator() {
- return null;
- }
-
- @Override
- public Object[] toArray() {
- return new Object[0];
- }
-
- @Override
- public <T> 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<? extends String> 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<String, List<UploadReqInfo>> requirements = new HashMap<>();
List<UploadReqInfo> 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);
}