summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraintTest.java104
1 files changed, 79 insertions, 25 deletions
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);
+ }
}