summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-07-22 13:07:27 +0100
committerMichael Morris <michael.morris@est.tech>2023-07-28 13:00:55 +0000
commit216ea4998de9ae4ee603d7f8f5f6725b218ca710 (patch)
tree891920a916a6301836061e29f6154b5973431f99 /catalog-be/src/test
parent47317bba3db6c7426a5461aa6c20716bf7db8c96 (diff)
Implement 'Update Service by importing Tosca Template'-story
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Ia2842c49cc81eb30174d783805261d0e73835e48 Issue-ID: SDC-4576
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java14
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java19
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java72
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplateTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java4
-rw-r--r--catalog-be/src/test/resources/config/catalog-be/error-configuration.yaml15
7 files changed, 57 insertions, 73 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
index fec288a953..44c1382baf 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
@@ -116,7 +116,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
.thenReturn(Optional.of(vendorSoftwareProduct));
// when
- final CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID);
+ final CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID, null);
// then
assertNotNull(csarInfo);
@@ -144,7 +144,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenReturn(Optional.of(vendorSoftwareProduct));
final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
- () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID, null));
assertEquals(ActionStatus.VSP_MODEL_NOT_ALLOWED, actualException.getActionStatus());
assertEquals(2, actualException.getParams().length);
assertEquals(resource.getModel(), actualException.getParams()[0]);
@@ -166,7 +166,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenReturn(Optional.of(vendorSoftwareProduct));
final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
- () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID, null));
assertEquals(ActionStatus.VSP_MODEL_NOT_ALLOWED, actualException.getActionStatus());
assertEquals(2, actualException.getParams().length);
assertEquals(resource.getModel(), actualException.getParams()[0]);
@@ -187,7 +187,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenReturn(Optional.of(vendorSoftwareProduct));
final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
- () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID, null));
assertEquals(ActionStatus.VSP_MODEL_NOT_ALLOWED, actualException.getActionStatus());
assertEquals(2, actualException.getParams().length);
assertEquals("SDC AID", actualException.getParams()[0]);
@@ -207,7 +207,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
when(csarOperation.findVsp(resource.getCsarUUID(), resource.getCsarVersionId(), user)).thenThrow(new RuntimeException());
final ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class,
- () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID, null));
assertEquals(ActionStatus.VSP_FIND_ERROR, actualException.getActionStatus());
assertEquals(2, actualException.getParams().length);
assertEquals(resource.getCsarUUID(), actualException.getParams()[0]);
@@ -223,7 +223,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
Map<String, byte[]> payload = loadPayload(PAYLOAD_NAME);
// when
- CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, payload, CSAR_UUID);
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, payload, CSAR_UUID, null);
// then
assertNotNull(csarInfo);
@@ -246,7 +246,7 @@ class CsarBusinessLogicTest extends BaseBusinessLogicMock {
when(csarOperation.findVspLatestPackage(anyString(), any(User.class))).thenReturn(Either.left(csar_data));
// when/then
- assertThrows(ComponentException.class, () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID));
+ assertThrows(ComponentException.class, () -> csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID, null));
}
@Test
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 4b7e42b737..e74160e69c 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
@@ -209,7 +209,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
.thenReturn(Either.left(newService));
when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
ServiceCsarInfo csarInfo = getCsarInfo();
- when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(csarInfo);
+ 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));
@@ -217,7 +217,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
// .thenReturn(getParsedToscaYamlInfo());
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)).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);
@@ -350,7 +350,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceBusinessLogic.validateServiceBeforeCreate(any(Service.class), any(User.class), any(AuditingActionEnum.class)))
.thenReturn(Either.left(newService));
when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
- when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(getCsarInfo());
+ when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString(), any())).thenReturn(getCsarInfo());
when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class)))
.thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), anyString(),
@@ -370,11 +370,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
new HashedMap();
when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class),
- any(Map.class), anyString())).thenReturn(csarInfo);
+ any(Map.class), anyString(), any())).thenReturn(csarInfo);
when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class),
any(Service.class))).thenReturn(Either.left(map));
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromCsar(oldService,
- user, payload, csarUUID));
+ user, payload, csarUUID, null));
}
@Test
@@ -400,7 +400,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromYaml(oldService,
topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo,
- nodeTypesArtifactsToCreate, false, true, nodeName, user.getUserId()));
+ nodeTypesArtifactsToCreate, false, true, nodeName, user.getUserId(), null));
}
@Test
@@ -419,7 +419,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
- false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId()));
+ false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId(), null));
}
@Test
@@ -438,7 +438,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
- false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId()));
+ false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId(), null));
}
@Test
@@ -678,14 +678,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
preparedService.setDeploymentArtifacts(deploymentArtifacts);
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
- NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToHandle);
when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(createServiceObject(true)));
when(csarArtifactsAndGroupsBusinessLogic.updateResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class),
anyString(), anyString(), anyList(), anyBoolean(), anyBoolean())).thenReturn(Either.left(preparedService));
Assertions.assertNotNull(
sIBL.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
- preparedService, nodeTypeInfoToUpdateArtifacts, true, true));
+ preparedService, true, true));
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
index 1b5b7d8a7e..b0bb8a8571 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
@@ -17,73 +17,34 @@
package org.openecomp.sdc.be.components.impl;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
-import org.mockito.Mockito;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadServiceInfo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
@ExtendWith(MockitoExtension.class)
class ServiceImportManagerTest {
- private final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
+ @Mock
+ private ServiceBusinessLogic serviceBusinessLogic;
+
@InjectMocks
private ServiceImportManager serviceImportManager;
@BeforeEach
public void setup() {
- serviceImportManager = new ServiceImportManager();
- }
-
- private ServiceImportManager createTestSubject() {
- return new ServiceImportManager();
- }
-
- @Test
- void testGetServiceImportBusinessLogic() {
- ServiceImportManager testSubject;
- ServiceImportBusinessLogic result;
-
- testSubject = createTestSubject();
- result = testSubject.getServiceImportBusinessLogic();
- assertNull(result);
- }
-
- @Test
- void testSetServiceImportBusinessLogic() {
- ServiceImportManager testSubject;
- ServiceImportBusinessLogic serviceImportBusinessLogic = null;
-
- testSubject = createTestSubject();
- testSubject.setServiceImportBusinessLogic(serviceImportBusinessLogic);
- assertNotNull(testSubject);
- }
-
- @Test
- void testGetServiceBusinessLogic() {
- ServiceImportManager testSubject;
- ServiceBusinessLogic result;
-
- testSubject = createTestSubject();
- result = testSubject.getServiceBusinessLogic();
- assertNull(result);
- }
-
- @Test
- void testSetServiceBusinessLogic() {
- ServiceImportManager testSubject;
- ServiceBusinessLogic serviceBusinessLogic = null;
-
- testSubject = createTestSubject();
- testSubject.setServiceBusinessLogic(serviceBusinessLogic);
- assertNotNull(testSubject);
+ MockitoAnnotations.openMocks(this);
+ serviceImportManager = new ServiceImportManager(serviceBusinessLogic, null);
}
@Test
@@ -92,8 +53,17 @@ class ServiceImportManagerTest {
serviceMetaData.setDescription("Description");
serviceMetaData.setVendorName("VendorName");
serviceMetaData.setVendorRelease("VendorRelease");
+ serviceMetaData.setDerivedFromGenericVersion("derivedFromGenericVersion");
Service service = new Service();
service.setName("service");
serviceImportManager.populateServiceMetadata(serviceMetaData, service);
+ assertEquals("derivedFromGenericVersion", service.getDerivedFromGenericVersion());
+ }
+
+ @Test
+ void testIsServiceExist() {
+ when(serviceBusinessLogic.isServiceExist(anyString())).thenReturn(false);
+ boolean result = serviceImportManager.isServiceExist("no exist");
+ assertFalse(result);
}
}
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 4f90947bd2..945c2617a8 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
@@ -1250,7 +1250,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
when(toscaOperationFacade.createToscaComponent(any(Service.class))).thenReturn(Either.left(service));
- Assertions.assertThrows(NullPointerException.class, () -> testSubject.createServiceTransaction(service, user, true));
+ Assertions.assertThrows(NullPointerException.class, () -> testSubject.createServiceTransaction(service, user, true, null));
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplateTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplateTest.java
index e8f53f015c..5585181bc3 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplateTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplateTest.java
@@ -124,7 +124,7 @@ public class ToscaNodeTemplateTest {
@Test
public void testGetMetadata() throws Exception {
ToscaNodeTemplate testSubject;
- Map<String, String> result;
+ Map<String, Object> result;
// default test
testSubject = createTestSubject();
@@ -135,7 +135,7 @@ public class ToscaNodeTemplateTest {
@Test
public void testSetMetadata() throws Exception {
ToscaNodeTemplate testSubject;
- Map<String, String> metadata = null;
+ Map<String, Object> metadata = null;
// default test
testSubject = createTestSubject();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java
index 13bb415bc0..362a42ab86 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateTest.java
@@ -104,7 +104,7 @@ public class ToscaTemplateTest {
@Test
public void testGetMetadata() throws Exception {
ToscaTemplate testSubject;
- Map<String, String> result;
+ Map<String, Object> result;
// default test
testSubject = createTestSubject();
@@ -115,7 +115,7 @@ public class ToscaTemplateTest {
@Test
public void testSetMetadata() throws Exception {
ToscaTemplate testSubject;
- Map<String, String> metadata = null;
+ Map<String, Object> metadata = null;
// default test
testSubject = createTestSubject();
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 0937c1d58e..11ce71d488 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
@@ -2881,3 +2881,18 @@ errors:
message: "Error: Uploaded YAML file is invalid.\n%1",
messageId: "SVC4010"
}
+
+ #---------SVC4019-----------------------------
+ # %1 - metadata property name
+ UNCHANGEABLE_PROPERTY_ERROR: {
+ code: 402,
+ message: "Error: '%1' cannot change",
+ messageId: "SVC4019"
+ }
+
+ #---------SVC4020-----------------------------
+ MISSING_SERVICE_METADATA: {
+ code: 402,
+ message: "Error: Missing metadata in Service",
+ messageId: "SVC4020"
+ }