aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2019-01-29 13:04:42 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-01-30 12:18:32 +0000
commitade7fd243fe41b5056ba63d3584ea616ee8bf808 (patch)
tree4be93c8ddfd4577b29fe8553f92d2bd17dbe89b4 /catalog-be/src/test/java
parent614136b09c5d11bec99fe3c1e23e8c9e022eaa58 (diff)
Add dependent child service to service
Add dependent child service to service Issue-ID: SDC-1987 Change-Id: Ic542fe1bc13f2b77df9944f05421a42b4b21c437 Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java287
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java176
2 files changed, 463 insertions, 0 deletions
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
new file mode 100644
index 0000000000..fe9827f362
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
@@ -0,0 +1,287 @@
+package org.openecomp.sdc.be.components.validation;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+public class NodeFilterValidationTest {
+
+ 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";
+ private static final String FLOAT_TYPE = "float";
+ private static final String STRING_TYPE = "string";
+ private static final String LIST_TYPE = "list";
+ private static final String COMPONENT1_ID = "component1";
+ private static final String INTEGER_TYPE = "integer";
+ private static final String PARENTSERVICE_ID = "parentservice";
+ private static final String COMPONENT2_ID = "component2";
+ private ComponentsUtils componentsUtils;
+
+ @InjectMocks
+ private NodeFilterValidator nodeFilterValidator;
+
+ @Before
+ public void setup() {
+ componentsUtils = Mockito.mock(ComponentsUtils.class);
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
+ Service service = createService("booleanIncorrect");
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
+ Service service = createService("boolean");
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
+ .replace("equal", "greater_than")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
+ Service service = createService("boolean");
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "trues")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
+ Service service = createService(STRING_TYPE);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
+ .replace("equal", "greater_than")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isLeft());
+ }
+
+ @Test
+ public void testValidateNodeFilterIntegerValueSuccess() {
+ Service service = createService(INTEGER_TYPE);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isLeft());
+ }
+
+ @Test
+ public void testValidateNodeFilterIntegerValueFail() {
+ Service service = createService(INTEGER_TYPE);
+
+ Mockito.when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1"))
+ .thenReturn(new ResponseFormat());
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isRight());
+ }
+
+ @Test
+ public void testValidateNodeFilterFloatValueSuccess() {
+ Service service = createService(FLOAT_TYPE);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
+ NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isLeft());
+ }
+
+ @Test
+ public void testValidateNodeFilterFloatValueFail() {
+ Service service = createService(FLOAT_TYPE);
+
+ Mockito.when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1"))
+ .thenReturn(new ResponseFormat());
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isRight());
+ }
+
+ @Test
+ public void testValidateNodeFilterStringValueSuccess() {
+ Service service = createService(STRING_TYPE);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertyConstraintBrotherSuccess() {
+ Service service = createService(STRING_TYPE);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property :[component2, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertyConstraintParentSuccess() {
+ Service service = createService(STRING_TYPE);
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertTrue(either.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
+ Service service = createService(STRING_TYPE);
+ service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(INTEGER_TYPE);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property : [component2, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertyConstraintParentPropertyTypeMismatch() {
+ Service service = createService(STRING_TYPE);
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(INTEGER_TYPE);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertyConstraintParentPropertyNotFound() {
+ Service service = createService(STRING_TYPE);
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testvalidatePropertyConstraintBrotherPropertyNotFound() {
+ Service service = createService(STRING_TYPE);
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ @Test
+ public void testValidatePropertyConstraintParentPropertySchemaMismatch() {
+ Service service = createService(LIST_TYPE,STRING_TYPE);
+ service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(LIST_TYPE);
+
+ Either<Boolean, ResponseFormat> either =
+ nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ + " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
+
+ Assert.assertFalse(either.isLeft());
+ }
+
+ private Service createService(String type) {
+ return createService(type, null);
+ }
+
+ private Service createService(String type, String schemaType) {
+ Service service = new Service();
+ service.setName(PARENTSERVICE_ID);
+
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName(PROPERTY_NAME);
+ propertyDefinition.setType(type);
+ if (schemaType != null){
+ SchemaDefinition schemaDefinition = new SchemaDefinition();
+ PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
+ schemaProperty.setType(schemaType);
+ schemaDefinition.setProperty(schemaProperty);
+ propertyDefinition.setSchema(schemaDefinition);
+ }
+ service.setProperties(Collections.singletonList(propertyDefinition));
+
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(COMPONENT1_ID);
+ componentInstance.setName(COMPONENT1_ID);
+
+ ComponentInstance componentInstance2 = new ComponentInstance();
+ componentInstance2.setUniqueId(COMPONENT2_ID);
+ componentInstance2.setName(COMPONENT2_ID);
+
+ service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
+
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ componentInstanceProperty.setName(PROPERTY_NAME);
+ componentInstanceProperty.setType(type);
+
+ ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
+ componentInstanceProperty2.setName(PROPERTY_NAME);
+ componentInstanceProperty2.setType(type);
+
+ Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
+ componentInstancePropertyMap.put(componentInstance.getUniqueId(),
+ Collections.singletonList(componentInstanceProperty));
+ componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
+ Collections.singletonList(componentInstanceProperty2));
+ componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
+
+ service.setComponentInstancesProperties(componentInstancePropertyMap);
+
+ return service;
+ }
+
+} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java
new file mode 100644
index 0000000000..942a279ec7
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ConstraintConvertorTest.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+
+public class ConstraintConvertorTest {
+
+ @Test
+ public void convertStatic(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {equal: some static}\n");
+ assertNotNull(uiConstraint);
+ assertEquals(uiConstraint.getConstraintOperator(),"equal");
+ assertEquals(uiConstraint.getValue(),"some static");
+ assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ }
+
+ @Test
+ public void convertFromStatic(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "some static");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size: {equal: some static}\n", constraint);
+ }
+
+ @Test
+ public void convertSelfProperty(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n {equal: { get_property: [SELF, size] }}");
+ assertNotNull(uiConstraint);
+ assertEquals(uiConstraint.getConstraintOperator(),"equal");
+ assertEquals(uiConstraint.getValue(),"size");
+ assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ assertEquals(uiConstraint.getSourceName().trim(),"SELF");
+ assertEquals(uiConstraint.getSourceType(), ConstraintConvertor.PROPERTY_CONSTRAINT);
+ }
+
+ @Test
+ public void convertFromSelfProperty(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.PROPERTY_CONSTRAINT, "SELF" ,"some static");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size:\n" + " equal:\n" + " get_property: [SELF, some static]\n", constraint);
+ }
+
+ @Test
+ public void convertCIProperty(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: { get_property: [A, size]}");
+ assertNotNull(uiConstraint);
+ assertEquals(uiConstraint.getConstraintOperator(),"equal");
+ assertEquals(uiConstraint.getValue(),"size");
+ assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ assertEquals(uiConstraint.getSourceName().trim(),"A");
+ }
+
+
+ @Test
+ public void convertFromCIProperty(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.PROPERTY_CONSTRAINT, "A" ,"size");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size:\n" + " equal:\n" + " get_property: [A, size]\n", constraint);
+ }
+
+ @Test
+ public void convertServiceTemplateInput(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {equal: {get_input: InputName}}\n");
+ assertNotNull(uiConstraint);
+ }
+
+ @Test
+ public void convertFromServiceTemplateInput(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.SERVICE_INPUT_CONSTRAINT, "InputName");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size:\n equal: {get_input: InputName}\n", constraint);
+ }
+
+ @Test
+ public void convertGreaterThanStatic(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {greater_than: 2}\n");
+ assertNotNull(uiConstraint);
+ assertEquals(uiConstraint.getConstraintOperator(),"greater_than");
+ assertEquals(uiConstraint.getValue(),2);
+ assertEquals(uiConstraint.getServicePropertyName().trim(),"mem_size");
+ }
+
+ @Test
+ public void convertFromGreaterThanStatic(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "greater_than" , ConstraintConvertor.STATIC_CONSTRAINT, 2);
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size: {greater_than: 2}\n", constraint);
+ }
+
+ @Test
+ public void convertLessThanServiceProperty(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size: {less_then: {get_input: InputName}}");
+ assertNotNull(uiConstraint);
+ }
+
+ @Test
+ public void convertFromLessThanServiceProperty(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "less_then" , ConstraintConvertor.SERVICE_INPUT_CONSTRAINT, "InputName");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size:\n" + " less_then: {get_input: InputName}\n", constraint);
+ }
+
+ @Test
+ public void convertFromEqualStaticMap(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "{x: xx,"+
+ " y: yy}\n");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size:\n" + " equal: {x: xx, y: yy}\n", constraint);
+ }
+
+ @Test
+ public void convertStringToMap(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: {x: xx, y: yy}\n");
+ assertNotNull(uiConstraint);
+ assertTrue(uiConstraint.getValue() instanceof Map);
+ }
+
+ @Test
+ public void convertFromEqualStaticList(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = new UIConstraint("mem_size", "equal" , ConstraintConvertor.STATIC_CONSTRAINT, "[x, y]\n");
+ String constraint = constraintConvertor.convert(uiConstraint);
+ assertNotNull(constraint);
+ assertEquals("mem_size:\n" + " equal: [x, y]\n", constraint);
+ }
+
+ @Test
+ public void convertStringToList(){
+ ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert("mem_size:\n" + " equal: [x, y]\n");
+ assertNotNull(uiConstraint);
+ assertTrue(uiConstraint.getValue() instanceof List);
+ }
+}