summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-09-11 10:56:37 +0100
committerMichael Morris <michael.morris@est.tech>2023-09-25 08:50:01 +0000
commitceaf83e0f29c10e4521321abcd6dd17080d2db60 (patch)
tree4ff4ac46184543f6a86f35a1860a9a5b7d6a24e8 /catalog-be/src/test/java
parentda6b4a245482f4eebade8f487fc9d63f456469ab (diff)
Support setting interfaces on instances
Issue-ID: SDC-4620 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I4f78eb5e017e79120d61870ecc3b7268f83b4206
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java121
1 files changed, 121 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java
index b3f6024a9b..1dd7f40730 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInterfaceOperationBusinessLogicTest.java
@@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import fj.data.Either;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -418,6 +419,126 @@ class ComponentInterfaceOperationBusinessLogicTest extends BaseBusinessLogicMock
assertThat(result).isPresent();
}
+ @Test
+ void createComponentInstanceInterfaceOperationTest() throws BusinessLogicException {
+ final String componentId = component.getUniqueId();
+ final String componentInstanceId = componentInstance.getUniqueId();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ final Map<String, OperationDataDefinition> operations = new HashMap<>();
+ final OperationDataDefinition operationDataDefinition = new OperationDataDefinition();
+ operationDataDefinition.setUniqueId(UUID.randomUUID().toString());
+ final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
+ artifactDataDefinition.setArtifactName("EO Implementation info");
+ operationDataDefinition.setImplementation(artifactDataDefinition);
+ operations.put("configure", operationDataDefinition);
+ interfaceDefinition.setOperations(operations );
+
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = new HashMap<>();
+ componentInstancesInterfacesMap.put(componentInstanceId, new ArrayList<>());
+ componentInstance.setInterfaces(
+ (Map<String, Object>) new HashMap<>().put(componentInstanceId, interfaceDefinition));
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
+ when(componentValidations.getComponentInstance(component, componentInstanceId))
+ .thenReturn(Optional.of(componentInstance));
+ when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceInterfaces(component, componentInstanceId))
+ .thenReturn(StorageOperationStatus.OK);
+ when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+
+ final Optional<ComponentInstance> result = componentInterfaceOperationBusinessLogic
+ .createComponentInstanceInterfaceOperation(componentId, componentInstanceId, interfaceDefinition,
+ ComponentTypeEnum.SERVICE, new Wrapper<>(), true);
+ assertThat(result).isPresent();
+ }
+
+ @Test
+ void createComponentInstanceInterfaceOperationTestUpdateFail() throws BusinessLogicException {
+ final String componentId = component.getUniqueId();
+ final String componentInstanceId = componentInstance.getUniqueId();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+ final Map<String, OperationDataDefinition> operations = new HashMap<>();
+ final OperationDataDefinition operationDataDefinition = new OperationDataDefinition();
+ operationDataDefinition.setUniqueId(UUID.randomUUID().toString());
+ final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
+ artifactDataDefinition.setArtifactName("EO Implementation info");
+ operationDataDefinition.setImplementation(artifactDataDefinition);
+ operations.put("configure", operationDataDefinition);
+ interfaceDefinition.setOperations(operations );
+
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = new HashMap<>();
+ componentInstancesInterfacesMap.put(componentInstanceId, new ArrayList<>());
+ componentInstance.setInterfaces(
+ (Map<String, Object>) new HashMap<>().put(componentInstanceId, interfaceDefinition));
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
+ when(componentValidations.getComponentInstance(component, componentInstanceId))
+ .thenReturn(Optional.of(componentInstance));
+ when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacade.updateComponentInstanceInterfaces(component, componentInstanceId))
+ .thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+
+ final Optional<ComponentInstance> result = componentInterfaceOperationBusinessLogic
+ .createComponentInstanceInterfaceOperation(componentId, componentInstanceId, interfaceDefinition,
+ ComponentTypeEnum.SERVICE, new Wrapper<>(), true);
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ void createComponentInstanceInterfaceOperationTestNoInstances() throws BusinessLogicException {
+ final String componentId = component.getUniqueId();
+ final String componentInstanceId = componentInstance.getUniqueId();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
+
+ final Optional<ComponentInstance> result = componentInterfaceOperationBusinessLogic
+ .createComponentInstanceInterfaceOperation(componentId, componentInstanceId, interfaceDefinition,
+ ComponentTypeEnum.SERVICE, new Wrapper<>(), true);
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ void createComponentInstanceInterfaceOperationTestNoOperations() throws BusinessLogicException {
+ final String componentId = component.getUniqueId();
+ final String componentInstanceId = componentInstance.getUniqueId();
+ final InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
+ interfaceDefinition.setType("tosca.interfaces.node.lifecycle.Standard");
+
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = new HashMap<>();
+ componentInstancesInterfacesMap.put(componentInstanceId, new ArrayList<>());
+ componentInstance.setInterfaces(
+ (Map<String, Object>) new HashMap<>().put(componentInstanceId, interfaceDefinition));
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+
+ when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(component));
+ when(componentValidations.getComponentInstance(component, componentInstanceId))
+ .thenReturn(Optional.of(componentInstance));
+
+ final Optional<ComponentInstance> result = componentInterfaceOperationBusinessLogic
+ .createComponentInstanceInterfaceOperation(componentId, componentInstanceId, interfaceDefinition,
+ ComponentTypeEnum.SERVICE, new Wrapper<>(), true);
+ assertThat(result).isEmpty();
+ }
+
private void initComponentData() {
try {
component = new Service();