From cda67b6e9d477cad22de6d4ef5834e61c83db0a9 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Tue, 1 Sep 2020 13:29:56 +0100 Subject: Add and change node_filter unit testes Issue-ID: SDC-3272 Signed-off-by: aribeiro Change-Id: I29ff07fa5e4d4cec1379018d417e35a156e7aa2f --- .../impl/ComponentNodeFilterBusinessLogicTest.java | 33 ++++++++++++ .../servlets/ComponentNodeFilterServletTest.java | 58 ++++++++++++++++++++-- 2 files changed, 86 insertions(+), 5 deletions(-) (limited to 'catalog-be') 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 7c81807777..5867c4d199 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 @@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -456,6 +457,38 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock .validateComponentInstanceExist(resource, componentInstanceId); } + @Test + public void updateNodeFilterTest() throws BusinessLogicException { + componentInstance.setNodeFilter(ciNodeFilterDataDefinition); + + when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource)); + when(nodeFilterValidator.validateFilter(resource, componentInstanceId, + Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true)); + when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + + when(nodeFilterOperation.updateCapabilities(anyString(), anyString(), + any(CINodeFilterDataDefinition.class), anyList())).thenReturn(Either.left(ciNodeFilterDataDefinition)); + + final List constraints = requirementNodeFilterPropertyDataDefinition.getConstraints(); + final Optional updateNodeFilterResult = componentNodeFilterBusinessLogic + .updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.CAPABILITIES); + + assertThat(updateNodeFilterResult).isPresent(); + assertThat(updateNodeFilterResult.get().getProperties().getListToscaDataDefinition()).hasSize(1); + + verify(toscaOperationFacade, times(1)).getToscaElement(componentId); + verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); + verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId, + constraints, NodeFilterConstraintAction.UPDATE); + verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource); + verify(nodeFilterOperation, times(1)) + .updateCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class), anyList()); + } + @Test public void updateNodeFilterFailTest() { componentInstance.setNodeFilter(ciNodeFilterDataDefinition); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java index 947a702db0..a745f41ec0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentNodeFilterServletTest.java @@ -70,6 +70,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType; @@ -113,7 +114,6 @@ public class ComponentNodeFilterServletTest extends JerseyTest { private static UserValidations userValidations; private CINodeFilterDataDefinition ciNodeFilterDataDefinition; - private RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition; private UIConstraint uiConstraint; private String constraint; private String inputJson; @@ -309,7 +309,7 @@ public class ComponentNodeFilterServletTest extends JerseyTest { } @Test - public void updateNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException { + public void updateNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; final String path = String.format(pathFormat, componentType, componentId, componentInstance, @@ -343,6 +343,44 @@ public class ComponentNodeFilterServletTest extends JerseyTest { assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200); } + @Test + public void updateNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException { + initComponentData(); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.CAPABILITIES_PARAM_NAME); + + when(userValidations.validateUserExists(user)).thenReturn(user); + when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); + + when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200); + when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat); + + when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class))) + .thenReturn(Collections.singletonList(uiConstraint)); + + when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class), + ArgumentMatchers.>any(), + nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))) + .thenReturn(Either.left(Arrays.asList(new ObjectMapper().convertValue(uiConstraint, Map.class)))); + + when(componentNodeFilterBusinessLogic + .updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint), + true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.CAPABILITIES)) + .thenReturn(Optional.of(ciNodeFilterDataDefinition)); + final Response response = target() + .path(path) + .request(MediaType.APPLICATION_JSON) + .header(USER_ID_HEADER, USER_ID) + .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON)); + + verify(componentNodeFilterBusinessLogic, times(1)) + .updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(), + ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class)); + + assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200); + } + @Test public void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); @@ -514,15 +552,25 @@ public class ComponentNodeFilterServletTest extends JerseyTest { constraint = new ConstraintConvertor().convert(uiConstraint); inputJson = buildConstraintDataJson(uiConstraint); - requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); + final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition = + new RequirementNodeFilterPropertyDataDefinition(); requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName()); requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint))); - final ListDataDefinition listDataDefinition = + final ListDataDefinition propertyDataDefinitionList = new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition))); + final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition = + new RequirementNodeFilterCapabilityDataDefinition(); + requirementNodeFilterCapabilityDataDefinition.setName(uiConstraint.getServicePropertyName()); + requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList); + + final ListDataDefinition capabilityDataDefinitionList = + new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterCapabilityDataDefinition))); + ciNodeFilterDataDefinition = new CINodeFilterDataDefinition(); - ciNodeFilterDataDefinition.setProperties(listDataDefinition); + ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList); + ciNodeFilterDataDefinition.setCapabilities(capabilityDataDefinitionList); ciNodeFilterDataDefinition.setID("NODE_FILTER_UID"); user = new User(); -- cgit 1.2.3-korg