summaryrefslogtreecommitdiffstats
path: root/models-pdp/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-12-17 12:07:14 -0500
committerJim Hahn <jrh3@att.com>2020-12-17 18:52:46 -0500
commit6345dce40405740dc09176c45dae03baeb939b8e (patch)
tree07804a2f9e2dfd1083975c79059346a9cf778b1d /models-pdp/src
parent4c4946e339942863e73e20726dd95aaacfcfb5a6 (diff)
Use ValidationResult for models v2.0
Policy models uses PfValidationXxx classes which are totally unrelated to ValidationResult in policy common. This precludes the use of various utility methods and annotations for doing validation. Modified policy models to use ValidationResult instead. This approach uses function calls, though a future approach could make use of annotations instead. Issue-ID: POLICY-2648 Change-Id: I9760f1dc46902ab6bef7f440f3caf5e951660a5d Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-pdp/src')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java44
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java63
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java16
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java81
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java42
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java24
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java31
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java6
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java64
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java50
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java14
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java8
12 files changed, 151 insertions, 292 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
index 5820a355b..d231fe7e4 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,14 +35,11 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -163,40 +160,19 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (key.getParentConceptKey().isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent of key is a null key"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("parent of key", key.getParentConceptKey()));
if (PfKey.NULL_KEY_NAME.equals(key.getParentLocalName())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "local name of parent of key is null"));
+ addResult(result, "local name of parent of key", key.getParentLocalName(), IS_NULL);
}
- if (pdpState == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "PDP state may not be null"));
- }
-
- if (healthy == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "PDP health status may not be null"));
- }
-
- if (message != null && StringUtils.isBlank(message)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "message may not be blank"));
- }
+ result.addResult(validateNotNull("pdpState", pdpState));
+ result.addResult(validateNotNull("healthy", healthy));
+ result.addResult(validateNotBlank("message", message, false));
return result;
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
index 67458cf5f..66d36d8d6 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
@@ -44,17 +44,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
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.PfReferenceKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -218,61 +215,21 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (description != null && StringUtils.isBlank(description)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "description may not be blank"));
- }
-
- if (pdpGroupState == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "pdpGroupState may not be null"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateNotBlank("description", description, false));
+ result.addResult(validateNotNull("pdpGroupState", pdpGroupState));
- if (properties != null) {
- validateProperties(result);
- }
+ validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotBlank);
- if (pdpSubGroups == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP group must have a list of PDP subgroups"));
- } else {
- for (JpaPdpSubGroup jpaPdpSubgroup : pdpSubGroups) {
- result = jpaPdpSubgroup.validate(result);
- }
- }
+ result.addResult(validateNotNull("pdpSubGroups", pdpSubGroups));
+ validateList(result, "pdpSubGroups", pdpSubGroups, Validated::validateNotNull);
return result;
}
- /**
- * Validate the properties.
- *
- * @param result where to place any new validation results
- */
- private void validateProperties(PfValidationResult result) {
-
- for (Entry<String, String> propertyEntry : properties.entrySet()) {
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property key may not be null or blank"));
- }
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property value may not be null or blank"));
- }
- }
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
index d08a19a6a..49163ee8c 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
@@ -3,6 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,14 +38,12 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.builder.CompareToBuilder;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
import org.onap.policy.models.pdp.concepts.PdpEngineWorkerStatistics;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
@@ -203,15 +202,10 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
}
@Override
- public PfValidationResult validate(@NonNull PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
+ result.addResult(validateKeyNotNull("key", key));
return result;
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
index 7d018860e..c3d172a85 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,7 +43,7 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
@@ -52,9 +52,7 @@ import org.onap.policy.models.base.PfKeyUse;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfSearchableKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
@@ -279,80 +277,33 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (key.getParentConceptKey().isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent of key is a null key"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("parent of key", key.getParentConceptKey()));
if (currentInstanceCount < 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "the current instance count of a PDP sub group may not be negative"));
+ addResult(result, "currentInstanceCount", currentInstanceCount, "is negative");
}
if (desiredInstanceCount < 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "the desired instance count of a PDP sub group may not be negative"));
- }
-
- if (properties != null) {
- for (Entry<String, String> propertyEntry : properties.entrySet()) {
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property key may not be null or blank"));
- }
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a property value may not be null or blank"));
- }
- }
+ addResult(result, "desiredInstanceCount", desiredInstanceCount, "is negative");
}
- return validateSubConcepts(result);
- }
+ validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotBlank);
- /**
- * Validate collections of sub concepts.
- *
- * @param result the result in which to store the validation result
- * @return the validation result including the results of this method
- */
- private PfValidationResult validateSubConcepts(PfValidationResult result) {
if (supportedPolicyTypes == null || supportedPolicyTypes.isEmpty()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP subgroup must support at least one policy type"));
+ addResult(result, "supportedPolicyTypes", supportedPolicyTypes, "is empty");
} else {
- for (PfSearchableKey supportedPolicyType : supportedPolicyTypes) {
- result = supportedPolicyType.validate(result);
- }
+ validateList(result, "supportedPolicyTypes", supportedPolicyTypes, Validated::validateNotNull);
}
- if (policies == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP subgroup must have a list of policies"));
- } else {
- for (PfConceptKey policyKey : policies) {
- result = policyKey.validate(result);
- }
- }
+ result.validateNotNull("policies", policies);
+ validateList(result, "policies", policies, Validated::validateNotNull);
- if (pdpInstances == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "a PDP subgroup must have a list of PDPs"));
- } else {
- for (JpaPdp jpaPdp : pdpInstances) {
- result = jpaPdp.validate(result);
- }
- }
+ result.validateNotNull("pdpInstances", pdpInstances);
+ validateList(result, "pdpInstances", pdpInstances, Validated::validateNotNull);
return result;
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
index 7ea7cd376..e496521b7 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
@@ -40,8 +40,6 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdp;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class provides the provision of information on PAP concepts in the database to callers.
@@ -49,10 +47,6 @@ import org.slf4j.LoggerFactory;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class PdpProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpProvider.class);
-
- // Recurring string constants
- private static final String NOT_VALID = "\" is not valid \n";
/**
* Get PDP groups.
@@ -96,11 +90,9 @@ public class PdpProvider {
JpaPdpGroup jpaPdpGroup = new JpaPdpGroup();
jpaPdpGroup.fromAuthorative(pdpGroup);
- PfValidationResult validationResult = jpaPdpGroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp group \"" + jpaPdpGroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpGroup.validate("PDP group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.create(jpaPdpGroup);
@@ -133,11 +125,9 @@ public class PdpProvider {
JpaPdpGroup jpaPdpGroup = new JpaPdpGroup();
jpaPdpGroup.fromAuthorative(pdpGroup);
- PfValidationResult validationResult = jpaPdpGroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp group \"" + jpaPdpGroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpGroup.validate("PDP group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpGroup);
@@ -171,11 +161,9 @@ public class PdpProvider {
final JpaPdpSubGroup jpaPdpSubgroup = new JpaPdpSubGroup(subGroupKey);
jpaPdpSubgroup.fromAuthorative(pdpSubGroup);
- PfValidationResult validationResult = jpaPdpSubgroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "PDP subgroup \"" + jpaPdpSubgroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpSubgroup.validate("PDP sub group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpSubgroup);
@@ -198,11 +186,9 @@ public class PdpProvider {
final JpaPdp jpaPdp = new JpaPdp(pdpKey);
jpaPdp.fromAuthorative(pdp);
- PfValidationResult validationResult = jpaPdp.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "PDP \"" + jpaPdp.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdp.validate("PDP");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdp);
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
index 3b1718090..7901246d7 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
@@ -3,6 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,16 +31,14 @@ import java.util.Map;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfTimestampKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
@@ -48,10 +47,7 @@ import org.slf4j.LoggerFactory;
* @author Ning Xi (ning.xi@est.tech)
*/
public class PdpStatisticsProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpStatisticsProvider.class);
-
// Recurring string constants
- private static final String NOT_VALID = "\" is not valid \n";
private static final String DESC_ORDER = "DESC";
/**
@@ -118,11 +114,9 @@ public class PdpStatisticsProvider {
JpaPdpStatistics jpaPdpStatistics = new JpaPdpStatistics();
jpaPdpStatistics.fromAuthorative(pdpStatistics);
- PfValidationResult validationResult = jpaPdpStatistics.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp statictics \"" + jpaPdpStatistics.getName() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpStatistics.validate("pdp statistics");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.create(jpaPdpStatistics);
@@ -156,11 +150,9 @@ public class PdpStatisticsProvider {
JpaPdpStatistics jpaPdpStatistics = new JpaPdpStatistics();
jpaPdpStatistics.fromAuthorative(pdpStatistics);
- PfValidationResult validationResult = jpaPdpStatistics.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp statistics \"" + jpaPdpStatistics.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpStatistics.validate("pdp statistics");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpStatistics);
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java
index a013addab..a4bf25209 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java
@@ -35,7 +35,6 @@ import java.util.List;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild;
@@ -130,44 +129,44 @@ public class JpaPdpGroupTest {
assertThatThrownBy(() -> {
testJpaPdpGroup.validate(null);
- }).hasMessageMatching("resultIn" + NULL_ERROR);
+ }).hasMessageMatching("fieldName" + NULL_ERROR);
- assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setPdpGroupState(PdpState.PASSIVE);
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setKey(PfConceptKey.getNullKey());
- assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", VERSION));
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setDescription(" ");
- assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setDescription(" A Description ");
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setDescription(null);
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setProperties(new LinkedHashMap<>());
testJpaPdpGroup.getProperties().put(null, null);
- assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.getProperties().remove(null);
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setProperties(new LinkedHashMap<>());
testJpaPdpGroup.getProperties().put("NullKey", null);
- assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.getProperties().remove("NullKey");
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
List<JpaPdpSubGroup> jpaPdpSubgroups = testJpaPdpGroup.getPdpSubGroups();
assertNotNull(jpaPdpSubgroups);
testJpaPdpGroup.setPdpSubGroups(null);
- assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setPdpSubGroups(new ArrayList<>());
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.setPdpSubGroups(jpaPdpSubgroups);
- assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpGroup.validate("").isValid());
JpaPdpGroup otherJpaPdpGroup = new JpaPdpGroup(testJpaPdpGroup);
assertEquals(0, testJpaPdpGroup.compareTo(otherJpaPdpGroup));
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
index b8d8d99a0..83cf85b8f 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +32,6 @@ import java.util.ArrayList;
import java.util.Date;
import org.junit.Test;
import org.onap.policy.models.base.PfTimestampKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
/**
@@ -92,11 +92,11 @@ public class JpaPdpStatisticsTest {
@Test
public void testValidate() {
JpaPdpStatistics nullKeyJpaPdpStat = new JpaPdpStatistics();
- assertFalse(nullKeyJpaPdpStat.validate(new PfValidationResult()).isOk());
+ assertFalse(nullKeyJpaPdpStat.validate("").isValid());
PdpStatistics pdpStat = createPdpStatistics();
JpaPdpStatistics jpaPdpStat2 = new JpaPdpStatistics(pdpStat);
- assertTrue(jpaPdpStat2.validate(new PfValidationResult()).isOk());
+ assertTrue(jpaPdpStat2.validate("").isValid());
}
@Test
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java
index cb27151f8..969b59c6d 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.pdp.persistence.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -36,7 +37,7 @@ import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfSearchableKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild;
@@ -138,82 +139,79 @@ public class JpaPdpSubGroupTest {
assertThatThrownBy(() -> {
testJpaPdpSubGroup.validate(null);
- }).hasMessageMatching("resultIn is marked .*ull but is null");
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
- .contains("INVALID:parent of key is a null key"));
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
+ assertThat(testJpaPdpSubGroup.validate("").getResult())
+ .contains("parent of key").contains(Validated.IS_A_NULL_KEY);
testJpaPdpSubGroup.getKey().setParentConceptKey(new PfConceptKey("Parent:1.0.0"));
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
- .contains("INVALID:parent of key is a null key"));
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
- .contains("INVALID:a PDP subgroup must support at least one policy type"));
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
+ assertThat(testJpaPdpSubGroup.validate("").getResult())
+ .doesNotContain("parent of key")
+ .contains("supportedPolicyTypes").contains("is empty");
testJpaPdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfSearchableKey("APolicyType:1.0.0"));
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
- .contains("INVALID:a PDP subgroup must support at least one policy type"));
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
PfReferenceKey savedKey = testJpaPdpSubGroup.getKey();
testJpaPdpSubGroup.setKey(PfReferenceKey.getNullKey());
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setKey(savedKey);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setProperties(new LinkedHashMap<>());
testJpaPdpSubGroup.getProperties().put(null, null);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.getProperties().remove(null);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setProperties(new LinkedHashMap<>());
testJpaPdpSubGroup.getProperties().put("NullKey", null);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.getProperties().remove("NullKey");
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setDesiredInstanceCount(-1);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setDesiredInstanceCount(0);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setProperties(null);
testJpaPdpSubGroup.setCurrentInstanceCount(-1);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setCurrentInstanceCount(0);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setProperties(null);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
List<PfSearchableKey> supportedPolicyTypes = testJpaPdpSubGroup.getSupportedPolicyTypes();
assertNotNull(supportedPolicyTypes);
testJpaPdpSubGroup.setSupportedPolicyTypes(null);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setSupportedPolicyTypes(supportedPolicyTypes);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
List<PfConceptKey> supportedPolicies = testJpaPdpSubGroup.getPolicies();
assertNotNull(supportedPolicies);
testJpaPdpSubGroup.setPolicies(null);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setPolicies(new ArrayList<>());
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setPolicies(supportedPolicies);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
List<JpaPdp> pdpInstances = testJpaPdpSubGroup.getPdpInstances();
assertNotNull(pdpInstances);
testJpaPdpSubGroup.setPdpInstances(null);
- assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setPdpInstances(new ArrayList<>());
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setPdpInstances(pdpInstances);
- assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdpSubGroup.validate("").isValid());
JpaPdpSubGroup otherJpaPdpSubGroup = new JpaPdpSubGroup(testJpaPdpSubGroup);
assertEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java
index 74a3c9e31..3102c5098 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.pdp.persistence.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -31,7 +32,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -115,48 +116,45 @@ public class JpaPdpTest {
assertThatThrownBy(() -> {
testJpaPdp.validate(null);
- }).hasMessageMatching("resultIn is marked .*ull but is null");
+ }).hasMessageMatching("fieldName is marked .*ull but is null");
- assertFalse(testJpaPdp.validate(new PfValidationResult()).isOk());
- assertTrue(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:parent of key is a null key"));
+ assertFalse(testJpaPdp.validate("").isValid());
+ assertThat(testJpaPdp.validate("").getResult())
+ .contains("parent").contains(Validated.IS_A_NULL_KEY);
testJpaPdp.getKey().setParentConceptKey(new PfConceptKey("Parent:1.0.0"));
- assertFalse(testJpaPdp.validate(new PfValidationResult()).isOk());
- assertFalse(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:parent of key is a null key"));
- assertTrue(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:local name of parent of key is null"));
+ assertFalse(testJpaPdp.validate("").isValid());
+ assertThat(testJpaPdp.validate("").getResult())
+ .doesNotContain("\"parent\"")
+ .contains("local name").contains(Validated.IS_NULL);
testJpaPdp.getKey().setParentLocalName("ParentLocal");
- assertFalse(testJpaPdp.validate(new PfValidationResult()).isOk());
- assertFalse(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:local name of parent of key is null"));
- assertTrue(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:PDP state may not be null"));
+ assertFalse(testJpaPdp.validate("").isValid());
+ assertThat(testJpaPdp.validate("").getResult())
+ .doesNotContain("local name")
+ .contains("pdpState").contains(Validated.IS_NULL);
testJpaPdp.setPdpState(PdpState.ACTIVE);
- assertFalse(testJpaPdp.validate(new PfValidationResult()).isOk());
- assertFalse(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:PDP state may not be null"));
- assertTrue(testJpaPdp.validate(new PfValidationResult()).toString()
- .contains("INVALID:PDP health status may not be null"));
+ assertFalse(testJpaPdp.validate("").isValid());
+ assertThat(testJpaPdp.validate("").getResult())
+ .doesNotContain("pdpState")
+ .contains("healthy").contains(Validated.IS_NULL);
testJpaPdp.setHealthy(PdpHealthStatus.HEALTHY);
- assertTrue(testJpaPdp.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdp.validate("").isValid());
PfReferenceKey savedKey = testJpaPdp.getKey();
testJpaPdp.setKey(PfReferenceKey.getNullKey());
- assertFalse(testJpaPdp.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdp.validate("").isValid());
testJpaPdp.setKey(savedKey);
- assertTrue(testJpaPdp.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdp.validate("").isValid());
testJpaPdp.setMessage(null);
- assertTrue(testJpaPdp.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdp.validate("").isValid());
testJpaPdp.setMessage("");
- assertFalse(testJpaPdp.validate(new PfValidationResult()).isOk());
+ assertFalse(testJpaPdp.validate("").isValid());
testJpaPdp.setMessage("Valid Message");
- assertTrue(testJpaPdp.validate(new PfValidationResult()).isOk());
+ assertTrue(testJpaPdp.validate("").isValid());
JpaPdp otherJpaPdp = new JpaPdp(testJpaPdp);
assertEquals(0, testJpaPdp.compareTo(otherJpaPdp));
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java
index 7dc5d3ae8..b6874726d 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
@@ -204,7 +205,8 @@ public class PdpProviderTest {
pdpGroups0.getGroups().get(0).setPdpGroupState(null);
assertThatThrownBy(() -> {
new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups());
- }).hasMessageContaining("INVALID:pdpGroupState may not be null");
+ }).hasMessageContaining("PDP group").hasMessageContaining("pdpGroupState")
+ .hasMessageContaining(Validated.IS_NULL);
}
@Test
@@ -269,7 +271,8 @@ public class PdpProviderTest {
pdpGroups0.getGroups().get(0).setPdpGroupState(null);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpGroups(pfDao, pdpGroups0.getGroups());
- }).hasMessageContaining("INVALID:pdpGroupState may not be null");
+ }).hasMessageContaining("PDP group").hasMessageContaining("pdpGroupState")
+ .hasMessageContaining(Validated.IS_NULL);
}
@Test
@@ -375,7 +378,8 @@ public class PdpProviderTest {
existingSubGroup.setDesiredInstanceCount(-1);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(pfDao, PDP_GROUP0, existingSubGroup);
- }).hasMessageContaining("INVALID:the desired instance count of a PDP sub group may not be negative");
+ }).hasMessageContaining("PDP sub group").hasMessageContaining("desiredInstanceCount")
+ .hasMessageContaining("is negative");
existingSubGroup.setDesiredInstanceCount(10);
}
@@ -473,7 +477,7 @@ public class PdpProviderTest {
existingPdp.setMessage("");
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, PDP_GROUP0, "APEX", existingPdp);
- }).hasMessageContaining("INVALID:message may not be blank");
+ }).hasMessageContaining("PDP").hasMessageContaining("message").hasMessageContaining(Validated.IS_BLANK);
existingPdp.setMessage("A Message");
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
index 904e5f135..d8eeab44f 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProviderTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +33,7 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
@@ -141,11 +143,13 @@ public class PdpStatisticsProviderTest {
assertThatThrownBy(() -> {
new PdpStatisticsProvider().createPdpStatistics(pfDao, pdpStatisticsNullList);
- }).hasMessageContaining("pdp statictics \"NULL\" is not valid");
+ }).hasMessageContaining("pdp statistics").hasMessageContaining("key")
+ .hasMessageContaining(Validated.IS_A_NULL_KEY);
assertThatThrownBy(() -> {
new PdpStatisticsProvider().updatePdpStatistics(pfDao, pdpStatisticsNullList);
- }).hasMessageContaining("pdp statistics \"NULL:0.0.0:0\" is not valid");
+ }).hasMessageContaining("pdp statistics").hasMessageContaining("key")
+ .hasMessageContaining(Validated.IS_A_NULL_KEY);
}
@Test