summaryrefslogtreecommitdiffstats
path: root/common-parameters/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-07 10:20:20 -0400
committerJim Hahn <jrh3@att.com>2019-06-07 10:20:20 -0400
commite671e9fa5d09ec696cb24aeefaf10ddbc7c705d7 (patch)
tree11b6367c23d8b689c5120e0d1779f6e23616df3c /common-parameters/src/test/java
parentc657a28325092a721f2d8d9bb7991ae88d2b237e (diff)
Add @Max annotation to paramater validation code
Change-Id: I928eeb6bf52cb9e825db456278ce8bff449c692c Issue-ID: POLICY-1762 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'common-parameters/src/test/java')
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
index 8adf1165..eb673222 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
@@ -30,6 +30,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.Test;
+import org.onap.policy.common.parameters.annotations.Max;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@@ -50,6 +51,7 @@ public class TestValidation {
private static final String NOT_NULL_OBJECT_NAME = "notNullObject";
private static final String NOT_NULL_STRING_NAME = "notNullString";
private static final String MIN_LONG_NAME = "minLong";
+ private static final String MAX_LONG_NAME = "maxLong";
@NotNull
private String notNullString;
@@ -66,6 +68,9 @@ public class TestValidation {
@Min(value = 10)
private long minLong;
+ @Max(value = 10)
+ private long maxLong;
+
@Test
public void testValidationOk() throws IOException {
TestParametersL00 l0Parameters = new TestParametersL00("l0Parameters");
@@ -362,6 +367,26 @@ public class TestValidation {
assertEquals(ValidationStatus.CLEAN, result.getStatus());
}
+ @Test
+ public void testParameterValidationResult_Max() throws Exception {
+ ParameterValidationResult result =
+ new ParameterValidationResult(TestValidation.class.getDeclaredField(MAX_LONG_NAME), 11L);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals("field 'maxLong' type 'long' value '11' INVALID, must be <= 10\n".replace('\'', '"'),
+ result.getResult());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MAX_LONG_NAME), 20);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals("field 'maxLong' type 'long' value '20' INVALID, must be <= 10\n".replace('\'', '"'),
+ result.getResult());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MAX_LONG_NAME), 10L);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MAX_LONG_NAME), 9);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+ }
+
// these classes are used to test class-level annotations