Fix cannot set node filter cap using get_property
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / validation / NodeFilterValidationTest.java
index bcf815f..621b141 100644 (file)
 
 package org.openecomp.sdc.be.components.validation;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 import org.junit.Assert;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.InjectMocks;
@@ -43,15 +51,10 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
 import org.openecomp.sdc.common.impl.FSConfigurationSource;
 import org.openecomp.sdc.exception.ResponseFormat;
 
-import java.util.*;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-
 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";
@@ -70,7 +73,7 @@ public class NodeFilterValidationTest {
     @BeforeEach
     public void setup() {
         componentsUtils = Mockito.mock(ComponentsUtils.class);
-        MockitoAnnotations.initMocks(this);
+        MockitoAnnotations.openMocks(this);
         new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
     }
 
@@ -103,13 +106,13 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
 
@@ -157,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());
     }
@@ -168,7 +171,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -180,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());
     }
@@ -191,7 +194,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -206,7 +209,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -217,7 +220,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -232,7 +235,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> either =
                 nodeFilterValidator.validateFilter(service, INNER_SERVICE,
                         Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD,
-                    NodeFilterConstraintType.PROPERTIES);
+                    NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
 
         Assert.assertTrue(either.isRight());
     }
@@ -243,7 +246,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> either =
                 nodeFilterValidator.validateFilter(service, INNER_SERVICE,
                     Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD,
-                    NodeFilterConstraintType.PROPERTIES);
+                    NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
 
         Assert.assertTrue(either.isLeft());
     }
@@ -254,7 +257,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -264,8 +267,8 @@ public class NodeFilterValidationTest {
         Service service = createService(STRING_TYPE);
         Either<Boolean, ResponseFormat> either =
                 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
-                        + "  equal:  { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD,
-                    NodeFilterConstraintType.PROPERTIES);
+                        + "  equal:  { get_property : [SELF, Prop1]}\n"), NodeFilterConstraintAction.ADD,
+                    NodeFilterConstraintType.PROPERTIES, EMPTY_STR);
 
         Assert.assertTrue(either.isLeft());
     }
@@ -278,7 +281,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -291,7 +294,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -304,7 +307,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -317,7 +320,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }
@@ -330,7 +333,7 @@ public class NodeFilterValidationTest {
         Either<Boolean, ResponseFormat> 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());
     }