diff options
Diffstat (limited to 'catalog-model/src/test')
10 files changed, 700 insertions, 156 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java index 8b8e813501..39f9118337 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java @@ -523,7 +523,7 @@ public class CapabilityTypeOperationTest extends ModelTestBase { property2.setDescription("Number of (actual or virtual) CPUs associated with the Compute node."); property2.setType(ToscaType.INTEGER.name().toLowerCase()); List<PropertyConstraint> constraints3 = new ArrayList<>(); - List<String> range = new ArrayList<>(); + List<Object> range = new ArrayList<>(); range.add("1"); range.add("4"); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java index 33322ecfb6..3f78ff0b03 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java @@ -166,17 +166,17 @@ public class PropertyOperationTest extends ModelTestBase { constraints.add(propertyConstraint10); return constraints; } - + private InRangeConstraint buildInRangeConstraint() { - List<String> range = new ArrayList<>(); + List<Object> range = new ArrayList<>(); range.add("23"); range.add("67"); InRangeConstraint inRangeConstraint = new InRangeConstraint(range); return inRangeConstraint; } - + private ValidValuesConstraint buildValidValuesConstraint() { - List<String> validValues = new ArrayList<>(); + List<Object> validValues = new ArrayList<>(); validValues.add("abc"); validValues.add("def"); validValues.add("fhi"); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java index 73a60079c3..5f8bde8090 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java @@ -302,7 +302,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { property2.setDescription("Number of (actual or virtual) CPUs associated with the Compute node."); property2.setType(ToscaType.INTEGER.name().toLowerCase()); List<PropertyConstraint> constraints3 = new ArrayList<>(); - List<String> range = new ArrayList<>(); + List<Object> range = new ArrayList<>(); range.add("4"); range.add("1"); InRangeConstraint propertyConstraint3 = new InRangeConstraint(range); @@ -593,7 +593,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { propertyDefinition.setDescription(PROP + "_" + value); propertyDefinition.setType(ToscaType.INTEGER.name().toLowerCase()); List<PropertyConstraint> constraints = new ArrayList<>(); - List<String> range = new ArrayList<>(); + List<Object> range = new ArrayList<>(); range.add("1"); range.add("4"); InRangeConstraint propertyConstraint = new InRangeConstraint(range); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraintTest.java index 6d9a4c4e3a..7f35aff071 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraintTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,29 +20,91 @@ package org.openecomp.sdc.be.model.tosca.constraints; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; public class EqualConstraintTest { - private EqualConstraint createTestSubject() { - return new EqualConstraint(""); - } + private EqualConstraint createStringTestSubject() { + return new EqualConstraint("test"); + } - + private EqualConstraint createIntegerTestSubject() { + return new EqualConstraint(418); + } - - @Test - public void testValidate() throws Exception { - EqualConstraint testSubject; - Object propertyValue = null; + @Test + public void testGetEqual() { + EqualConstraint testSubject = createStringTestSubject(); + Object result = testSubject.getEqual(); - // test 1 - testSubject = createTestSubject(); - propertyValue = null; - testSubject.validate(propertyValue); - } + assertEquals("test", result); + } - + @Test + public void testSetEqual() { + EqualConstraint testSubject = createStringTestSubject(); + testSubject.setEqual("test2"); + Object result = testSubject.getEqual(); + assertEquals("test2", result); + } + + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + EqualConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + EqualConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + EqualConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + EqualConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertFalse(validTypes); + } + + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + EqualConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); + + String expectedMessage = + "equal constraint has invalid values <" + testSubject.getEqual() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + EqualConstraint testSubject = createIntegerTestSubject(); + + testSubject.changeConstraintValueTypeTo("string"); + Object result = testSubject.getEqual(); + + assertTrue(result instanceof String); + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraintTest.java new file mode 100644 index 0000000000..d5d8fa7b35 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraintTest.java @@ -0,0 +1,109 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.tosca.constraints; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; + +public class GreaterOrEqualConstraintTest { + + private GreaterOrEqualConstraint createStringTestSubject() { + return new GreaterOrEqualConstraint("test"); + } + + private GreaterOrEqualConstraint createIntegerTestSubject() { + return new GreaterOrEqualConstraint(418); + } + + @Test + public void testGetGreaterOrEqualThan() { + GreaterOrEqualConstraint testSubject = createStringTestSubject(); + Object result = testSubject.getGreaterOrEqual(); + + assertEquals("test", result); + } + + @Test + public void testSetGreaterOrEqual() { + GreaterOrEqualConstraint testSubject = createStringTestSubject(); + testSubject.setGreaterOrEqual("test2"); + Object result = testSubject.getGreaterOrEqual(); + + assertEquals("test2", result); + } + + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterOrEqualConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterOrEqualConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterOrEqualConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterOrEqualConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertFalse(validTypes); + } + + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + GreaterOrEqualConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); + + String expectedMessage = + "greaterOrEqual constraint has invalid values <" + testSubject.getGreaterOrEqual() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterOrEqualConstraint testSubject = createIntegerTestSubject(); + + testSubject.changeConstraintValueTypeTo("string"); + Object result = testSubject.getGreaterOrEqual(); + + assertTrue(result instanceof String); + } +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java index dd79d80a79..41bc94f661 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,37 +20,91 @@ package org.openecomp.sdc.be.model.tosca.constraints; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; public class GreaterThanConstraintTest { - private GreaterThanConstraint createTestSubject() { - return new GreaterThanConstraint(""); - } + private GreaterThanConstraint createStringTestSubject() { + return new GreaterThanConstraint("test"); + } + + private GreaterThanConstraint createIntegerTestSubject() { + return new GreaterThanConstraint(418); + } + + @Test + public void testGetGreaterThan() { + GreaterThanConstraint testSubject = createStringTestSubject(); + Object result = testSubject.getGreaterThan(); + + assertEquals("test", result); + } + + @Test + public void testSetGreaterThan() { + GreaterThanConstraint testSubject = createStringTestSubject(); + testSubject.setGreaterThan("test2"); + Object result = testSubject.getGreaterThan(); + + assertEquals("test2", result); + } + + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterThanConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterThanConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterThanConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertTrue(validTypes); + } + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterThanConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertFalse(validTypes); + } + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + GreaterThanConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); - + String expectedMessage = + "greaterThan constraint has invalid values <" + testSubject.getGreaterThan() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); - - @Test - public void testGetGreaterThan() throws Exception { - GreaterThanConstraint testSubject; - String result; + assertTrue(actualMessage.contains(expectedMessage)); + } - // default test - testSubject = createTestSubject(); - result = testSubject.getGreaterThan(); - } + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + GreaterThanConstraint testSubject = createIntegerTestSubject(); - - @Test - public void testSetGreaterThan() throws Exception { - GreaterThanConstraint testSubject; - String greaterThan = ""; + testSubject.changeConstraintValueTypeTo("string"); + Object result = testSubject.getGreaterThan(); - // default test - testSubject = createTestSubject(); - testSubject.setGreaterThan(greaterThan); - } + assertTrue(result instanceof String); + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java index 9d14bfc72b..8eff6f7cdc 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,59 +20,144 @@ package org.openecomp.sdc.be.model.tosca.constraints; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; public class InRangeConstraintTest { - private InRangeConstraint createTestSubject() { - return new InRangeConstraint(null); - } - - - - - - @Test - public void testGetRangeMinValue() throws Exception { - InRangeConstraint testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getRangeMinValue(); - } - - - @Test - public void testSetRangeMinValue() throws Exception { - InRangeConstraint testSubject; - String minValue = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setRangeMinValue(minValue); - } - - - @Test - public void testGetRangeMaxValue() throws Exception { - InRangeConstraint testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getRangeMaxValue(); - } - - - @Test - public void testSetRangeMaxValue() throws Exception { - InRangeConstraint testSubject; - String maxValue = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setRangeMaxValue(maxValue); - } + private InRangeConstraint createStringTestSubject() { + List<Object> validValues = new ArrayList<>(); + validValues.add("test1"); + validValues.add("test10"); + return new InRangeConstraint(validValues); + } + + private InRangeConstraint createIntegerTestSubject() { + List<Object> validValues = new ArrayList<>(); + validValues.add(1); + validValues.add(10); + return new InRangeConstraint(validValues); + } + + @Test + public void testGetInRange() { + InRangeConstraint testSubject = createStringTestSubject(); + List<Object> result = testSubject.getInRange(); + + assertFalse(result.isEmpty()); + assertEquals("test1", result.get(0)); + assertEquals("test10", result.get(1)); + } + + @Test + public void testSetInRange() { + InRangeConstraint testSubject = createStringTestSubject(); + List<Object> validValues = new ArrayList<>(); + validValues.add("test21"); + validValues.add("test30"); + testSubject.setInRange(validValues); + List<Object> result = testSubject.getInRange(); + + assertEquals(2, result.size()); + assertEquals("test21", result.get(0)); + assertEquals("test30", result.get(1)); + } + + @Test + public void testGetRangeMinValue() throws Exception { + InRangeConstraint testSubject = createIntegerTestSubject(); + Object result = testSubject.getRangeMinValue(); + + assertEquals(1, result); + } + + @Test + public void testSetRangeMinValue() throws Exception { + InRangeConstraint testSubject = createIntegerTestSubject(); + testSubject.setRangeMinValue(21); + + Object result = testSubject.getRangeMinValue(); + + assertEquals(21, result); + } + + @Test + public void testGetRangeMaxValue() throws Exception { + InRangeConstraint testSubject = createIntegerTestSubject(); + Object result = testSubject.getRangeMaxValue(); + + assertEquals(10, result); + } + + @Test + public void testSetRangeMaxValue() throws Exception { + InRangeConstraint testSubject = createIntegerTestSubject(); + testSubject.setRangeMaxValue(30); + + Object result = testSubject.getRangeMaxValue(); + + assertEquals(30, result); + } + + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + InRangeConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + InRangeConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + InRangeConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + InRangeConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + + assertFalse(validTypes); + } + + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + InRangeConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); + String expectedMessage = + "inRange constraint has invalid values <" + testSubject.getInRange() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + InRangeConstraint testSubject = createIntegerTestSubject(); + testSubject.changeConstraintValueTypeTo("string"); + List<Object> result = testSubject.getInRange(); + + result.forEach(value -> assertTrue(value instanceof String)); + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraintTest.java index ef567d9672..aae21f0335 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraintTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,39 +20,91 @@ package org.openecomp.sdc.be.model.tosca.constraints; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; public class LessOrEqualConstraintTest { - private LessOrEqualConstraint createTestSubject() { - return new LessOrEqualConstraint(""); - } + private LessOrEqualConstraint createStringTestSubject() { + return new LessOrEqualConstraint("test"); + } - + private LessOrEqualConstraint createIntegerTestSubject() { + return new LessOrEqualConstraint(418); + } - + @Test + public void testGetLessOrEqualThan() { + LessOrEqualConstraint testSubject = createStringTestSubject(); + Object result = testSubject.getLessOrEqual(); + assertEquals("test", result); + } - - @Test - public void testGetLessOrEqual() throws Exception { - LessOrEqualConstraint testSubject; - String result; + @Test + public void testSetLessOrEqual() { + LessOrEqualConstraint testSubject = createStringTestSubject(); + testSubject.setLessOrEqual("test2"); + Object result = testSubject.getLessOrEqual(); - // default test - testSubject = createTestSubject(); - result = testSubject.getLessOrEqual(); - } + assertEquals("test2", result); + } - - @Test - public void testSetLessOrEqual() throws Exception { - LessOrEqualConstraint testSubject; - String lessOrEqual = ""; + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + LessOrEqualConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertTrue(validTypes); + } - // default test - testSubject = createTestSubject(); - testSubject.setLessOrEqual(lessOrEqual); - } + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + LessOrEqualConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + LessOrEqualConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + LessOrEqualConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertFalse(validTypes); + } + + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + LessOrEqualConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); + + String expectedMessage = + "lessOrEqual constraint has invalid values <" + testSubject.getLessOrEqual() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + LessOrEqualConstraint testSubject = createIntegerTestSubject(); + + testSubject.changeConstraintValueTypeTo("string"); + Object result = testSubject.getLessOrEqual(); + + assertTrue(result instanceof String); + } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraintTest.java new file mode 100644 index 0000000000..6736452d4d --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraintTest.java @@ -0,0 +1,109 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.tosca.constraints; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; + +public class LessThanConstraintTest { + + private LessThanConstraint createStringTestSubject() { + return new LessThanConstraint("test"); + } + + private LessThanConstraint createIntegerTestSubject() { + return new LessThanConstraint(418); + } + + @Test + public void testGetLessThan() { + LessThanConstraint testSubject = createStringTestSubject(); + Object result = testSubject.getLessThan(); + + assertEquals("test", result); + } + + @Test + public void testSetLessThan() { + LessThanConstraint testSubject = createStringTestSubject(); + testSubject.setLessThan("test2"); + Object result = testSubject.getLessThan(); + + assertEquals("test2", result); + } + + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + LessThanConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + LessThanConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + LessThanConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + LessThanConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertFalse(validTypes); + } + + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + LessThanConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); + + String expectedMessage = + "lessThan constraint has invalid values <" + testSubject.getLessThan() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + LessThanConstraint testSubject = createIntegerTestSubject(); + + testSubject.changeConstraintValueTypeTo("string"); + Object result = testSubject.getLessThan(); + + assertTrue(result instanceof String); + } +} diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraintTest.java index 69f67b3669..01450e2632 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/ValidValuesConstraintTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,41 +20,114 @@ package org.openecomp.sdc.be.model.tosca.constraints; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; public class ValidValuesConstraintTest { - private ValidValuesConstraint createTestSubject() { - return new ValidValuesConstraint(null); - } + private ValidValuesConstraint createStringTestSubject() { + List<Object> validValues = new ArrayList<>(); + validValues.add("test1"); + validValues.add("test2"); + validValues.add("test3"); + validValues.add("test4"); + return new ValidValuesConstraint(validValues); + } + + private ValidValuesConstraint createIntegerTestSubject() { + List<Object> validValues = new ArrayList<>(); + validValues.add(1); + validValues.add(2); + validValues.add(3); + validValues.add(4); + return new ValidValuesConstraint(validValues); + } + + @Test + public void testGetValidValues() { + ValidValuesConstraint testSubject = createStringTestSubject(); + List<Object> result = testSubject.getValidValues(); + + assertFalse(result.isEmpty()); + assertEquals("test1", result.get(0)); + assertEquals("test4", result.get(3)); + } + + @Test + public void testSetValidValues() { + ValidValuesConstraint testSubject = createStringTestSubject(); + List<Object> validValues = new ArrayList<>(); + validValues.add("test5"); + validValues.add("test6"); + validValues.add("test7"); + validValues.add("test8"); + testSubject.setValidValues(validValues); + + List<Object> result = testSubject.getValidValues(); + + assertEquals(4, result.size()); + assertEquals("test5", result.get(0)); + assertEquals("test8", result.get(3)); + } + + @Test + public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + ValidValuesConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertTrue(validTypes); + } + + @Test + public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + ValidValuesConstraint testSubject = createStringTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertFalse(validTypes); + } + + @Test + public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + ValidValuesConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("integer"); + assertTrue(validTypes); + } - + @Test + public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + ValidValuesConstraint testSubject = createIntegerTestSubject(); + Boolean validTypes = testSubject.validateValueType("string"); + assertFalse(validTypes); + } - + @Test + public void testChangeStringConstraintValueTypeToIntegerThrow() { + String propertyType = "integer"; + ValidValuesConstraint testSubject = createStringTestSubject(); + Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { + testSubject.changeConstraintValueTypeTo(propertyType); + }); + String expectedMessage = + "validValues constraint has invalid values <" + testSubject.getValidValues() + "> property type is <" + propertyType + ">"; + String actualMessage = exception.getMessage(); - - @Test - public void testGetValidValues() throws Exception { - ValidValuesConstraint testSubject; - List<String> result; + assertTrue(actualMessage.contains(expectedMessage)); + } - // default test - testSubject = createTestSubject(); - result = testSubject.getValidValues(); - } + @Test + public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + ValidValuesConstraint testSubject = createIntegerTestSubject(); - - @Test - public void testSetValidValues() throws Exception { - ValidValuesConstraint testSubject; - List<String> validValues = null; + testSubject.changeConstraintValueTypeTo("string"); + List<Object> result = testSubject.getValidValues(); - // default test - testSubject = createTestSubject(); - testSubject.setValidValues(validValues); - } + result.forEach(value -> assertTrue(value instanceof String)); + } } |