summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2021-11-03 20:43:16 +0000
committerMichael Morris <michael.morris@est.tech>2021-12-06 14:05:00 +0000
commita7dd2ece847fa88dda4912994f2e5220bd4adb7b (patch)
tree737a199af0cf70b26cb99d696c6c7f0872859f5b /catalog-be/src/test/java/org
parentd5edf5274286e9808dfabf2f49a03a1ba235b70c (diff)
Update import service to import node filter
Issue-ID: SDC-3775 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: Ide75c9319ad321d796a1ead34cbf425ad8de5504
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java51
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java14
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java55
3 files changed, 107 insertions, 13 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
index a5ff6d9ce4..cd708599f5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.impl;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -41,6 +42,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -50,6 +52,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.UserValidations;
@@ -71,6 +74,8 @@ import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -540,6 +545,52 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
}
@Test
+ public void testAssociateNodeFilterToComponentInstance() {
+ CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
+
+ UploadNodeFilterInfo filter = new UploadNodeFilterInfo();
+ UploadNodeFilterPropertyInfo propertyDataDefinition = new UploadNodeFilterPropertyInfo();
+ propertyDataDefinition.setName("order");
+ propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2"));
+ List<UploadNodeFilterPropertyInfo> propertyList = new LinkedList<>();
+ propertyList.add(propertyDataDefinition);
+ filter.setProperties(Collections.singletonList(propertyDataDefinition));
+
+ Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
+ nodeFilterMap.put(componentInstanceId, filter);
+
+ when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition));
+
+ StorageOperationStatus status = componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId, nodeFilterMap);
+ assertEquals(StorageOperationStatus.OK, status);
+ }
+
+ @Test
+ public void testAssociateNodeFilterToComponentInstanceFail() {
+ CINodeFilterDataDefinition ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
+
+ UploadNodeFilterInfo filter = new UploadNodeFilterInfo();
+ UploadNodeFilterPropertyInfo propertyDataDefinition = new UploadNodeFilterPropertyInfo();
+ propertyDataDefinition.setName("order");
+ propertyDataDefinition.setValues(Collections.singletonList("order: {equal: 2"));
+ List<UploadNodeFilterPropertyInfo> propertyList = new LinkedList<>();
+ propertyList.add(propertyDataDefinition);
+ filter.setProperties(Collections.singletonList(propertyDataDefinition));
+
+ Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
+ nodeFilterMap.put(componentInstanceId, filter);
+
+ when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)).thenReturn(Either.left(ciNodeFilterDataDefinition));
+ when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class),
+ any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+
+ Assertions.assertThrows(ComponentException.class, () -> componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(componentId,
+ nodeFilterMap));
+ }
+
+ @Test
public void validateUserTes() {
final String USER_ID = "jh0003";
final User user = new User();
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 ee52431a4f..822fad5f5f 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
@@ -61,6 +61,7 @@ import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -93,6 +94,7 @@ import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadPropInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.UploadResourceInfo;
@@ -848,6 +850,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>();
+ Map<String, UploadNodeFilterInfo> instNodeFilter = new HashMap<>();
Map<String, Resource> originCompMap = new HashMap<>();
originCompMap.put("componentUid", originResource);
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
@@ -857,7 +860,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Assertions.assertNotNull(yamlName);
sIB1.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes.left().value(), instProperties,
instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes,
- originCompMap, instInputs, uploadComponentInstanceInfo);
+ originCompMap, instInputs, instNodeFilter, uploadComponentInstanceInfo);
}
@Test
@@ -874,6 +877,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>();
Map<String, Resource> originCompMap = new HashMap<>();
+ Map<String, UploadNodeFilterInfo> instNodeFilter = new HashMap<>();
originCompMap.put("componentUid", originResource);
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
@@ -882,7 +886,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName,
resource, componentInstancesList, null, instProperties, instCapabilties,
instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap,
- instInputs, uploadComponentInstanceInfo));
+ instInputs, instNodeFilter, uploadComponentInstanceInfo));
}
@Test
@@ -1194,6 +1198,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>();
+ Map<String, UploadNodeFilterInfo> instNodeFilter = new HashMap<>();
Map<String, Resource> originCompMap = new HashMap<>();
originCompMap.put("componentUid", originResource);
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
@@ -1203,7 +1208,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
sIB1.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes.left().value(),
instProperties, instCapabilties, instRequirements, instDeploymentArtifacts,
- instArtifacts, instAttributes, originCompMap, instInputs,
+ instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter,
uploadComponentInstanceInfo);
}
@@ -1220,6 +1225,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>();
+ Map<String, UploadNodeFilterInfo> instNodeFilter = new HashMap<>();
Map<String, Resource> originCompMap = new HashMap<>();
originCompMap.put("componentUid", originResource);
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
@@ -1229,7 +1235,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName,
service, componentInstancesList, null, instProperties, instCapabilties,
instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap,
- instInputs, uploadComponentInstanceInfo));
+ instInputs, instNodeFilter, uploadComponentInstanceInfo));
}
@Test
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 ccc7139fa6..6d9467dd80 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
@@ -24,6 +24,9 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -45,7 +48,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
@@ -55,10 +57,13 @@ import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -84,6 +89,8 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadCapInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
import org.openecomp.sdc.be.model.UploadPropInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.User;
@@ -110,14 +117,15 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
private static final String RESOURCE_SUBCATEGORY = "Router";
- private final ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
- private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- private final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
- private final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
- private final IElementOperation elementDao = Mockito.mock(IElementOperation.class);
- private final IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
- private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
- private final LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class);
+ private final ComponentsUtils componentsUtils = new ComponentsUtils(mock(AuditingManager.class));
+ private final ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
+ private final ServiceBusinessLogic serviceBusinessLogic = mock(ServiceBusinessLogic.class);
+ private final ICapabilityTypeOperation capabilityTypeOperation = mock(ICapabilityTypeOperation.class);
+ private final IElementOperation elementDao = mock(IElementOperation.class);
+ private final IInterfaceLifecycleOperation interfaceTypeOperation = mock(IInterfaceLifecycleOperation.class);
+ private final InputsBusinessLogic inputsBusinessLogic = mock(InputsBusinessLogic.class);
+ private final LifecycleBusinessLogic lifecycleBusinessLogic = mock(LifecycleBusinessLogic.class);
+ private final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic = mock(ComponentNodeFilterBusinessLogic.class);
private ResponseFormatManager responseManager = null;
private User user = null;
@@ -151,6 +159,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
testSubject.setInterfaceTypeOperation(interfaceTypeOperation);
testSubject.setInputsBusinessLogic(inputsBusinessLogic);
testSubject.setLifecycleBusinessLogic(lifecycleBusinessLogic);
+ testSubject.setComponentNodeFilterBusinessLogic(componentNodeFilterBusinessLogic);
}
@Test
@@ -1154,6 +1163,34 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
}
@Test
+ public void testAssociateCINodeFilterToComponent() {
+ String yamlName = "yamlName.yml";
+ Service service = createServiceObject(true);
+ Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
+ nodeFilterMap.put("componentInstanceID", new UploadNodeFilterInfo());
+
+ when(componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(service.getUniqueId(), nodeFilterMap))
+ .thenReturn(StorageOperationStatus.OK);
+
+ testSubject.associateCINodeFilterToComponent(yamlName, service, nodeFilterMap);
+ verify(componentNodeFilterBusinessLogic, times(1)).associateNodeFilterToComponentInstance(service.getUniqueId(),
+ nodeFilterMap);
+ }
+
+ @Test
+ public void testAssociateCINodeFilterToComponentFail() {
+ String yamlName = "yamlName.yml";
+ Service service = createServiceObject(true);
+ Map<String, UploadNodeFilterInfo> nodeFilterMap = new HashMap<>();
+ nodeFilterMap.put("componentInstanceID", new UploadNodeFilterInfo());
+
+ when(componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(service.getUniqueId(), nodeFilterMap))
+ .thenReturn(StorageOperationStatus.NOT_FOUND);
+
+ Assertions.assertThrows(ComponentException.class, () -> testSubject.associateCINodeFilterToComponent(yamlName, service, nodeFilterMap));
+ }
+
+ @Test
void testCreateServiceTransaction() {
Service service = createServiceObject(true);
List<ComponentInstance> list = new ArrayList<>();