From 1ecdbf74427467327de0b1e11cd0a839d6dc05bd Mon Sep 17 00:00:00 2001 From: priyanshu Date: Mon, 6 Aug 2018 14:31:02 +0530 Subject: Interface operations Model update 1. Interface operations Model update 2. Removed unnecessary dependencies on resource 3. Fixed the broken code after merge Change-Id: I2b6381493530f1d61f0803ee1d1d688648356f73 Issue-ID: SDC-1535 Signed-off-by: priyanshu --- .../impl/InterfaceOperationBusinessLogicTest.java | 89 +++++----------------- .../test/utils/InterfaceOperationTestUtils.java | 26 ++++--- 2 files changed, 33 insertions(+), 82 deletions(-) (limited to 'catalog-be/src/test') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index dd67921970..b9e0b594ea 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -70,10 +70,10 @@ public class InterfaceOperationBusinessLogicTest { public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; public static final String RESOURCE_SUBCATEGORY = "Router"; - private String resourceId = "resourceId1"; private String operationId = "uniqueId1"; Resource resourceUpdate; + Operation operation; public static final String RESOURCE_NAME = "My-Resource_Name with space"; @@ -102,7 +102,6 @@ public class InterfaceOperationBusinessLogicTest { ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(); private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class); - @InjectMocks InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic(); @@ -167,12 +166,14 @@ public class InterfaceOperationBusinessLogicTest { when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes)); //InterfaceOperation - when(operationValidator.validateInterfaceOperations(anyCollection(), anyString(), anyBoolean())).thenReturn(Either.left(true)); when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); - when(interfaceOperation.deleteInterface(anyObject(), anyObject())).thenReturn(Either.left(new HashSet<>())); - when(interfaceOperation.deleteInterface(any(),any())).thenReturn(Either.left(new HashSet<>())); + when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.getInterfaceOperation(anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); @@ -191,13 +192,11 @@ public class InterfaceOperationBusinessLogicTest { bl.setUserValidations(userValidations); bl.setInterfaceOperation(interfaceOperation); bl.setInterfaceOperationValidation(operationValidator); - bl.setArtifactCassandraDao(artifactCassandraDao); Resource resourceCsar = createResourceObjectCsar(true); setCanWorkOnResource(resourceCsar); Either oldResourceRes = Either.left(resourceCsar); when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes); responseManager = ResponseFormatManager.getInstance(); - } @Test @@ -206,30 +205,24 @@ public class InterfaceOperationBusinessLogicTest { resource.setComponentType(ComponentTypeEnum.RESOURCE); validateUserRoles(Role.ADMIN, Role.DESIGNER); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - resourceUpdate = setUpResourceMock(); - Either interfaceOperation = bl.createInterfaceOperation(resourceId, resourceUpdate, user, true); + operation = InterfaceOperationTestUtils.createMockOperation(); + Either interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true); Assert.assertTrue(interfaceOperation.isLeft()); - Map interfaceOperationsFromInterfaces = InterfaceUtils - .getInterfaceOperationsFromInterfaces(interfaceOperation.left().value().getInterfaces(), - interfaceOperation.left().value()); - for(Operation operation : interfaceOperationsFromInterfaces.values()) { - Assert.assertNotNull(operation.getWorkflowId()); - Assert.assertNotNull(operation.getWorkflowVersionId()); - } + Assert.assertNotNull(interfaceOperation.left().value().getWorkflowId()); + Assert.assertNotNull(interfaceOperation.left().value().getWorkflowVersionId()); } @Test public void updateInterfaceOperationTest() { validateUserRoles(Role.ADMIN, Role.DESIGNER); - resourceUpdate = setUpResourceMock(); + operation = InterfaceOperationTestUtils.createMockOperation(); Resource resource = createResourceForInterfaceOperation(); resource.setComponentType(ComponentTypeEnum.RESOURCE); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - Either interfaceOperation = bl.updateInterfaceOperation(resourceId, resourceUpdate, user, true); + Either interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true); Assert.assertTrue(interfaceOperation.isLeft()); } - @Test public void deleteInterfaceOperationTest() { Resource resource = createResourceForInterfaceOperation(); @@ -237,71 +230,23 @@ public class InterfaceOperationBusinessLogicTest { validateUserRoles(Role.ADMIN, Role.DESIGNER); when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK); - Set idsToDelete = new HashSet<>(); - idsToDelete.add(operationId); - - Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true); + Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, operationId, user, true); Assert.assertTrue(deleteResourceResponseFormatEither.isLeft()); } @Test - public void deleteInterfaceOperationTestShouldFailWrongId() { - validateUserRoles(Role.ADMIN, Role.DESIGNER); - Set idsToDelete = new HashSet<>(); + public void getInterfaceOperationTest() { Resource resource = createResourceForInterfaceOperation(); resource.setComponentType(ComponentTypeEnum.RESOURCE); - when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - idsToDelete.add(resourceId); - Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true); - Assert.assertFalse(deleteResourceResponseFormatEither.isLeft()); - } - - - @Test - public void deleteInterfaceOperationFailToDeleteArtifactTest() { - Resource resource = createResourceForInterfaceOperation(); - resource.setComponentType(ComponentTypeEnum.RESOURCE); - when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); - when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR); - validateUserRoles(Role.ADMIN, Role.DESIGNER); - Set idsToDelete = new HashSet<>(); - idsToDelete.add(operationId); - - Either deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true); - Assert.assertTrue(deleteResourceResponseFormatEither.isRight()); - } - - @Test - public void interfaceOperationFailedScenarioTest() { validateUserRoles(Role.ADMIN, Role.DESIGNER); - Resource resourceWithoutInterface = new Resource(); - resourceWithoutInterface.setUniqueId(resourceId); - when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resourceWithoutInterface)); - Either interfaceOperation = bl.updateInterfaceOperation(resourceId, resourceWithoutInterface, user, true); - Assert.assertTrue(interfaceOperation.isRight()); + when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource)); + Either getResourceResponseFormatEither = bl.getInterfaceOperation(resourceId, operationId, user, true); + Assert.assertTrue(getResourceResponseFormatEither.isLeft()); } private void validateUserRoles(Role... roles) { List listOfRoles = Stream.of(roles).collect(Collectors.toList()); } - private Resource createMockResourceForAddInterface () { - Resource resource = new Resource(); - resource.setUniqueId(resourceId); - resource.setName(RESOURCE_NAME); - resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); - resource.setDescription("My short description"); - - Map operationMap = new HashMap<>(); - Map interfaceDefinitionMap = new HashMap<>(); - interfaceDefinitionMap.put("int1", InterfaceOperationTestUtils.createInterface("int1", "Interface 1", - "lifecycle", "org.openecomp.interfaces.node.lifecycle." + RESOURCE_NAME, operationMap)); - resource.setInterfaces(interfaceDefinitionMap); - List inputDefinitionList = new ArrayList<>(); - inputDefinitionList.add(createInputDefinition("uniqueId1")); - resource.setInputs(inputDefinitionList); - - return resource; - } private Resource setCanWorkOnResource(Resource resource) { resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java index d5bb4b36c6..76e73bab75 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java @@ -38,12 +38,6 @@ public class InterfaceOperationTestUtils { return id; } - public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) { - Map operationMap = createMockOperationMap(); - return createInterface("int1", "Interface 1", - "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap); - } - public static Operation createInterfaceOperation(String uniqueID, String description, ArtifactDefinition artifactDefinition, ListDataDefinition inputs, ListDataDefinition outputs, String name) { @@ -57,8 +51,23 @@ public class InterfaceOperationTestUtils { return operation; } + public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) { + Map operationMap = createMockOperationMap(); + return createInterface("int1", "Interface 1", + "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap); + } + + public static Operation mockOperationToReturn(String resourceNamme) { + return createMockOperation(); + } public static Map createMockOperationMap() { + Map operationMap = new HashMap<>(); + operationMap.put("op1", createMockOperation()); + return operationMap; + } + + public static Operation createMockOperation() { Operation operation = new Operation(); ListDataDefinition operationInputDefinitionList = new ListDataDefinition<>(); operationInputDefinitionList.add(createMockOperationInputDefinition("label1")); @@ -77,9 +86,7 @@ public class InterfaceOperationTestUtils { operation.setImplementation(implementation); operation.setWorkflowId("workflowId"); operation.setWorkflowVersionId("workflowVersionId"); - Map operationMap = new HashMap<>(); - operationMap.put("op1", operation); - return operationMap; + return operation; } public static OperationInputDefinition createMockOperationInputDefinition(String name) { @@ -101,7 +108,6 @@ public class InterfaceOperationTestUtils { Map interfaceDefinitionMap = new HashMap<>(); interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1", "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap)); - return interfaceDefinitionMap; } -- cgit 1.2.3-korg