summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-09-08 18:55:08 +0100
committerMichael Morris <michael.morris@est.tech>2022-09-19 08:38:43 +0000
commit0d38a72c022fa93dba0bf052f893e51fb73d3552 (patch)
tree25f49242e6c6666c39e32abae66e4950fe4e18ed /catalog-model/src/test/java
parent2fe3d879319a34e9802d0bc172fa11fefe771df3 (diff)
Support TOSCA functions in Node Capability Filters
Adds support to use TOSCA functions as value in the node capability filters. Removes the current capability filter component to reuse, with a few changes, the node property filters component. Fixes problems with the edition and deletion of node capability filters. Change-Id: Ic91242d6cbc24e2ce0f60b84c63e104575bef8a9 Issue-ID: SDC-4173 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/test/java')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperationTest.java77
1 files changed, 66 insertions, 11 deletions
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