summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java35
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java77
2 files changed, 93 insertions, 19 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
index 3dc2a73466..f1de061c9f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
@@ -84,13 +84,9 @@ public class NodeFilterOperation extends BaseOperation {
final int propertyIndex,
final NodeFilterConstraintType nodeFilterConstraintType) {
if (NodeFilterConstraintType.PROPERTIES.equals(nodeFilterConstraintType)) {
- final ListDataDefinition<PropertyFilterDataDefinition> properties = nodeFilterDataDefinition.getProperties();
- properties.getListToscaDataDefinition().remove(propertyIndex);
- nodeFilterDataDefinition.setProperties(properties);
+ nodeFilterDataDefinition.getProperties().getListToscaDataDefinition().remove(propertyIndex);
} else if (NodeFilterConstraintType.CAPABILITIES.equals(nodeFilterConstraintType)) {
- final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilities = nodeFilterDataDefinition.getCapabilities();
- capabilities.getListToscaDataDefinition().remove(propertyIndex);
- nodeFilterDataDefinition.setCapabilities(capabilities);
+ removeCapabilityNodeFilterByIndex(nodeFilterDataDefinition, propertyIndex);
}
return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition);
}
@@ -116,11 +112,11 @@ public class NodeFilterOperation extends BaseOperation {
capabilities = new ListDataDefinition<>();
nodeFilterDataDefinition.setCapabilities(capabilities);
}
-
+
final Optional<RequirementNodeFilterCapabilityDataDefinition> existingCap = capabilities
.getListToscaDataDefinition().stream()
.filter(def -> def.getName().equals(requirementNodeFilterCapabilityDataDefinition.getName())).findAny();
-
+
if (existingCap.isPresent()) {
final ListDataDefinition<PropertyFilterDataDefinition> newProperties = requirementNodeFilterCapabilityDataDefinition.getProperties();
final ListDataDefinition<PropertyFilterDataDefinition> existingProperties = existingCap.get().getProperties();
@@ -144,6 +140,29 @@ public class NodeFilterOperation extends BaseOperation {
return addOrUpdateNodeFilter(false, componentId, componentInstanceId, nodeFilterDataDefinition);
}
+ private void removeCapabilityNodeFilterByIndex(final CINodeFilterDataDefinition nodeFilterDataDefinition, final int filterToRemoveIndex) {
+ int currentFilterCountdown = filterToRemoveIndex;
+ final List<RequirementNodeFilterCapabilityDataDefinition> filtersByCapability =
+ nodeFilterDataDefinition.getCapabilities().getListToscaDataDefinition();
+ for (final RequirementNodeFilterCapabilityDataDefinition capabilityFilterGroup : filtersByCapability) {
+ final List<PropertyFilterDataDefinition> capabilityFilters = capabilityFilterGroup.getProperties().getListToscaDataDefinition();
+ if (isFilterInCapabilityGroup(currentFilterCountdown, capabilityFilters)) {
+ capabilityFilters.remove(currentFilterCountdown);
+ break;
+ } else {
+ currentFilterCountdown = getRemainingFilterCount(currentFilterCountdown, capabilityFilters);
+ }
+ }
+ }
+
+ private boolean isFilterInCapabilityGroup(int currentFilterCount, List<PropertyFilterDataDefinition> capabilityFilters) {
+ return capabilityFilters.size() > currentFilterCount;
+ }
+
+ private int getRemainingFilterCount(int currentFilterCount, final List<PropertyFilterDataDefinition> capabilityFilters) {
+ return currentFilterCount - capabilityFilters.size();
+ }
+
private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(final boolean isUpdateAction, final String componentId,
final String componentInstanceId,
final CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
index bd16016ad9..3df279511b 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java
@@ -20,9 +20,22 @@
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
import org.janusgraph.core.JanusGraphVertex;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -37,22 +50,14 @@ import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import java.util.Arrays;
-import java.util.HashMap;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
class NodeFilterOperationTest {
private final NodeFilterOperation nodeFilterOperation = new NodeFilterOperation();
@@ -116,4 +121,54 @@ class NodeFilterOperationTest {
assertEquals("new node filter name", expectedNodeFilter.getName());
assertEquals(listDataDefinition, expectedNodeFilter.getProperties());
}
+
+ @Test
+ void deleteCapabilityConstraintTest() {
+ final var ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
+ final var capabilities = new ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition>();
+
+ var capabilityFilter1 = new RequirementNodeFilterCapabilityDataDefinition();
+ final var propertyFilterList = new ListDataDefinition<PropertyFilterDataDefinition>();
+ propertyFilterList.add(new PropertyFilterDataDefinition());
+ propertyFilterList.add(new PropertyFilterDataDefinition());
+ propertyFilterList.add(new PropertyFilterDataDefinition());
+ propertyFilterList.add(new PropertyFilterDataDefinition());
+ propertyFilterList.add(new PropertyFilterDataDefinition());
+ propertyFilterList.add(new PropertyFilterDataDefinition());
+ capabilityFilter1.setProperties(propertyFilterList);
+ capabilities.add(capabilityFilter1);
+
+ var capabilityFilter2 = new RequirementNodeFilterCapabilityDataDefinition();
+ final var propertyFilterList2 = new ListDataDefinition<PropertyFilterDataDefinition>();
+ final var filterToDelete = new PropertyFilterDataDefinition();
+ propertyFilterList2.add(filterToDelete);
+ propertyFilterList2.add(new PropertyFilterDataDefinition());
+ capabilityFilter2.setProperties(propertyFilterList2);
+ capabilities.add(capabilityFilter2);
+
+ final GraphVertex serviceVertexMock = mock(GraphVertex.class);
+ final JanusGraphVertex serviceJanusVertex = mock(JanusGraphVertex.class);
+ when(serviceVertexMock.getVertex()).thenReturn(serviceJanusVertex);
+ when(serviceVertexMock.getUniqueId()).thenReturn("componentId");
+ when(janusGraphDao.getVertexById("componentId", JsonParseFlagEnum.NoParse)).thenReturn(Either.left(serviceVertexMock));
+ final GraphVertex nodeFilterVertexMock = mock(GraphVertex.class);
+ when(janusGraphDao.getChildVertex(serviceVertexMock, EdgeLabelEnum.NODE_FILTER_TEMPLATE, JsonParseFlagEnum.ParseJson))
+ .thenReturn(Either.left(nodeFilterVertexMock));
+ final JanusGraphVertex nodeFilterJanusVertexMock = mock(JanusGraphVertex.class);
+ when(nodeFilterVertexMock.getVertex()).thenReturn(nodeFilterJanusVertexMock);
+ final Edge edgeToDeleteMock = mock(Edge.class);
+ when(nodeFilterJanusVertexMock.edges(Direction.IN, EdgeLabelEnum.NODE_FILTER_TEMPLATE.name()))
+ .thenReturn(List.of(edgeToDeleteMock).iterator());
+ when(janusGraphDao.getProperty(any(), eq(GraphPropertyEnum.UNIQUE_ID.getProperty()))).thenReturn("componentId");
+ when(janusGraphDao.updateVertex(nodeFilterVertexMock)).thenReturn(Either.left(nodeFilterVertexMock));
+
+ ciNodeFilterDataDefinition.setCapabilities(capabilities);
+ final Either<CINodeFilterDataDefinition, StorageOperationStatus> result = nodeFilterOperation.deleteConstraint(
+ "componentId", "instanceId", ciNodeFilterDataDefinition, 6, NodeFilterConstraintType.CAPABILITIES);
+
+ assertTrue(result.isLeft());
+ assertEquals(1, propertyFilterList2.getListToscaDataDefinition().size());
+ assertFalse(propertyFilterList2.getListToscaDataDefinition().contains(filterToDelete));
+ }
+
} \ No newline at end of file