diff options
Diffstat (limited to 'catalog-be/src/test')
2 files changed, 155 insertions, 36 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 c4a4acecbc..6996465a82 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 @@ -25,6 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; 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.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -43,7 +45,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; @@ -57,8 +58,10 @@ import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; 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; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.ComponentInstance; @@ -145,7 +148,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) .thenReturn(StorageOperationStatus.OK); - when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(ActionStatus.GENERAL_ERROR); + when(componentsUtils.convertFromStorageResponse(any())).thenReturn(ActionStatus.GENERAL_ERROR); when(nodeFilterOperation.createNodeFilter(componentId, componentInstanceId)) .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource)) @@ -246,6 +249,76 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock } @Test + public void addNodeFilterPropertiesTest() throws BusinessLogicException { + componentInstance.setNodeFilter(ciNodeFilterDataDefinition); + + when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource)); + when(nodeFilterValidator + .validateFilter(resource, componentInstanceId, + requirementNodeFilterPropertyDataDefinition.getConstraints(), + NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true)); + when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) + .thenReturn(Either.left(true)); + when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + when(nodeFilterOperation.addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class), + any(RequirementNodeFilterPropertyDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition)); + when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + + final Optional<CINodeFilterDataDefinition> result = componentNodeFilterBusinessLogic + .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD, + "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.PROPERTIES); + + assertThat(result).isPresent(); + assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1); + verify(toscaOperationFacade, times(1)).getToscaElement(componentId); + verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId, + Collections.singletonList(constraint), NodeFilterConstraintAction.ADD); + verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); + verify(nodeFilterOperation, times(1)) + .addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class), + any(RequirementNodeFilterPropertyDataDefinition.class)); + verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource); + } + + @Test + public void addNodeFilterCapabilitiesTest() throws BusinessLogicException { + componentInstance.setNodeFilter(ciNodeFilterDataDefinition); + + when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource)); + when(nodeFilterValidator + .validateFilter(resource, componentInstanceId, + requirementNodeFilterPropertyDataDefinition.getConstraints(), + NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true)); + when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) + .thenReturn(Either.left(true)); + when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + when(nodeFilterOperation.addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class), + any(RequirementNodeFilterCapabilityDataDefinition.class))).thenReturn(Either.left(ciNodeFilterDataDefinition)); + when(graphLockOperation.unlockComponent(componentId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + + final Optional<CINodeFilterDataDefinition> result = componentNodeFilterBusinessLogic + .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD, + "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.CAPABILITIES); + + assertThat(result).isPresent(); + assertThat(result.get().getProperties().getListToscaDataDefinition()).hasSize(1); + verify(toscaOperationFacade, times(1)).getToscaElement(componentId); + verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId, + Collections.singletonList(constraint), NodeFilterConstraintAction.ADD); + verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); + verify(nodeFilterOperation, times(1)) + .addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class), + any(RequirementNodeFilterCapabilityDataDefinition.class)); + verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource); + } + + @Test public void addNodeFilterFailTest() { componentInstance.setNodeFilter(ciNodeFilterDataDefinition); @@ -264,7 +337,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints(); assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD, - "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE)); + "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.PROPERTIES)); verify(toscaOperationFacade, times(1)).getToscaElement(componentId); verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); @@ -285,7 +359,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD, - "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE)); + "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.PROPERTIES)); } @Test @@ -477,4 +552,4 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock fail(e.getMessage()); } } -}
\ No newline at end of file +} 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 08890ef3e7..3bad7dd497 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 @@ -72,6 +72,7 @@ import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; @@ -143,10 +144,11 @@ public class ComponentNodeFilterServletTest extends JerseyTest { } @Test - public void addNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException { + public void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -160,7 +162,7 @@ public class ComponentNodeFilterServletTest extends JerseyTest { assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName()); assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString()); - when(componentsUtils.parseToConstraint(anyString(), any(User.class),ArgumentMatchers.any(ComponentTypeEnum.class))) + when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class))) .thenReturn(Optional.of(uiConstraint)); assertNotNull(constraint); @@ -169,7 +171,8 @@ public class ComponentNodeFilterServletTest extends JerseyTest { assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint); when(componentNodeFilterBusinessLogic .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD, - uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE)) + uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.PROPERTIES)) .thenReturn(Optional.of(ciNodeFilterDataDefinition)); final Response response = target() @@ -179,8 +182,44 @@ public class ComponentNodeFilterServletTest extends JerseyTest { .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON)); verify(componentNodeFilterBusinessLogic, times(1)) - .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(), anyString(), anyBoolean(), - ArgumentMatchers.any(ComponentTypeEnum.class)); + .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(), + anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class), + ArgumentMatchers.any(NodeFilterConstraintType.class)); + + assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200); + } + + @Test + public void addNodeFilterCapabilitiesSuccessTest() 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.parseToConstraint(anyString(), any(User.class),ArgumentMatchers.any(ComponentTypeEnum.class))) + .thenReturn(Optional.of(uiConstraint)); + + assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1); + when(componentNodeFilterBusinessLogic + .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD, + uiConstraint.getServicePropertyName(), 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) + .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON)); + + verify(componentNodeFilterBusinessLogic, times(1)) + .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(), + anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class), + ArgumentMatchers.any(NodeFilterConstraintType.class)); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200); } @@ -188,8 +227,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void addNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -202,7 +242,8 @@ public class ComponentNodeFilterServletTest extends JerseyTest { when(componentNodeFilterBusinessLogic .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD, - uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE)) + uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE, + NodeFilterConstraintType.PROPERTIES)) .thenReturn(Optional.empty()); final Response response = target() @@ -211,18 +252,14 @@ public class ComponentNodeFilterServletTest extends JerseyTest { .header(USER_ID_HEADER, USER_ID) .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON)); - verify(componentNodeFilterBusinessLogic, times(1)) - .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(), anyString(), anyBoolean(), - ArgumentMatchers.any(ComponentTypeEnum.class)); - assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500); } @Test public void addNodeFilterFailConstraintParseTest() throws JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -247,8 +284,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void addNodeFilterFailConvertTest() throws JsonProcessingException, BusinessLogicException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES.getType()); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -273,8 +311,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void updateNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -306,8 +345,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -338,8 +378,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void updateNodeFilterFailConstraintParseTest() throws JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -360,8 +401,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void updateNodeFilterFailConvertTest() throws JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -384,8 +426,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void deleteNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException { initComponentData(); - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance, 0); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0); when(userValidations.validateUserExists(user)).thenReturn(user); when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user); @@ -413,8 +456,9 @@ public class ComponentNodeFilterServletTest extends JerseyTest { @Test public void deleteNodeFilterFailTest() { - final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s"; - final String path = String.format(pathFormat, componentType, componentId, componentInstance, 1); + final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s/%s"; + final String path = String.format(pathFormat, componentType, componentId, componentInstance, + NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 1); final Response response = target() .path(path) .request(MediaType.APPLICATION_JSON) @@ -488,4 +532,4 @@ public class ComponentNodeFilterServletTest extends JerseyTest { return mapper.writeValueAsString(uiConstraint); } -}
\ No newline at end of file +} |