summaryrefslogtreecommitdiffstats
path: root/models-base/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-12-18 19:01:52 -0500
committerJim Hahn <jrh3@att.com>2020-12-21 10:38:00 -0500
commit12fce55a66848bcc7f71430324b3a9051b8ce0d4 (patch)
treef8fdcb848f5b3bcfc07cc44f728bc51da620c6b3 /models-base/src/test/java
parent6345dce40405740dc09176c45dae03baeb939b8e (diff)
Use annotations to do validation
Modified models to use annotations instead of function calls for most field validations. Created a few new validation annotations for use within models. Per review comments: - renamed Key to VerifyKey - enhanced VerifyKey to imply "@Valid", unless disabled Issue-ID: POLICY-2648 Change-Id: I2b53f218b0a2ab1ed1f5e278816a3509f1408972 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-base/src/test/java')
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java6
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java6
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java19
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java4
4 files changed, 18 insertions, 17 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java
index 8d6b1b9f4..dc69e2e67 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java
@@ -37,6 +37,7 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.annotations.Pattern;
import org.onap.policy.models.base.PfKey.Compatibility;
import org.onap.policy.models.base.testconcepts.DummyPfKey;
@@ -268,10 +269,13 @@ public class PfKeyImplTest {
@Setter
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
- private static class MyKey extends PfKeyImpl {
+ public static class MyKey extends PfKeyImpl {
private static final long serialVersionUID = 1L;
+ @Pattern(regexp = NAME_REGEXP)
private String name;
+
+ @Pattern(regexp = VERSION_REGEXP)
private String version;
public MyKey(String name, String version) {
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java
index 8534d82a6..dab28f636 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java
@@ -434,12 +434,14 @@ public class ValidatedTest {
private final String text;
@Override
- public ValidationResult validate(String fieldName) {
+ public BeanValidationResult validate(String fieldName) {
if (TEXT.equals(text)) {
return null;
}
- return new ObjectValidationResult(fieldName, text, ValidationStatus.INVALID, NOT_SAME);
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
+ result.addResult(new ObjectValidationResult(fieldName, text, ValidationStatus.INVALID, NOT_SAME));
+ return result;
}
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
index 67a450702..548c26252 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
@@ -27,20 +27,25 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
@Data
@EqualsAndHashCode(callSuper = false)
public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
private static final long serialVersionUID = 1L;
+
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfConceptKey key;
+ @NotBlank
private String description;
@@ -101,16 +106,6 @@ public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuth
}
@Override
- public ValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = new BeanValidationResult(fieldName, this);
-
- result.addResult(validateKeyNotNull("key", key));
- result.addResult(validateNotBlank("description", description, false));
-
- return result;
- }
-
- @Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
index 5a5891ad6..015d1a950 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
@@ -24,7 +24,7 @@ package org.onap.policy.models.base.testconcepts;
import java.util.Arrays;
import java.util.List;
import lombok.NonNull;
-import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
@@ -75,7 +75,7 @@ public class DummyPfKey extends PfKey {
}
@Override
- public ValidationResult validate(@NonNull String fieldName) {
+ public BeanValidationResult validate(@NonNull String fieldName) {
return null;
}