From 302c525546650b71ad699903d98090f8cb23f068 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Thu, 10 Mar 2022 12:19:18 +0000 Subject: Fix cannot set node filter cap using get_property Change-Id: I92fd4016b19e03e22622cf6e476f17b49e3d6a47 Issue-ID: SDC-3904 Signed-off-by: MichaelMorris --- .../impl/ComponentNodeFilterBusinessLogicTest.java | 46 +++++++++++++--------- .../validation/NodeFilterValidationTest.java | 37 ++++++++--------- 2 files changed, 47 insertions(+), 36 deletions(-) (limited to 'catalog-be/src/test/java') 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 ed5c5b9a2d..3b717fb51d 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 @@ -29,6 +29,7 @@ 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.ArgumentMatchers.isNull; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -266,7 +267,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator .validateFilter(resource, componentInstanceId, requirementNodeFilterPropertyDataDefinition.getConstraints(), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(true)); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true)); when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) @@ -279,13 +280,13 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock final Optional result = componentNodeFilterBusinessLogic .addNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.ADD, "MyPropertyName", constraint, true, ComponentTypeEnum.RESOURCE, - NodeFilterConstraintType.PROPERTIES, capabilityName); + 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, NodeFilterConstraintType.PROPERTIES); + Collections.singletonList(constraint), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, ""); verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); verify(nodeFilterOperation, times(1)) .addNewProperty(anyString(), anyString(), any(CINodeFilterDataDefinition.class), @@ -301,7 +302,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator .validateFilter(resource, componentInstanceId, requirementNodeFilterPropertyDataDefinition.getConstraints(), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES)).thenReturn(Either.left(true)); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, capabilityName)).thenReturn(Either.left(true)); when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) @@ -320,7 +321,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock 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, NodeFilterConstraintType.CAPABILITIES); + Collections.singletonList(constraint), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, capabilityName); verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); verify(nodeFilterOperation, times(1)) .addNewCapabilities(anyString(), anyString(), any(CINodeFilterDataDefinition.class), @@ -336,7 +337,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator .validateFilter(resource, componentInstanceId, requirementNodeFilterPropertyDataDefinition.getConstraints(), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(true)); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, capabilityName)).thenReturn(Either.left(true)); when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) @@ -353,7 +354,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock verify(toscaOperationFacade, times(1)).getToscaElement(componentId); verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId, - constraints, NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + constraints, NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, capabilityName); verify(nodeFilterOperation, times(0)) .addNewProperty(componentId, componentInstanceId, ciNodeFilterDataDefinition, requirementNodeFilterPropertyDataDefinition); @@ -381,7 +382,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint), - NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(true)); + NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) .thenReturn(StorageOperationStatus.OK); @@ -405,7 +406,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock .validateComponentInstanceExist(resource, componentInstanceId); verify(nodeFilterValidator, times(1)) .validateFilter(resource, componentInstanceId, singletonList(constraint), - NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, ""); verify(nodeFilterOperation, times(1)) .deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition, 0, NodeFilterConstraintType.PROPERTIES); @@ -420,7 +421,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint), - NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(true)); + NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) .thenReturn(StorageOperationStatus.OK); @@ -440,7 +441,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource); verify(nodeFilterValidator, times(1)) .validateFilter(resource, componentInstanceId, singletonList(constraint), - NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, ""); verify(nodeFilterValidator, times(1)) .validateComponentInstanceExist(resource, componentInstanceId); verify(graphLockOperation, times(1)).unlockComponent(componentId, NodeTypeEnum.Resource); @@ -452,7 +453,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint), - NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES)).thenReturn(Either.left(true)); + NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, "")).thenReturn(Either.left(true)); assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic .deleteNodeFilter(componentId, componentInstanceId, NodeFilterConstraintAction.DELETE, constraint, @@ -461,7 +462,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock verify(toscaOperationFacade, times(1)).getToscaElement(componentId); verify(nodeFilterValidator, times(1)) .validateFilter(resource, componentInstanceId, singletonList(constraint), - NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.DELETE, NodeFilterConstraintType.PROPERTIES, ""); verify(nodeFilterValidator, times(1)) .validateComponentInstanceExist(resource, componentInstanceId); } @@ -476,7 +477,12 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(), ArgumentMatchers.any(NodeFilterConstraintAction.class), - ArgumentMatchers.any(NodeFilterConstraintType.class))).thenReturn(Either.left(true)); + ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true)); + + when(nodeFilterValidator + .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(), + ArgumentMatchers.any(NodeFilterConstraintAction.class), + ArgumentMatchers.any(NodeFilterConstraintType.class), isNull())).thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) .thenReturn(StorageOperationStatus.OK); @@ -499,16 +505,20 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock } @Test - public void updateNodeFilterFailTest() { + public void updateNodeFilterFailTest() throws BusinessLogicException { componentInstance.setNodeFilter(ciNodeFilterDataDefinition); when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource)); when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId)) .thenReturn(Either.left(true)); + when(nodeFilterValidator + .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(), + ArgumentMatchers.any(NodeFilterConstraintAction.class), + ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true)); when(nodeFilterValidator .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(), ArgumentMatchers.any(NodeFilterConstraintAction.class), - ArgumentMatchers.any(NodeFilterConstraintType.class))).thenReturn(Either.left(true)); + ArgumentMatchers.any(NodeFilterConstraintType.class), isNull())).thenReturn(Either.left(true)); when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource)) .thenReturn(StorageOperationStatus.OK); @@ -523,7 +533,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock .thenReturn(StorageOperationStatus.OK); assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic - .updateNodeFilter(componentId, componentInstanceId, uiConstraint, ComponentTypeEnum.RESOURCE, + .updateNodeFilter(componentId, componentInstanceId, uiConstraint, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES, 0)); } @@ -535,7 +545,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock when(nodeFilterValidator .validateFilter(ArgumentMatchers.any(Component.class), anyString(), anyList(), ArgumentMatchers.any(NodeFilterConstraintAction.class), - ArgumentMatchers.any(NodeFilterConstraintType.class))).thenReturn(Either.left(true)); + ArgumentMatchers.any(NodeFilterConstraintType.class), anyString())).thenReturn(Either.left(true)); assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic .updateNodeFilter(componentId, componentInstanceId, uiConstraint, ComponentTypeEnum.RESOURCE, diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java index 3bdd22c6fc..621b14102f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java @@ -53,7 +53,8 @@ import org.openecomp.sdc.exception.ResponseFormat; public class NodeFilterValidationTest { - private static final String UI_CONSTRAINT_STATIC = "Prop1: {equal: 'value'}"; + private static final String EMPTY_STR = ""; + private static final String UI_CONSTRAINT_STATIC = "Prop1: {equal: 'value'}"; private static final String INNER_SERVICE = "innerService"; private static final String PROPERTY_NAME = "Prop1"; private static final String VALUE = "value"; @@ -105,13 +106,13 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); assertTrue(either.isRight()); either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES, EMPTY_STR); assertTrue(either.isRight()); } @@ -159,7 +160,7 @@ public class NodeFilterValidationTest { nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true") .replace("equal", "greater_than")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } @@ -170,7 +171,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "trues")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } @@ -182,7 +183,7 @@ public class NodeFilterValidationTest { nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true") .replace("equal", "greater_than")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isLeft()); } @@ -193,7 +194,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isLeft()); } @@ -208,7 +209,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isRight()); } @@ -219,7 +220,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")), - NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isLeft()); } @@ -234,7 +235,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isRight()); } @@ -245,7 +246,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isLeft()); } @@ -256,7 +257,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property :[component2, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isLeft()); } @@ -267,7 +268,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property : [SELF, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertTrue(either.isLeft()); } @@ -280,7 +281,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property : [component2, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } @@ -293,7 +294,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } @@ -306,7 +307,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } @@ -319,7 +320,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } @@ -332,7 +333,7 @@ public class NodeFilterValidationTest { Either either = nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n" + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD, - NodeFilterConstraintType.PROPERTIES); + NodeFilterConstraintType.PROPERTIES, EMPTY_STR); Assert.assertFalse(either.isLeft()); } -- cgit 1.2.3-korg