summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-base/pom.xml5
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConcept.java13
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java49
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java22
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java15
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModel.java100
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java38
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfValidationMessage.java104
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java146
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/Validated.java377
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java25
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java37
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java10
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java34
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java42
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java645
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java133
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java24
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java6
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java12
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java10
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java10
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/DummyTimestampEntity.java9
-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
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java82
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java39
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java52
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java43
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java35
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java12
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java48
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java44
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java22
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java71
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java90
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java59
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java39
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java77
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java44
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java93
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java27
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java58
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java61
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java11
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java37
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java24
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java7
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java17
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java25
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java30
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java25
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java7
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java30
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java29
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java45
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java30
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java33
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java21
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java110
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java19
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java17
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java23
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java10
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java13
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java9
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java12
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java27
87 files changed, 1444 insertions, 2539 deletions
diff --git a/models-base/pom.xml b/models-base/pom.xml
index 75134b79a..cf9c27eef 100644
--- a/models-base/pom.xml
+++ b/models-base/pom.xml
@@ -33,6 +33,11 @@
<dependencies>
<dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>common-parameters</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models-errors</artifactId>
<version>${project.version}</version>
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
index 5273bd39e..394eb89f2 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.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.
@@ -30,7 +30,7 @@ import lombok.NonNull;
* and interfaces on all concepts that are sub-classes of this class.
*/
-public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
+public abstract class PfConcept extends Validated implements Serializable, Comparable<PfConcept> {
private static final long serialVersionUID = -7434939557282697490L;
/**
@@ -65,15 +65,6 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
public abstract List<PfKey> getKeys();
/**
- * Validate that this concept is structurally correct.
- *
- * @param result the parameter in which the result of the validation will be returned
- * @return the validation result that was passed in in the @{link result} field with the result of this validation
- * added
- */
- public abstract PfValidationResult validate(@NonNull final PfValidationResult result);
-
- /**
* Clean this concept, tidy up any superfluous information such as leading and trailing white space.
*/
public abstract void clean();
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
index 863a3ef02..484632f7c 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
@@ -45,7 +45,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
// @formatter:off
/**
@@ -241,19 +242,11 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
}
@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.equals(PfConceptKey.getNullKey())) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (!conceptMap.isEmpty()) {
- result = validateConceptMap(result);
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateConceptMap());
return result;
}
@@ -261,29 +254,31 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
/**
* Validate the concept map of the container.
*
- * @param resultIn the incoming validation results so far
- * @return the validation results with the results of this validation added
+ * @return the validation result
*/
- private PfValidationResult validateConceptMap(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ private ValidationResult validateConceptMap() {
+ BeanValidationResult result = new BeanValidationResult("conceptMap", conceptMap);
for (final Entry<PfConceptKey, C> conceptEntry : conceptMap.entrySet()) {
+ BeanValidationResult result2 = null;
+
if (conceptEntry.getKey().equals(PfConceptKey.getNullKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key on concept entry " + conceptEntry.getKey() + " may not be the null key"));
+ addResult(result, "key on concept entry", conceptEntry.getKey(), IS_A_NULL_KEY);
} else if (conceptEntry.getValue() == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "value on concept entry " + conceptEntry.getKey() + " may not be null"));
+ result2 = new BeanValidationResult(conceptEntry.getKey().getId(), conceptEntry.getKey());
+ addResult(result2, "value", conceptEntry.getValue(), IS_NULL);
} else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key on concept entry key " + conceptEntry.getKey() + " does not equal concept value key "
- + conceptEntry.getValue().getKey()));
- result = conceptEntry.getValue().validate(result);
+ result2 = new BeanValidationResult(conceptEntry.getKey().getId(), conceptEntry.getKey());
+ addResult(result2, "value", conceptEntry.getValue(), "does not equal concept key");
+ result2.addResult(conceptEntry.getValue().validate("value"));
} else {
- result = conceptEntry.getValue().validate(result);
+ result2 = new BeanValidationResult(conceptEntry.getKey().getId(), conceptEntry.getKey());
+ result2.addResult(conceptEntry.getValue().validate("value"));
}
+
+ result.addResult(result2);
}
- return result;
+ return (result.isClean() ? null : result);
}
@Override
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java
index 81066c37c..3cbef75f9 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -26,8 +26,9 @@ import java.util.List;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* A key, upon which other key subclasses can be built, providing implementations of the methods.
@@ -241,20 +242,11 @@ public abstract class PfKeyImpl extends PfKey {
}
@Override
- public PfValidationResult validate(final PfValidationResult result) {
- final String nameValidationErrorMessage =
- Assertions.getStringParameterValidationMessage(NAME_TOKEN, getName(), getNameRegEx());
- if (nameValidationErrorMessage != null) {
- result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "name invalid-" + nameValidationErrorMessage));
- }
+ public ValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- final String versionValidationErrorMessage =
- Assertions.getStringParameterValidationMessage(VERSION_TOKEN, getVersion(), getVersionRegEx());
- if (versionValidationErrorMessage != null) {
- result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "version invalid-" + versionValidationErrorMessage));
- }
+ result.addResult(validateRegex(NAME_TOKEN, getName(), getNameRegEx()));
+ result.addResult(validateRegex(VERSION_TOKEN, getVersion(), getVersionRegEx()));
return result;
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java
index 03873236c..616284daf 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.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,8 +25,9 @@ import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* This class records a usage of a key in the system. When the list of keys being used by a concept
@@ -134,12 +135,10 @@ public class PfKeyUse extends PfKey {
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult result) {
- if (usedKey.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(usedKey, this.getClass(), ValidationResult.INVALID,
- "usedKey is a null key"));
- }
- return usedKey.validate(result);
+ public ValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
+ result.addResult(validateKeyNotNull("usedKey", usedKey));
+ return result;
}
@Override
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
index 340f4e3b2..c87874774 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.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.
@@ -32,8 +32,10 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* This class is the base class for all models in the Policy Framework. All model classes inherit
@@ -56,7 +58,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class PfModel extends PfConcept {
- private static final String IS_A_NULL_KEY = " is a null key";
+ private static final String KEYS_TOKEN = "keys";
private static final long serialVersionUID = -771659065637205430L;
@@ -110,15 +112,10 @@ public abstract class PfModel extends PfConcept {
}
@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);
+ result.addResult(validateKeyNotNull("key", key));
// Key consistency check
final Set<PfConceptKey> artifactKeySet = new TreeSet<>();
@@ -128,9 +125,9 @@ public abstract class PfModel extends PfConcept {
for (final PfKey pfKey : this.getKeys()) {
// Check for the two type of keys we have
if (pfKey instanceof PfConceptKey) {
- result = validateArtifactKeyInModel((PfConceptKey) pfKey, artifactKeySet, result);
+ validateArtifactKeyInModel((PfConceptKey) pfKey, artifactKeySet, result);
} else if (pfKey instanceof PfReferenceKey) {
- result = validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result);
+ validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result);
} else {
// It must be a PfKeyUse, nothing else is legal
usedKeySet.add((PfKeyUse) pfKey);
@@ -140,12 +137,11 @@ public abstract class PfModel extends PfConcept {
// Check all reference keys have correct parent keys
for (final PfReferenceKey referenceKey : referenceKeySet) {
if (!artifactKeySet.contains(referenceKey.getParentConceptKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent artifact key not found for reference key " + referenceKey));
+ addResult(result, "reference key", referenceKey, "parent artifact key not found");
}
}
- result = validateKeyUses(usedKeySet, artifactKeySet, referenceKeySet, result);
+ validateKeyUses(usedKeySet, artifactKeySet, referenceKeySet, result);
return result;
}
@@ -156,78 +152,69 @@ public abstract class PfModel extends PfConcept {
* @param artifactKey The artifact key to check
* @param artifactKeySet The set of artifact keys encountered so far, this key is appended to
* the set
- * @param result The validation result to append to
- * @return the result of the validation
+ * @param result where to add the results
*/
- private PfValidationResult validateArtifactKeyInModel(final PfConceptKey artifactKey,
- final Set<PfConceptKey> artifactKeySet, final PfValidationResult result) {
- // Null key check
- if (artifactKey.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key " + artifactKey + IS_A_NULL_KEY));
- }
+ private void validateArtifactKeyInModel(final PfConceptKey artifactKey,
+ final Set<PfConceptKey> artifactKeySet, final BeanValidationResult result) {
+
+ result.addResult(validateKeyNotNull(KEYS_TOKEN, artifactKey));
+
+ BeanValidationResult result2 = new BeanValidationResult(KEYS_TOKEN, artifactKey);
// Null key name start check
if (artifactKey.getName().toUpperCase().startsWith(PfKey.NULL_KEY_NAME)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key " + artifactKey + " name starts with keyword " + PfKey.NULL_KEY_NAME));
+ addResult(result2, "name of " + artifactKey.getId(), artifactKey.getName(),
+ "starts with keyword " + PfKey.NULL_KEY_NAME);
}
// Unique key check
if (artifactKeySet.contains(artifactKey)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "duplicate key " + artifactKey + " found"));
+ addResult(result, KEYS_TOKEN, artifactKey, "duplicate key");
} else {
artifactKeySet.add(artifactKey);
}
-
- return result;
}
/**
* Check for consistent usage of a reference key in the model.
*
- * @param artifactKey The reference key to check
+ * @param referenceKey The reference key to check
* @param referenceKeySet The set of reference keys encountered so far, this key is appended to
* the set
- * @param result The validation result to append to
- * @return the result of the validation
+ * @param result where to add the results
*/
- private PfValidationResult validateReferenceKeyInModel(final PfReferenceKey referenceKey,
- final Set<PfReferenceKey> referenceKeySet, final PfValidationResult result) {
+ private void validateReferenceKeyInModel(final PfReferenceKey referenceKey,
+ final Set<PfReferenceKey> referenceKeySet, final BeanValidationResult result) {
// Null key check
if (referenceKey.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key " + referenceKey + IS_A_NULL_KEY));
+ addResult(result, KEYS_TOKEN, referenceKey, IS_A_NULL_KEY);
}
+ BeanValidationResult result2 = new BeanValidationResult(KEYS_TOKEN, referenceKey);
+
// Null parent key check
if (referenceKey.getParentConceptKey().isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parent artifact key of key " + referenceKey + IS_A_NULL_KEY));
+ addResult(result2, "parent key of " + referenceKey.getId(), referenceKey.getParentConceptKey().getId(),
+ IS_A_NULL_KEY);
}
// Null local name check
if (referenceKey.getLocalName().equals(PfKey.NULL_KEY_NAME)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key " + referenceKey + " has a null local name"));
+ addResult(result2, "local name of " + referenceKey.getId(), referenceKey.getLocalName(), IS_NULL);
}
// Null key name start check
if (referenceKey.getParentConceptKey().getName().toUpperCase().startsWith(PfKey.NULL_KEY_NAME)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key " + referenceKey + " parent name starts with keyword " + PfKey.NULL_KEY_NAME));
+ addResult(result2, "parent name of " + referenceKey.getId(), referenceKey.getParentConceptKey().getName(),
+ "starts with keyword " + PfKey.NULL_KEY_NAME);
}
// Unique key check
if (referenceKeySet.contains(referenceKey)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "duplicate key " + referenceKey + " found"));
+ addResult(result, KEYS_TOKEN, referenceKey, "duplicate key");
} else {
referenceKeySet.add(referenceKey);
}
-
- return result;
}
/**
@@ -238,29 +225,26 @@ public abstract class PfModel extends PfConcept {
* the set
* @param referenceKeySet The set of reference keys encountered so far, this key is appended to
* the set
- * @param result The validation result to append to
- * @return the result of the validation
+ * @param result where to add the results
*/
- private PfValidationResult validateKeyUses(final Set<PfKeyUse> usedKeySet, final Set<PfConceptKey> artifactKeySet,
- final Set<PfReferenceKey> referenceKeySet, final PfValidationResult result) {
+ private void validateKeyUses(final Set<PfKeyUse> usedKeySet, final Set<PfConceptKey> artifactKeySet,
+ final Set<PfReferenceKey> referenceKeySet, final BeanValidationResult result) {
// Check all key uses
for (final PfKeyUse usedKey : usedKeySet) {
if (usedKey.getKey() instanceof PfConceptKey) {
// PfConceptKey usage, check the key exists
if (!artifactKeySet.contains(usedKey.getKey())) {
- result.addValidationMessage(new PfValidationMessage(usedKey.getKey(), this.getClass(),
- ValidationResult.INVALID, "an artifact key used in the model is not defined"));
+ result.addResult(new ObjectValidationResult("artifact key", usedKey.getId(),
+ ValidationStatus.INVALID, NOT_DEFINED));
}
} else {
// PfReferenceKey usage, check the key exists
if (!referenceKeySet.contains(usedKey.getKey())) {
- result.addValidationMessage(new PfValidationMessage(usedKey.getKey(), this.getClass(),
- ValidationResult.INVALID, "a reference key used in the model is not defined"));
+ result.addResult(new ObjectValidationResult("reference key", usedKey.getId(),
+ ValidationStatus.INVALID, NOT_DEFINED));
}
}
}
-
- return result;
}
@Override
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
index 7984e4297..83403ac43 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.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.
@@ -28,8 +28,9 @@ import javax.persistence.Embeddable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* A reference key identifies entities in the system that are contained in other entities. Every contained concept in
@@ -339,34 +340,13 @@ public class PfReferenceKey extends PfKey {
}
@Override
- public PfValidationResult validate(final PfValidationResult result) {
- final String parentNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(PARENT_KEY_NAME,
- parentKeyName, NAME_REGEXP);
- if (parentNameValidationErrorMessage != null) {
- result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "parentKeyName invalid-" + parentNameValidationErrorMessage));
- }
-
- final String parentKeyVersionValidationErrorMessage = Assertions
- .getStringParameterValidationMessage(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP);
- if (parentKeyVersionValidationErrorMessage != null) {
- result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "parentKeyVersion invalid-" + parentKeyVersionValidationErrorMessage));
- }
+ public ValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- final String parentLocalNameValidationErrorMessage = Assertions
- .getStringParameterValidationMessage(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP);
- if (parentLocalNameValidationErrorMessage != null) {
- result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "parentLocalName invalid-" + parentLocalNameValidationErrorMessage));
- }
-
- final String localNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(LOCAL_NAME,
- localName, LOCAL_NAME_REGEXP);
- if (localNameValidationErrorMessage != null) {
- result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
- "localName invalid-" + localNameValidationErrorMessage));
- }
+ result.addResult(validateRegex(PARENT_KEY_NAME, parentKeyName, NAME_REGEXP));
+ result.addResult(validateRegex(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP));
+ result.addResult(validateRegex(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP));
+ result.addResult(validateRegex(LOCAL_NAME, localName, LOCAL_NAME_REGEXP));
return result;
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidationMessage.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidationMessage.java
deleted file mode 100644
index cd8b08bfa..000000000
--- a/models-base/src/main/java/org/onap/policy/models/base/PfValidationMessage.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 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.
- * 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.onap.policy.models.base;
-
-import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
-
-/**
- * A validation message is created for each validation observation observed during validation of a
- * concept. The message holds the key and the class of the concept on which the observation was made
- * as well as the type of observation and a message describing the observation.
- */
-public class PfValidationMessage {
- private final PfKey observedKey;
- private ValidationResult validationResult = ValidationResult.VALID;
- private final String observedClass;
- private final String message;
-
- /**
- * Create an validation observation with the given fields.
- *
- * @param observedKey the key of the class on which the validation observation was made
- * @param observedClass the class on which the validation observation was made
- * @param validationResult the type of observation made
- * @param message a message describing the observation
- */
- public PfValidationMessage(final PfKey observedKey, final Class<?> observedClass,
- final ValidationResult validationResult, final String message) {
- Assertions.argumentNotNull(observedKey, "observedKey may not be null");
- Assertions.argumentNotNull(observedClass, "observedClass may not be null");
- Assertions.argumentNotNull(validationResult, "validationResult may not be null");
- Assertions.argumentNotNull(message, "message may not be null");
-
- this.observedKey = observedKey;
- this.observedClass = observedClass.getName();
- this.validationResult = validationResult;
- this.message = message;
- }
-
- /**
- * Gets the key of the observation.
- *
- * @return the key of the observation
- */
- public PfKey getObservedKey() {
- return observedKey;
- }
-
- /**
- * Gets the observed class.
- *
- * @return the observed class
- */
- public String getObservedClass() {
- return observedClass;
- }
-
- /**
- * Gets the type of observation made.
- *
- * @return the type of observation made
- */
- public ValidationResult getValidationResult() {
- return validationResult;
- }
-
- /**
- * Get a description of the observation.
- *
- * @return the observation description
- */
- public String getMessage() {
- return message;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return observedKey.toString() + ':' + observedClass + ':' + validationResult.name() + ':' + message;
- }
-}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java
deleted file mode 100644
index bbac3b7e5..000000000
--- a/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 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.onap.policy.models.base;
-
-import java.util.LinkedList;
-import java.util.List;
-import lombok.Getter;
-
-/**
- * This class records the result of a validation and holds all validation observation messages.
- */
-@Getter
-public class PfValidationResult {
- /**
- * The ValidationResult enumeration describes the severity of a validation result.
- */
- public enum ValidationResult {
- /** No problems or observations were detected during validation. */
- VALID,
- /**
- * Observations were made on a concept (such as blank descriptions) of a nature that will not affect the use of
- * the concept.
- */
- OBSERVATION,
- /**
- * Warnings were made on a concept (such as defined but unused concepts) of a nature that may affect the use of
- * the concept.
- */
- WARNING,
- /**
- * Errors were detected on a concept (such as referenced but undefined concepts) of a nature that will affect
- * the use of the concept.
- */
- INVALID
- }
-
- // The actual verification result
- private ValidationResult validationResult = ValidationResult.VALID;
-
- // Messages collected during the verification process
- private final List<PfValidationMessage> messageList = new LinkedList<>();
-
- /**
- * Check if a validation reported a valid concept, returns true if the model is usable (that is, even if the model
- * has warnings or observations).
- *
- * @return true, if the concept is reported as valid and can be used
- */
- public boolean isValid() {
- return validationResult != ValidationResult.INVALID;
- }
-
- /**
- * Check if a validation reported a concept with no errors or warnings, returns true if the model is OK to use.
- *
- * @return true, if the concept has no warnings or errors
- */
- public boolean isOk() {
- return validationResult == ValidationResult.VALID || validationResult == ValidationResult.OBSERVATION;
- }
-
-
- /**
- * Append a validation result to another validation result.
- *
- * @param result2Append the result to append to the current validation result
- */
- public void append(final PfValidationResult result2Append) {
- for (PfValidationMessage message : result2Append.getMessageList()) {
- addValidationMessage(message);
- }
- }
-
- /**
- * Adds a validation message to the validation result, used by validate() implementations on {@link PfConcept}
- * subclasses to report validaiton observations.
- *
- * @param validationMessage the validation message
- */
- public void addValidationMessage(final PfValidationMessage validationMessage) {
- messageList.add(validationMessage);
-
- // Check if the incoming message has a more sever status than the
- // current one on the overall validation result,
- // if so, the overall result goes to that level
- if (validationMessage.getValidationResult().ordinal() > validationResult.ordinal()) {
- validationResult = validationMessage.getValidationResult();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
-
- switch (validationResult) {
- case VALID:
-
- builder.append("***validation of model successful***");
- return builder.toString();
- case OBSERVATION:
-
- builder.append("\n***observations noted during validation of model***\n");
- break;
- case WARNING:
-
- builder.append("\n***warnings issued during validation of model***\n");
- break;
- case INVALID:
- builder.append("\n***validation of model failed***\n");
- break;
- default:
- break;
- }
-
- for (final PfValidationMessage message : messageList) {
- builder.append(message);
- builder.append("\n");
- }
-
- builder.append("********************************");
- return builder.toString();
- }
-}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/Validated.java b/models-base/src/main/java/org/onap/policy/models/base/Validated.java
index d79d58f13..b962d46ab 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/Validated.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/Validated.java
@@ -20,234 +20,343 @@
package org.onap.policy.models.base;
+import com.google.re2j.Pattern;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.BiFunction;
+import java.util.function.Function;
import lombok.NonNull;
-import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
/**
* Classes that can be validated. This can be used as a super class or as a stand-alone
* utility class.
*/
-public class Validated {
+public abstract class Validated {
+ public static final String IS_BLANK = "is blank";
+ public static final String IS_A_NULL_KEY = "is a null key";
+ public static final String IS_NULL = "is null";
+ public static final String NOT_DEFINED = "not defined";
+ public static final String NOT_FOUND = "not found";
+
+ public static final String KEY_TOKEN = "key";
+ public static final String VALUE_TOKEN = "value";
+
+ /**
+ * Validates the fields of the object.
+ *
+ * @param fieldName name of the field containing this
+ * @return the result, or {@code null}
+ */
+ public abstract ValidationResult validate(String fieldName);
/**
- * Validates the fields of the object. The default method simply returns the result.
+ * Adds a result indicating that a value is invalid.
*
- * @param result where to place the result
- * @return the result
+ * @param result where to put the result
+ * @param fieldName name of the field containing the value
+ * @param value the field's value
+ * @param errorMessage the error message
*/
- public PfValidationResult validate(@NonNull PfValidationResult result) {
- return result;
+ public static void addResult(@NonNull BeanValidationResult result, @NonNull String fieldName, Object value,
+ @NonNull String errorMessage) {
+ result.addResult(
+ new ObjectValidationResult(fieldName, getKeyId(value), ValidationStatus.INVALID, errorMessage));
}
/**
- * Validates that a field value is not null.
+ * Makes a result that indicates a value is invalid, because it is null.
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param value value to be validated
- * @param result where to place the result
- * @return the result
+ * @param fieldName name of the field containing the value
+ * @param value the field's value
+ * @return a result indicating the value is invalid
*/
- public PfValidationResult validateNotNull(@NonNull Object container, @NonNull String fieldName, Object value,
- @NonNull PfValidationResult result) {
+ public static ValidationResult makeNullResult(@NonNull String fieldName, Object value) {
+ return new ObjectValidationResult(fieldName, getKeyId(value), ValidationStatus.INVALID, IS_NULL);
+ }
+ /**
+ * Validates a value, if is not {@code null}, by invoking it's validate() method.
+ *
+ * @param result where to put the result
+ * @param fieldName name of the field containing the value
+ * @param value the field's value
+ */
+ public static void validateOptional(@NonNull BeanValidationResult result, @NonNull String fieldName,
+ Validated value) {
+ if (value != null) {
+ result.addResult(value.validate(fieldName));
+ }
+ }
+
+ /**
+ * Validates that a value is not {@code null}. If the value is a subclass of this
+ * class, then it's {@link #validate(String)} method is invoked, too.
+ *
+ * @param fieldName name of the field containing the value
+ * @param value the field's value
+ * @return a result, or {@code null}
+ */
+ public static ValidationResult validateNotNull(@NonNull String fieldName, Object value) {
if (value == null) {
- addError(container, fieldName, result, "null");
+ return new ObjectValidationResult(fieldName, value, ValidationStatus.INVALID, IS_NULL);
+ }
+
+ if (value instanceof Validated) {
+ return ((Validated) value).validate(fieldName);
}
- return result;
+ return null;
}
/**
- * Validates that the name and version of a concept key do not have the null default
- * values.
+ * Validates that a value is not "blank" (i.e., empty). value.
*
- * @param value value to be validated
- * @param result where to place the result
- * @return the result
+ * @param fieldName name of the field containing the value
+ * @param value the field's value
+ * @param checkNull {@code true} if to validate that the value is not {@code null}
+ * @return a result, or {@code null}
*/
- public PfValidationResult validateNotNull(@NonNull PfConceptKey value, @NonNull PfValidationResult result) {
-
- if (PfKey.NULL_KEY_NAME.equals(value.getName())) {
- addError(value, "name", result, "null");
+ public static ValidationResult validateNotBlank(@NonNull String fieldName, String value, boolean checkNull) {
+ if (value == null && !checkNull) {
+ return null;
}
- if (PfKey.NULL_KEY_VERSION.equals(value.getVersion())) {
- addError(value, "version", result, "null");
+ if (StringUtils.isBlank(value)) {
+ return new ObjectValidationResult(fieldName, value, ValidationStatus.INVALID, IS_BLANK);
}
- return result;
+ return null;
}
/**
- * Validates the contents of a field, verifying that it matches a pattern, if it is
- * non-null.
+ * Validates that a value matches regular expression.
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param value value to be validated
- * @param pattern pattern used to validate the value
- * @param result where to place the result
- * @return the result
+ * @param fieldName name of the field containing the value
+ * @param value the field's value
+ * @param pattern regular expression to be matched
+ * @return a result, or {@code null}
*/
- public PfValidationResult validateText(@NonNull Object container, @NonNull String fieldName, String value,
- @NonNull String pattern, @NonNull PfValidationResult result) {
+ public static ValidationResult validateRegex(@NonNull String fieldName, String value, @NonNull String pattern) {
+ if (value == null) {
+ return makeNullResult(fieldName, value);
+ }
- if (value != null) {
- addError(container, fieldName, result,
- Assertions.getStringParameterValidationMessage(fieldName, value, pattern));
+ if (!Pattern.matches(pattern, value)) {
+ return new ObjectValidationResult(fieldName, value, ValidationStatus.INVALID,
+ "does not match regular expression " + pattern);
}
- return result;
+ return null;
}
/**
- * Validates the contents of a property field, verifying that the keys ands values are
- * non-null.
+ * Validates a key, ensuring that it isn't null and that it's structurally sound.
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param properties properties to be validated
- * @param resultIn where to place the result
- * @return the result
+ * @param fieldName name of the field containing the key
+ * @param key the field's value
+ * @return a result, or {@code null}
*/
- public <T> PfValidationResult validatePropertiesNotNull(@NonNull Object container, @NonNull String fieldName,
- Map<String, T> properties, @NonNull PfValidationResult resultIn) {
+ public static ValidationResult validateKeyNotNull(@NonNull String fieldName, PfKey key) {
+ if (key == null) {
+ return new ObjectValidationResult(fieldName, key, ValidationStatus.INVALID, IS_A_NULL_KEY);
+ }
+
+ if (key.isNullKey()) {
+ return new ObjectValidationResult(fieldName, key.getId(), ValidationStatus.INVALID, IS_A_NULL_KEY);
+ }
- PfValidationResult result = resultIn;
+ return key.validate(fieldName);
+ }
- if (properties == null) {
+ /**
+ * Validates a key's version, ensuring that it isn't null.
+ *
+ * @param fieldName name of the field containing the key
+ * @param key the field's value
+ * @return a result, or {@code null}
+ */
+ public static BeanValidationResult validateKeyVersionNotNull(@NonNull String fieldName, PfConceptKey key) {
+ if (key != null && key.isNullVersion()) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, key);
+ result.addResult(makeNullResult(PfKeyImpl.VERSION_TOKEN, key.getVersion()));
return result;
}
- for (Entry<String, T> ent : properties.entrySet()) {
- String key = ent.getKey();
- String keyName = fieldName + "." + key;
- result = validateNotNull(container, keyName, key, result);
+ return null;
+ }
+
+ /**
+ * Generates a function to validate that a value is not below a minimum.
+ *
+ * @param min minimum value allowed
+ * @param allowedValue {@code null} or an allowed value outside the range
+ * @param checkRef {@code true} to generate an error if the value is {@code null}
+ * @return a function to validate that a value is not below a minimum
+ */
+ public static BiFunction<String, Integer, ValidationResult> validateMin(int min, Integer allowedValue,
+ boolean checkRef) {
+ return (name, value) -> validateMin(name, value, min, allowedValue, checkRef);
+ }
+
+ /**
+ * Validates that a value is not below a minimum.
+ *
+ * @param fieldName name of the field containing the key
+ * @param value the field's value
+ * @param min minimum value allowed
+ * @param allowedValue {@code null} or an allowed value outside the range
+ * @param checkRef {@code true} to generate an error if the value is {@code null}
+ * @return a result, or {@code null}
+ */
+ public static ValidationResult validateMin(@NonNull String fieldName, Integer value, int min, Integer allowedValue,
+ boolean checkRef) {
+ if (value == null) {
+ if (checkRef) {
+ return makeNullResult(fieldName, value);
+ }
+
+ return null;
+ }
- result = validateNotNull(container, keyName, ent.getValue(), result);
+ if (value < min && !value.equals(allowedValue)) {
+ return new ObjectValidationResult(fieldName, value, ValidationStatus.INVALID,
+ "is below the minimum value: " + min);
}
- return result;
+ return null;
}
/**
- * Validates the items in a collection field are non-null.
+ * Validates the items in a list.
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param collection collection whose items are to be validated
- * @param resultIn where to place the result
- * @return the result
+ * @param result where to add the results
+ * @param fieldName name of the field containing the list
+ * @param list the field's list (may be {@code null})
+ * @param checker function to validate in individual item in the list
*/
- public <T> PfValidationResult validateCollectionNotNull(@NonNull Object container, @NonNull String fieldName,
- Collection<T> collection, @NonNull PfValidationResult resultIn) {
+ public static <T> void validateList(@NonNull BeanValidationResult result, @NonNull String fieldName,
+ Collection<T> list, @NonNull BiFunction<String, T, ValidationResult> checker) {
+ if (list == null) {
+ return;
+ }
- PfValidationResult result = resultIn;
+ BeanValidationResult result2 = new BeanValidationResult(fieldName, list);
- if (collection == null) {
- return result;
+ int count = 0;
+ for (T value : list) {
+ result2.addResult(checker.apply(String.valueOf(count++), value));
}
- String prefix = fieldName + ".";
- int count = 0;
+ if (!result2.isClean()) {
+ result.addResult(result2);
+ }
+ }
+
+ /**
+ * Validates the items in a map.
+ *
+ * @param result where to add the results
+ * @param fieldName name of the field containing the list
+ * @param map the field's map (may be {@code null})
+ * @param checker function to validate in individual item in the list
+ */
+ public static <T> void validateMap(@NonNull BeanValidationResult result, @NonNull String fieldName,
+ Map<String, T> map, @NonNull Function<Map.Entry<String, T>, ValidationResult> checker) {
+ if (map == null) {
+ return;
+ }
- for (T item : collection) {
- result = validateNotNull(container, prefix + count, item, result);
- ++count;
+ BeanValidationResult result2 = new BeanValidationResult(fieldName, map);
+
+ for (Entry<String, T> entry : map.entrySet()) {
+ result2.addResult(checker.apply(entry));
}
- return result;
+ if (!result2.isClean()) {
+ result.addResult(result2);
+ }
}
/**
- * Invokes the "validate()" method on each item in a collection field, if the item is
- * non-null.
+ * Validates a Map entry, ensuring that neither the key nor the value are "blank"
+ * (i.e., empty or {@code null}).
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param collection collection whose items are to be validated
- * @param result where to place the result
- * @return the result
+ * @param entry entry to be validated
+ * @return a result, or {@code null}
*/
- public <T extends Validated> PfValidationResult validateCollection(@NonNull Object container,
- @NonNull String fieldName, Collection<T> collection, @NonNull PfValidationResult result) {
+ public static BeanValidationResult validateEntryNotBlankNotBlank(Map.Entry<String, String> entry) {
+ BeanValidationResult result = new BeanValidationResult("" + entry.getKey(), entry.getKey());
- if (collection == null) {
- return result;
+ if (StringUtils.isBlank(entry.getKey())) {
+ Validated.addResult(result, KEY_TOKEN, entry.getKey(), IS_BLANK);
}
- for (T item : collection) {
- if (item != null) {
- result = item.validate(result);
- }
+ if (StringUtils.isBlank(entry.getValue())) {
+ Validated.addResult(result, VALUE_TOKEN, entry.getValue(), IS_BLANK);
}
- return result;
+ return (result.isClean() ? null : result);
}
/**
- * Invokes the "validate()" method on each item in a concept collection field, if the
- * item is non-null.
+ * Validates a Map entry, ensuring that the key is not "blank" (i.e., empty or
+ * {@code null}) and the value is not {@code null}.
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param collection collection whose items are to be validated
- * @param result where to place the result
- * @return the result
+ * @param entry entry to be validated
+ * @return a result, or {@code null}
*/
- public <T extends PfConcept> PfValidationResult validateConceptCollection(@NonNull Object container,
- @NonNull String fieldName, Collection<T> collection, @NonNull PfValidationResult result) {
+ public static BeanValidationResult validateEntryNotBlankNotNull(Map.Entry<String, String> entry) {
+ BeanValidationResult result = new BeanValidationResult("" + entry.getKey(), entry.getKey());
- if (collection == null) {
- return result;
+ if (StringUtils.isBlank(entry.getKey())) {
+ Validated.addResult(result, KEY_TOKEN, entry.getKey(), IS_BLANK);
}
- for (T item : collection) {
- if (item != null) {
- result = item.validate(result);
- }
+ if (entry.getValue() == null) {
+ result.addResult(makeNullResult(VALUE_TOKEN, entry.getValue()));
}
- return result;
+ return (result.isClean() ? null : result);
}
/**
- * Adds an error message to the validation result.
+ * Validates a Map entry, ensuring that neither the key nor the value are
+ * {@code null}. If the value is a subclass of this class, then it's
+ * {@link #validate(String)} method is invoked.
*
- * @param container the object that contains the field
- * @param fieldName name of the field to be validated
- * @param result where to place the result
- * @param errmsg the error message to be added, or {@code null} if nothing to add
+ * @param entry entry to be validated
+ * @return a result, or {@code null}
*/
- public void addError(@NonNull Object container, @NonNull String fieldName, @NonNull PfValidationResult result,
- String errmsg) {
- if (errmsg != null) {
- result.addValidationMessage(new PfValidationMessage(makeKey(container), container.getClass(),
- ValidationResult.INVALID, fieldName + " invalid-" + errmsg));
+ public static <V> BeanValidationResult validateEntryValueNotNull(Map.Entry<String, V> entry) {
+ BeanValidationResult result = new BeanValidationResult("" + entry.getKey(), entry.getKey());
+
+ if (entry.getKey() == null) {
+ result.addResult(makeNullResult(KEY_TOKEN, entry.getKey()));
+ }
+
+ V value = entry.getValue();
+ if (value == null) {
+ result.addResult(makeNullResult(VALUE_TOKEN, value));
+ } else if (value instanceof Validated) {
+ result.addResult(((Validated) value).validate(VALUE_TOKEN));
}
+
+ return (result.isClean() ? null : result);
}
/**
- * Makes a PfKey suitable for insertion into a validation message. Note: the
- * "toString()" method of the key simply invokes container.toString();
+ * Gets a key's ID, if the value is a {@link PfKey}.
*
- * @param container the container object for which the key should be made
- * @return a key for the container
+ * @param value value from which to get the ID
+ * @return the value's ID, if it's a key, the original value otherwise
*/
- public PfKey makeKey(@NonNull Object container) {
-
- return new PfConceptKey() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public String toString() {
- return container.toString();
- }
- };
+ private static Object getKeyId(Object value) {
+ return (value instanceof PfKey ? ((PfKey) value).getId() : value);
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
index 062f6f953..8c74850d2 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.base;
+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;
@@ -111,9 +112,7 @@ public class PfConceptContainerTest {
container.clean();
assertEquals(clonedContainer, container);
- PfValidationResult result = new PfValidationResult();
- result = container.validate(result);
- assertTrue(result.isOk());
+ assertThat(container.validate("").getResult()).isNull();
assertEquals(0, container.compareTo(clonedContainer));
@@ -136,30 +135,30 @@ public class PfConceptContainerTest {
final DummyPfConceptContainer container3 = container;
assertThatThrownBy(() -> container3.validate(null))
- .hasMessageMatching("^resultIn is marked .*on.*ull but is null$");
+ .hasMessageMatching("^fieldName is marked .*on.*ull but is null$");
DummyPfConceptContainer validateContainer = new DummyPfConceptContainer();
- assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ assertFalse(validateContainer.validate("").isValid());
validateContainer.setKey(new PfConceptKey("VCKey", VERSION0_0_1));
- assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+ assertTrue(validateContainer.validate("").isValid());
validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
- assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+ assertTrue(validateContainer.validate("").isValid());
validateContainer.getConceptMap().put(PfConceptKey.getNullKey(), new DummyPfConcept(PfConceptKey.getNullKey()));
- assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ assertFalse(validateContainer.validate("").isValid());
validateContainer.getConceptMap().remove(PfConceptKey.getNullKey());
- assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+ assertTrue(validateContainer.validate("").isValid());
validateContainer.getConceptMap().put(testConceptKey, null);
- assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ assertFalse(validateContainer.validate("").isValid());
validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
- assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+ assertTrue(validateContainer.validate("").isValid());
validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(conceptKey));
- assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ assertFalse(validateContainer.validate("").isValid());
validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
- assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+ assertTrue(validateContainer.validate("").isValid());
assertEquals(conceptKey, container.get(conceptKey).getKey());
assertEquals(conceptKey, container.get(conceptKey.getName()).getKey());
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 8b94a48c3..8d6b1b9f4 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
@@ -21,6 +21,7 @@
package org.onap.policy.models.base;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
@@ -35,6 +36,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.models.base.PfKey.Compatibility;
import org.onap.policy.models.base.testconcepts.DummyPfKey;
@@ -109,20 +111,13 @@ public class PfKeyImplTest {
assertFalse(someKey1.isCompatible(someKey5));
assertFalse(someKey1.isCompatible(new DummyPfKey()));
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey0.validate(new PfValidationResult()).getValidationResult());
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey1.validate(new PfValidationResult()).getValidationResult());
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey2.validate(new PfValidationResult()).getValidationResult());
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey3.validate(new PfValidationResult()).getValidationResult());
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey4.validate(new PfValidationResult()).getValidationResult());
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey5.validate(new PfValidationResult()).getValidationResult());
- assertEquals(PfValidationResult.ValidationResult.VALID,
- someKey6.validate(new PfValidationResult()).getValidationResult());
+ assertTrue(someKey0.validate("").isValid());
+ assertTrue(someKey1.validate("").isValid());
+ assertTrue(someKey2.validate("").isValid());
+ assertTrue(someKey3.validate("").isValid());
+ assertTrue(someKey4.validate("").isValid());
+ assertTrue(someKey5.validate("").isValid());
+ assertTrue(someKey6.validate("").isValid());
someKey0.clean();
assertNotNull(someKey0.toString());
@@ -179,22 +174,20 @@ public class PfKeyImplTest {
Field nameField = testKey.getClass().getDeclaredField("name");
nameField.setAccessible(true);
nameField.set(testKey, "Key Name");
- PfValidationResult validationResult = new PfValidationResult();
- testKey.validate(validationResult);
+ ValidationResult validationResult = testKey.validate("");
nameField.set(testKey, "TheKey");
nameField.setAccessible(false);
- assertEquals("name invalid-parameter name with value Key Name " + "does not match regular expression "
- + PfKey.NAME_REGEXP, validationResult.getMessageList().get(0).getMessage());
+ assertThat(validationResult.getResult()).contains("\"name\"").doesNotContain("\"version\"")
+ .contains("does not match regular expression " + PfKey.NAME_REGEXP);
Field versionField = testKey.getClass().getDeclaredField("version");
versionField.setAccessible(true);
versionField.set(testKey, "Key Version");
- PfValidationResult validationResult2 = new PfValidationResult();
- testKey.validate(validationResult2);
+ ValidationResult validationResult2 = testKey.validate("");
versionField.set(testKey, VERSION001);
versionField.setAccessible(false);
- assertEquals("version invalid-parameter version with value Key Version " + "does not match regular expression "
- + PfKey.VERSION_REGEXP, validationResult2.getMessageList().get(0).getMessage());
+ assertThat(validationResult2.getResult()).doesNotContain("\"name\"").contains("\"version\"")
+ .contains("does not match regular expression " + PfKey.VERSION_REGEXP);
}
@Test
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
index f9ad889c7..d2aebdc43 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
@@ -62,9 +62,7 @@ public class PfKeyUseTest {
keyUse.clean();
assertNotNull(keyUse);
- PfValidationResult result = new PfValidationResult();
- result = keyUse.validate(result);
- assertNotNull(result);
+ assertNotNull(keyUse.validate(""));
assertNotEquals(0, keyUse.hashCode());
@@ -84,8 +82,7 @@ public class PfKeyUseTest {
assertEquals(0, keyUse.compareTo(new PfKeyUse(key)));
PfKeyUse keyUseNull = new PfKeyUse(PfConceptKey.getNullKey());
- PfValidationResult resultNull = new PfValidationResult();
- assertEquals(false, keyUseNull.validate(resultNull).isValid());
+ assertEquals(false, keyUseNull.validate("").isValid());
assertThatThrownBy(() -> keyUse.setKey(null)).hasMessageMatching("^key is marked .*on.*ull but is null$");
@@ -93,7 +90,8 @@ public class PfKeyUseTest {
assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessageMatching(OTHER_KEY_IS_NULL);
- assertThatThrownBy(() -> keyUse.validate(null)).hasMessageMatching("^result is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> keyUse.validate(null))
+ .hasMessageMatching("^fieldName is marked .*on.*ull but is null$");
PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey()));
assertEquals(testKeyUse, new PfKeyUse(testKeyUse));
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java
index 9e4e350a1..760231a7c 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java
@@ -73,59 +73,59 @@ public class PfModelTest {
public void testPfModelValidation() {
PfConceptKey dpmKey = new PfConceptKey("modelKey", VERSION001);
DummyPfModel dpm = new DummyPfModel(dpmKey);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
- assertThatThrownBy(() -> dpm.validate(null)).hasMessageMatching("^resultIn is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> dpm.validate(null)).hasMessageMatching("^fieldName is marked .*on.*ull but is null$");
dpm.setKey(PfConceptKey.getNullKey());
- assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ assertFalse(dpm.validate("").isValid());
dpm.setKey(dpmKey);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
dpm.getKeyList().add(PfReferenceKey.getNullKey());
dpm.getKeyList().add(new PfKeyUse(PfReferenceKey.getNullKey()));
- assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ assertFalse(dpm.validate("").isValid());
dpm.getKeyList().clear();
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfConceptKey goodCKey = new PfConceptKey("goodCKey", VERSION001);
PfReferenceKey goodRKey = new PfReferenceKey(goodCKey, "goodLocalName");
dpm.getKeyList().add(goodCKey);
dpm.getKeyList().add(goodRKey);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfConceptKey goodCKeyDup = new PfConceptKey(goodCKey);
dpm.getKeyList().add(goodCKeyDup);
- assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ assertFalse(dpm.validate("").isValid());
dpm.getKeyList().remove(goodCKeyDup);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfReferenceKey goodRKeyDup = new PfReferenceKey(goodRKey);
dpm.getKeyList().add(goodRKeyDup);
- assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ assertFalse(dpm.validate("").isValid());
dpm.getKeyList().remove(goodRKeyDup);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfKeyUse goodCKeyUse = new PfKeyUse(goodCKey);
dpm.getKeyList().add(goodCKeyUse);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfKeyUse goodRKeyUse = new PfKeyUse(goodRKey);
dpm.getKeyList().add(goodRKeyUse);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfConceptKey badCKey = new PfConceptKey("badCKey", VERSION001);
PfKeyUse badCKeyUse = new PfKeyUse(badCKey);
dpm.getKeyList().add(badCKeyUse);
- assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ assertFalse(dpm.validate("").isValid());
dpm.getKeyList().remove(badCKeyUse);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
PfKeyUse badRKeyUse = new PfKeyUse(new PfReferenceKey(badCKey, "badLocalName"));
dpm.getKeyList().add(badRKeyUse);
- assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ assertFalse(dpm.validate("").isValid());
dpm.getKeyList().remove(badRKeyUse);
- assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ assertTrue(dpm.validate("").isValid());
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
index a27a5ddea..de328e9f2 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.base;
+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;
@@ -30,6 +31,7 @@ import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationResult;
public class PfReferenceKeyTest {
@@ -93,9 +95,7 @@ public class PfReferenceKeyTest {
assertEquals(PfKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(PfReferenceKey.getNullKey()));
assertEquals(PfKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey));
- PfValidationResult result = new PfValidationResult();
- result = testReferenceKey.validate(result);
- assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
+ assertTrue(testReferenceKey.validate("").isValid());
testReferenceKey.clean();
@@ -139,49 +139,37 @@ public class PfReferenceKeyTest {
Field parentNameField = testReferenceKey.getClass().getDeclaredField("parentKeyName");
parentNameField.setAccessible(true);
parentNameField.set(testReferenceKey, "Parent Name");
- PfValidationResult validationResult = new PfValidationResult();
- testReferenceKey.validate(validationResult);
+ ValidationResult validationResult = testReferenceKey.validate("");
parentNameField.set(testReferenceKey, "ParentName");
parentNameField.setAccessible(false);
- assertEquals(
- "parentKeyName invalid-parameter parentKeyName with value Parent Name "
- + "does not match regular expression " + PfKey.NAME_REGEXP,
- validationResult.getMessageList().get(0).getMessage());
+ assertThat(validationResult.getResult()).contains("\"parentKeyName\"")
+ .contains("does not match regular expression " + PfKey.NAME_REGEXP);
Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion");
parentVersionField.setAccessible(true);
parentVersionField.set(testReferenceKey, "Parent Version");
- PfValidationResult validationResult2 = new PfValidationResult();
- testReferenceKey.validate(validationResult2);
+ ValidationResult validationResult2 = testReferenceKey.validate("");
parentVersionField.set(testReferenceKey, VERSION001);
parentVersionField.setAccessible(false);
- assertEquals(
- "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version "
- + "does not match regular expression " + PfKey.VERSION_REGEXP,
- validationResult2.getMessageList().get(0).getMessage());
+ assertThat(validationResult2.getResult()).contains("\"parentKeyVersion\"")
+ .contains("does not match regular expression " + PfKey.VERSION_REGEXP);
Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName");
parentLocalNameField.setAccessible(true);
parentLocalNameField.set(testReferenceKey, "Parent Local Name");
- PfValidationResult validationResult3 = new PfValidationResult();
- testReferenceKey.validate(validationResult3);
+ ValidationResult validationResult3 = testReferenceKey.validate("");
parentLocalNameField.set(testReferenceKey, PARENT_LOCAL_NAME);
parentLocalNameField.setAccessible(false);
- assertEquals(
- "parentLocalName invalid-parameter parentLocalName with value "
- + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
- validationResult3.getMessageList().get(0).getMessage());
+ assertThat(validationResult3.getResult()).contains("\"parentLocalName\"")
+ .contains("does not match regular expression [A-Za-z0-9\\-_\\.]+|^$");
Field localNameField = testReferenceKey.getClass().getDeclaredField("localName");
localNameField.setAccessible(true);
localNameField.set(testReferenceKey, "Local Name");
- PfValidationResult validationResult4 = new PfValidationResult();
- testReferenceKey.validate(validationResult4);
+ ValidationResult validationResult4 = testReferenceKey.validate("");
localNameField.set(testReferenceKey, LOCAL_NAME);
localNameField.setAccessible(false);
- assertEquals(
- "localName invalid-parameter localName with value Local Name "
- + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
- validationResult4.getMessageList().get(0).getMessage());
+ assertThat(validationResult4.getResult()).contains("\"localName\"")
+ .contains("does not match regular expression [A-Za-z0-9\\-_\\.]+|^$");
}
}
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 5d1367028..8534d82a6 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
@@ -1,9 +1,8 @@
-/*
+/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Models
+ * ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -21,424 +20,426 @@
package org.onap.policy.models.base;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Before;
+import java.util.function.BiFunction;
+import lombok.AllArgsConstructor;
+import lombok.NonNull;
import org.junit.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
public class ValidatedTest {
- private static final String COLLECTION_TEXT = "collection";
- private static final String ERROR_MESSAGE = "error message";
- private static final String COLLECTION_FIELD = "coll";
- private static final String VALID_VALUE = "abc123";
- private static final String PROPS_FIELD = "props";
- private static final String MY_NAME = "my.name";
- private static final String VALID_FIELD = "validField";
- private static final String INVALID_FIELD = "invalidField";
- private static final String NULL_FIELD = "nullField";
- private static final String WORD_PAT = "\\w*";
- private static final String MY_TO_STRING = "[some text]";
- private static final String VERSION = "1.2.3";
-
- private Validated validated;
-
- @Before
- public void setUp() {
- validated = new Validated();
+ private static final @NonNull String MY_FIELD = "myField";
+ private static final @NonNull String Q_KEY = "\"" + Validated.KEY_TOKEN + "\"";
+ private static final @NonNull String Q_VALUE = "\"" + Validated.VALUE_TOKEN + "\"";
+ private static final String NOT_SAME = "not same";
+ private static final String TEXT = "some text";
+ private static final String OTHER = "other text";
+ private static final String NAME = "myKey";
+ private static final String VERSION = "1.0.0";
+ private static final String BLANKS = "\t \n";
+
+ @Test
+ public void testAddResult() {
+ BeanValidationResult result = new BeanValidationResult("", this);
+ Validated.addResult(result, MY_FIELD, TEXT, "some message");
+ assertThat(result.getResult()).contains(MY_FIELD).contains(TEXT).contains("some message");
+
+ assertThatThrownBy(() -> Validated.addResult(null, MY_FIELD, TEXT, OTHER))
+ .isInstanceOf(NullPointerException.class);
+
+ assertThatThrownBy(() -> Validated.addResult(result, null, TEXT, OTHER))
+ .isInstanceOf(NullPointerException.class);
+
+ assertThatCode(() -> Validated.addResult(result, MY_FIELD, null, OTHER)).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> Validated.addResult(result, MY_FIELD, TEXT, null))
+ .isInstanceOf(NullPointerException.class);
}
@Test
- public void testValidate() {
- assertThatThrownBy(() -> validated.validate(null)).isInstanceOf(NullPointerException.class);
+ public void testMakeNullResult() {
+ ValidationResult rnull = Validated.makeNullResult(MY_FIELD, TEXT);
+ assertEquals(MY_FIELD, rnull.getName());
+ assertThat(rnull.getResult()).contains(MY_FIELD).contains(TEXT).contains(Validated.IS_NULL);
+ assertFalse(rnull.isValid());
+
+ assertThatThrownBy(() -> Validated.makeNullResult(null, TEXT)).isInstanceOf(NullPointerException.class);
- PfValidationResult result = new PfValidationResult();
- assertSame(result, validated.validate(result));
- assertTrue(result.isValid());
- assertEquals(0, result.getMessageList().size());
+ assertThatCode(() -> Validated.makeNullResult(MY_FIELD, null)).doesNotThrowAnyException();
}
@Test
- public void testValidateNotNull() {
- PfValidationResult result = new PfValidationResult();
+ public void testValidateOptional() {
+ BeanValidationResult result = new BeanValidationResult("", this);
+ Validated.validateOptional(result, MY_FIELD, null);
+ assertTrue(result.isClean());
- final PfValidationResult result2 = result;
- assertThatThrownBy(() -> validated.validateNotNull(null, VALID_FIELD, VALID_VALUE, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateNotNull(this, null, VALID_VALUE, result2))
+ Validated.validateOptional(result, MY_FIELD, new MyString(TEXT));
+ assertTrue(result.isClean());
+
+ Validated.validateOptional(result, MY_FIELD, new MyString(OTHER));
+ assertThat(result.getResult()).contains(MY_FIELD).contains(OTHER).contains(NOT_SAME);
+
+ assertThatThrownBy(() -> Validated.validateOptional(null, MY_FIELD, new MyString(TEXT)))
.isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateNotNull(this, VALID_FIELD, VALID_VALUE, null))
+
+ assertThatThrownBy(() -> Validated.validateOptional(result, null, new MyString(TEXT)))
.isInstanceOf(NullPointerException.class);
- // null text
- result = validated.validateNotNull(this, NULL_FIELD, null, result);
+ assertThatCode(() -> Validated.validateOptional(result, MY_FIELD, null)).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testValidateNotNull() {
+ assertThat(Validated.validateNotNull(MY_FIELD, TEXT)).isNull();
- // invalid text
- result = validated.validateNotNull(this, INVALID_FIELD, "!!!", result);
+ assertThat(Validated.validateNotNull(MY_FIELD, null).getResult()).contains(MY_FIELD)
+ .contains(Validated.IS_NULL);
- // valid text
- result = validated.validateNotNull(this, VALID_FIELD, VALID_VALUE, result);
+ // should invoke the value's validate() method, which should return success
+ assertThat(Validated.validateNotNull(MY_FIELD, new MyString(TEXT))).isNull();
- // different value
- result = validated.validateNotNull(this, VALID_FIELD, Integer.valueOf(10), result);
+ // should invoke the value's validate() method, which should return failure
+ assertThat(Validated.validateNotNull(MY_FIELD, new MyString(OTHER)).getResult()).contains(MY_FIELD)
+ .contains(NOT_SAME);
- assertFalse(result.isValid());
- assertEquals(1, result.getMessageList().size());
+ assertThatThrownBy(() -> Validated.validateNotNull(null, TEXT)).isInstanceOf(NullPointerException.class);
- // check result for null text
- PfValidationMessage msg = result.getMessageList().get(0);
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("nullField invalid-null"));
+ assertThatCode(() -> Validated.validateNotNull(MY_FIELD, null)).doesNotThrowAnyException();
}
@Test
- public void testValidateNotNullConceptKey() {
- PfValidationResult result = new PfValidationResult();
-
- // null key
- PfConceptKey key = new PfConceptKey();
- key.setVersion(VERSION);
- result = validated.validateNotNull(key, result);
-
- // null value
- key = new PfConceptKey();
- key.setName(MY_NAME);
- result = validated.validateNotNull(key, result);
-
- // both null
- key = new PfConceptKey();
- result = validated.validateNotNull(key, result);
-
- assertFalse(result.isValid());
- assertEquals(4, result.getMessageList().size());
-
- // valid key & value
- key = new PfConceptKey();
- key.setName(MY_NAME);
- key.setVersion(VERSION);
- result = validated.validateNotNull(key, result);
-
- // no change
- assertFalse(result.isValid());
- assertEquals(4, result.getMessageList().size());
-
- Iterator<PfValidationMessage> it = result.getMessageList().iterator();
-
- // check null key
- PfValidationMessage msg = it.next();
- assertEquals(PfConceptKey.class.getName(), msg.getObservedClass());
- assertTrue(msg.getMessage().contains("name invalid-null"));
-
- // check null value
- msg = it.next();
- assertEquals(PfConceptKey.class.getName(), msg.getObservedClass());
- assertTrue(msg.getMessage().contains("version invalid-null"));
-
- // check both null
- msg = it.next();
- assertEquals(PfConceptKey.class.getName(), msg.getObservedClass());
- assertTrue(msg.getMessage().contains("name invalid-null"));
- assertTrue(it.next().getMessage().contains("version invalid-null"));
-
- PfValidationResult pfValidationResult = new PfValidationResult();
- final PfConceptKey key2 = key;
- assertThatThrownBy(() -> validated.validateNotNull(key2, null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateNotNull(null, pfValidationResult))
+ public void testValidateNotBlank() {
+ assertThat(Validated.validateNotBlank(MY_FIELD, TEXT, false)).isNull();
+ assertThat(Validated.validateNotBlank(MY_FIELD, TEXT, true)).isNull();
+
+ assertThat(Validated.validateNotBlank(MY_FIELD, null, false)).isNull();
+ assertThat(Validated.validateNotBlank(MY_FIELD, null, true).getResult()).contains(MY_FIELD)
+ .contains(Validated.IS_BLANK);
+
+ assertThat(Validated.validateNotBlank(MY_FIELD, "", false).getResult()).contains(MY_FIELD)
+ .contains(Validated.IS_BLANK);
+ assertThat(Validated.validateNotBlank(MY_FIELD, "", true).getResult()).contains(MY_FIELD)
+ .contains(Validated.IS_BLANK);
+
+ assertThatThrownBy(() -> Validated.validateNotBlank(null, TEXT, false))
.isInstanceOf(NullPointerException.class);
+
+ assertThatCode(() -> Validated.validateNotBlank(MY_FIELD, null, false)).doesNotThrowAnyException();
}
@Test
- public void testValidateText() {
- PfValidationResult result = new PfValidationResult();
+ public void testValidateRegex() {
+ assertThat(Validated.validateRegex(MY_FIELD, "hello", ".*ll.*")).isNull();
- final PfValidationResult result2 = result;
- assertThatThrownBy(() -> validated.validateText(null, VALID_FIELD, VALID_VALUE, WORD_PAT, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateText(this, null, VALID_VALUE, WORD_PAT, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateText(this, VALID_FIELD, VALID_VALUE, null, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateText(this, VALID_FIELD, VALID_VALUE, WORD_PAT, null))
- .isInstanceOf(NullPointerException.class);
+ assertThat(Validated.validateRegex(MY_FIELD, "hello", "[x-z]").getResult()).contains(MY_FIELD).contains("hello")
+ .contains("does not match regular expression [x-z]");
- // null text
- result = validated.validateText(this, NULL_FIELD, null, WORD_PAT, result);
+ assertThatThrownBy(() -> Validated.validateRegex(null, "hello", "ll")).isInstanceOf(NullPointerException.class);
- // invalid text
- result = validated.validateText(this, INVALID_FIELD, "!!!", WORD_PAT, result);
+ assertThatCode(() -> Validated.validateRegex(MY_FIELD, null, "ll")).doesNotThrowAnyException();
- // valid text
- result = validated.validateText(this, VALID_FIELD, VALID_VALUE, WORD_PAT, result);
+ assertThatThrownBy(() -> Validated.validateRegex(MY_FIELD, "hello", null))
+ .isInstanceOf(NullPointerException.class);
+ }
- assertFalse(result.isValid());
- assertEquals(1, result.getMessageList().size());
+ @Test
+ public void testValidateKeyNotNull() throws CoderException {
+ assertThat(Validated.validateKeyNotNull(MY_FIELD, new PfConceptKey(NAME, VERSION)).getResult()).isNull();
+ assertThat(Validated.validateKeyNotNull(MY_FIELD, new PfConceptKey(NAME, PfConceptKey.NULL_KEY_VERSION))
+ .getResult()).isNull();
+ assertThat(Validated.validateKeyNotNull(MY_FIELD, new PfConceptKey(PfConceptKey.NULL_KEY_NAME, VERSION))
+ .getResult()).isNull();
+
+ // key is null
+ assertThat(Validated.validateKeyNotNull(MY_FIELD, new PfConceptKey()).getResult()).contains(MY_FIELD)
+ .doesNotContain("\"name\"").doesNotContain("\"version\"").contains(Validated.IS_A_NULL_KEY);
+
+ /*
+ * Key is not null, but key.validate() should fail due to an invalid version.
+ * Note: have to create the key by decoding from json, as the class will prevent
+ * an invalid version from being assigned.
+ */
+ PfConceptKey key = new StandardCoder().decode("{'name':'myKey','version':'bogus'}".replace('\'', '"'),
+ PfConceptKey.class);
+ assertThat(Validated.validateKeyNotNull(MY_FIELD, key).getResult()).contains(MY_FIELD).contains("version")
+ .contains("does not match regular expression");
+
+ // null parameter tests
+ assertThatThrownBy(() -> Validated.validateKeyNotNull(null, new PfConceptKey()))
+ .isInstanceOf(NullPointerException.class);
- // check result for invalid text
- PfValidationMessage msg = result.getMessageList().get(0);
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("invalidField invalid-parameter invalidField"));
+ assertThatCode(() -> Validated.validateKeyNotNull(MY_FIELD, null)).doesNotThrowAnyException();
}
@Test
- public void testValidatePropertiesNotNull() {
- PfValidationResult result = new PfValidationResult();
- result = validated.validatePropertiesNotNull(this, "properties", null, result);
- assertTrue(result.isValid());
- assertEquals(0, result.getMessageList().size());
+ public void testValidateKeyVersionNotNull() {
+ assertThat(Validated.validateKeyVersionNotNull(MY_FIELD, null)).isNull();
- Map<String, Integer> map = new LinkedHashMap<>();
+ assertThat(Validated.validateKeyVersionNotNull(MY_FIELD, new PfConceptKey(NAME, VERSION))).isNull();
- // null key
- map.put(null, 10);
+ assertThat(Validated.validateKeyVersionNotNull(MY_FIELD, new PfConceptKey(NAME, PfConceptKey.NULL_KEY_VERSION))
+ .getResult()).contains(MY_FIELD).contains("version").contains(Validated.IS_NULL);
- // null value
- map.put("abc", null);
+ assertThatThrownBy(() -> Validated.validateKeyVersionNotNull(null, new PfConceptKey()))
+ .isInstanceOf(NullPointerException.class);
- // valid key & value
- map.put("def", 11);
+ assertThatCode(() -> Validated.validateKeyVersionNotNull(MY_FIELD, null)).doesNotThrowAnyException();
+ }
+ @Test
+ public void testValidateMinIntIntegerBoolean_testValidateMinStringIntegerIntIntegerBoolean() {
+ /*
+ * No "special" value, don't check the reference.
+ */
+ BiFunction<String, Integer, ValidationResult> func = Validated.validateMin(10, null, false);
+ assertThat(func.apply(MY_FIELD, null)).isNull();
- result = validated.validatePropertiesNotNull(this, PROPS_FIELD, map, result);
+ // exact match
+ assertThat(func.apply(MY_FIELD, 10)).isNull();
- assertFalse(result.isValid());
- assertEquals(2, result.getMessageList().size());
+ assertThat(func.apply(MY_FIELD, 20)).isNull();
- Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+ assertThat(func.apply(MY_FIELD, 9).getResult()).contains(MY_FIELD).contains("9")
+ .contains("is below the minimum value: 10");
- // check null key
- PfValidationMessage msg = it.next();
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("props.null invalid-null"));
+ /*
+ * "special" value, don't check the reference.
+ */
+ func = Validated.validateMin(10, 7, false);
+ assertThat(func.apply(MY_FIELD, null)).isNull();
- // check null value
- msg = it.next();
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("props.abc invalid-null"));
+ // exact match
+ assertThat(func.apply(MY_FIELD, 10)).isNull();
- final PfValidationResult result2 = result;
- assertThatThrownBy(() -> validated.validatePropertiesNotNull(null, PROPS_FIELD, map, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validatePropertiesNotNull(this, null, map, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validatePropertiesNotNull(this, PROPS_FIELD, map, null))
- .isInstanceOf(NullPointerException.class);
- }
+ assertThat(func.apply(MY_FIELD, 20)).isNull();
- @Test
- public void testValidateCollectionNotNull() {
- PfValidationResult result = new PfValidationResult();
- result = validated.validateCollectionNotNull(this, COLLECTION_TEXT, null, result);
- assertTrue(result.isValid());
- assertEquals(0, result.getMessageList().size());
+ // special value - should be ok
+ assertThat(func.apply(MY_FIELD, 7)).isNull();
- final List<String> lst = Arrays.asList("abc", null, "def", null);
+ assertThat(func.apply(MY_FIELD, 9).getResult()).contains(MY_FIELD).contains("9")
+ .contains("is below the minimum value: 10");
- result = validated.validateCollectionNotNull(this, COLLECTION_FIELD, lst, result);
+ /*
+ * Check the reference (i.e., generate an error if the value is null).
+ */
+ func = Validated.validateMin(10, null, true);
+ assertThat(func.apply(MY_FIELD, null).getResult()).contains(MY_FIELD).contains(Validated.IS_NULL);
- assertFalse(result.isValid());
- assertEquals(2, result.getMessageList().size());
+ // exact match
+ assertThat(func.apply(MY_FIELD, 10)).isNull();
- Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+ assertThat(func.apply(MY_FIELD, 20)).isNull();
- // check first item
- PfValidationMessage msg = it.next();
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("coll.1 invalid-null"));
+ assertThat(func.apply(MY_FIELD, 9).getResult()).contains(MY_FIELD).contains("9")
+ .contains("is below the minimum value: 10");
- // check null value
- msg = it.next();
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("coll.3 invalid-null"));
- final PfValidationResult result2 = result;
- assertThatThrownBy(() -> validated.validateCollectionNotNull(null, COLLECTION_FIELD, lst, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateCollectionNotNull(this, null, lst, result2))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateCollectionNotNull(this, COLLECTION_FIELD, lst, null))
- .isInstanceOf(NullPointerException.class);
+ BiFunction<String, Integer, ValidationResult> func2 = func;
+ assertThatThrownBy(() -> func2.apply(null, 30)).isInstanceOf(NullPointerException.class);
+
+ assertThatCode(() -> func2.apply(MY_FIELD, null)).doesNotThrowAnyException();
}
@Test
- public void testValidateCollection() {
- PfValidationResult result = new PfValidationResult();
- result = validated.validateCollection(this, COLLECTION_TEXT, null, result);
- assertTrue(result.isValid());
- assertEquals(0, result.getMessageList().size());
-
- List<MyValid> lst = Arrays.asList(new MyValid(0, false), new MyValid(1, true), null, new MyValid(2, false),
- new MyValid(3, true));
- result = validated.validateCollection(this, COLLECTION_FIELD, lst, result);
-
- assertFalse(result.isValid());
- assertEquals(2, result.getMessageList().size());
-
- Iterator<PfValidationMessage> it = result.getMessageList().iterator();
-
- // check first item
- PfValidationMessage msg = it.next();
- assertEquals(MyValid.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("index.0 invalid-wrong value"));
-
- // check null value
- msg = it.next();
- assertEquals(MyValid.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("index.2 invalid-wrong value"));
-
- final PfValidationResult result2 = result;
- assertThatThrownBy(() -> validated.validateCollection(null, COLLECTION_FIELD, lst, result2))
+ public void testValidateList() {
+ BeanValidationResult result = new BeanValidationResult("", this);
+ Validated.validateList(result, MY_FIELD, null, Validated::validateNotNull);
+ assertThat(result.getResult()).isNull();
+
+ result = new BeanValidationResult("", this);
+ Validated.validateList(result, MY_FIELD, List.of(TEXT, OTHER), Validated::validateNotNull);
+ assertThat(result.getResult()).isNull();
+
+ List<String> list = new ArrayList<>();
+ list.add(TEXT);
+ list.add(null);
+ list.add(OTHER);
+ list.add(null);
+ result = new BeanValidationResult("", this);
+ Validated.validateList(result, MY_FIELD, list, Validated::validateNotNull);
+ assertThat(result.getResult()).doesNotContain("0").contains("1").doesNotContain("2").contains("3")
+ .contains(Validated.IS_NULL);
+
+ BeanValidationResult result2 = result;
+ assertThatThrownBy(() -> Validated.validateList(null, MY_FIELD, List.of(), Validated::validateNotNull))
.isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateCollection(this, null, lst, result2))
+
+ assertThatThrownBy(() -> Validated.validateList(result2, null, List.of(), Validated::validateNotNull))
.isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateCollection(this, COLLECTION_FIELD, lst, null))
+
+ assertThatCode(() -> Validated.validateList(result2, MY_FIELD, null, Validated::validateNotNull))
+ .doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> Validated.validateList(result2, MY_FIELD, List.of(), null))
.isInstanceOf(NullPointerException.class);
}
@Test
- public void testValidateConceptCollection() {
- PfValidationResult result = new PfValidationResult();
- result = validated.validateConceptCollection(this, COLLECTION_TEXT, null, result);
- assertTrue(result.isValid());
- assertEquals(0, result.getMessageList().size());
-
- List<MyConcept> lst = Arrays.asList(new MyConcept(0, false), new MyConcept(1, true), null,
- new MyConcept(2, false), new MyConcept(3, true));
- result = validated.validateConceptCollection(this, COLLECTION_FIELD, lst, result);
-
- assertFalse(result.isValid());
- assertEquals(2, result.getMessageList().size());
-
- Iterator<PfValidationMessage> it = result.getMessageList().iterator();
-
- // check first item
- PfValidationMessage msg = it.next();
- assertEquals(MyConcept.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("index.0 invalid-wrong value"));
-
- // check null value
- msg = it.next();
- assertEquals(MyConcept.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("index.2 invalid-wrong value"));
-
- final PfValidationResult result2 = result;
- assertThatThrownBy(() -> validated.validateConceptCollection(null, COLLECTION_FIELD, lst, result2))
+ public void testValidateMap() {
+ BeanValidationResult result = new BeanValidationResult("", this);
+ Validated.validateMap(result, MY_FIELD, null, Validated::validateEntryNotBlankNotBlank);
+ assertThat(result.getResult()).isNull();
+
+ result = new BeanValidationResult("", this);
+ Validated.validateMap(result, MY_FIELD, Map.of("abc", TEXT, "def", OTHER),
+ Validated::validateEntryNotBlankNotBlank);
+ assertThat(result.getResult()).isNull();
+
+ // invalid values
+ Map<String, String> map = new HashMap<>();
+ map.put("ghi", TEXT);
+ map.put("jkl", "");
+ map.put("mno", OTHER);
+ map.put("pqr", "");
+ result = new BeanValidationResult("", this);
+ Validated.validateMap(result, MY_FIELD, map, Validated::validateEntryNotBlankNotBlank);
+ assertThat(result.getResult()).doesNotContain("abc").contains("jkl").doesNotContain("mno").contains("pqr")
+ .contains(Q_VALUE).doesNotContain(Q_KEY).contains(Validated.IS_BLANK);
+
+ // invalid keys
+ map = new HashMap<>();
+ map.put("stu", TEXT);
+ map.put("", TEXT);
+ map.put("vwx", OTHER);
+ map.put(null, OTHER);
+ result = new BeanValidationResult("", this);
+ Validated.validateMap(result, MY_FIELD, map, Validated::validateEntryNotBlankNotBlank);
+ assertThat(result.getResult()).doesNotContain("stu").contains("\"\"").doesNotContain("vwx").contains("null")
+ .contains(Q_KEY).doesNotContain(Q_VALUE).contains(Validated.IS_BLANK);
+
+ BeanValidationResult result2 = result;
+ Map<String, String> map2 = map;
+ assertThatThrownBy(() -> Validated.validateMap(null, MY_FIELD, map2, Validated::validateEntryNotBlankNotBlank))
.isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateConceptCollection(this, null, lst, result2))
+
+ assertThatThrownBy(() -> Validated.validateMap(result2, null, map2, Validated::validateEntryNotBlankNotBlank))
.isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.validateConceptCollection(this, COLLECTION_FIELD, lst, null))
+
+ assertThatCode(() -> Validated.validateMap(result2, MY_FIELD, null, Validated::validateEntryNotBlankNotBlank))
+ .doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> Validated.validateMap(result2, MY_FIELD, map2, null))
.isInstanceOf(NullPointerException.class);
}
@Test
- public void testAddError() {
- final PfValidationResult result = new PfValidationResult();
- final PfValidationResult result2 = result;
+ public void testValidateEntryNotBlankNotBlank() {
+ assertThat(Validated.validateEntryNotBlankNotBlank(makeEntry(TEXT, OTHER))).isNull();
- assertThatThrownBy(() -> validated.addError(null, VALID_FIELD, result2, ERROR_MESSAGE))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.addError(this, null, result2, ERROR_MESSAGE))
- .isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> validated.addError(this, VALID_FIELD, null, ERROR_MESSAGE))
- .isInstanceOf(NullPointerException.class);
-
- validated.addError(this, VALID_FIELD, result, "error-A");
- validated.addError(this, VALID_FIELD, result, null);
- validated.addError(this, VALID_FIELD, result, "error-B");
+ // try invalid values for the key
+ assertThat(Validated.validateEntryNotBlankNotBlank(makeEntry(null, OTHER)).getResult()).contains(Q_KEY)
+ .contains(Validated.IS_BLANK).doesNotContain(Q_VALUE);
- assertFalse(result.isValid());
- assertEquals(2, result.getMessageList().size());
+ assertThat(Validated.validateEntryNotBlankNotBlank(makeEntry(BLANKS, OTHER)).getResult()).contains(Q_KEY)
+ .contains(Validated.IS_BLANK).doesNotContain(Q_VALUE);
- Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+ // try invalid values for the value
+ assertThat(Validated.validateEntryNotBlankNotBlank(makeEntry(TEXT, null)).getResult()).contains(Q_VALUE)
+ .contains(Validated.IS_BLANK).doesNotContain(Q_KEY);
- PfValidationMessage msg = it.next();
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("validField invalid-error-A"));
+ assertThat(Validated.validateEntryNotBlankNotBlank(makeEntry(TEXT, BLANKS)).getResult()).contains(Q_VALUE)
+ .contains(Validated.IS_BLANK).doesNotContain(Q_KEY);
- msg = it.next();
- assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
- assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
- assertTrue(msg.getMessage().contains("validField invalid-error-B"));
+ // both invalid
+ assertThat(Validated.validateEntryNotBlankNotBlank(makeEntry(BLANKS, BLANKS)).getResult()).contains(Q_KEY)
+ .contains(Q_VALUE);
}
@Test
- public void testMakeKey() {
- assertThatThrownBy(() -> validated.makeKey(null)).isInstanceOf(NullPointerException.class);
+ public void testValidateEntryNotBlankNotNull() {
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(TEXT, OTHER))).isNull();
- PfKey key = validated.makeKey(this);
- assertEquals(MY_TO_STRING, key.toString());
- }
+ // try invalid values for the key
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(null, OTHER)).getResult()).contains(Q_KEY)
+ .contains(Validated.IS_BLANK).doesNotContain(Q_VALUE);
+
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(BLANKS, OTHER)).getResult()).contains(Q_KEY)
+ .contains(Validated.IS_BLANK).doesNotContain(Q_VALUE);
- @Override
- public String toString() {
- return MY_TO_STRING;
+ // try invalid values for the value
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(TEXT, null)).getResult()).contains(Q_VALUE)
+ .contains(Validated.IS_NULL).doesNotContain(Q_KEY);
+
+ // blanks should have no impact for the value
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(TEXT, BLANKS))).isNull();
+
+ // both invalid
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(BLANKS, null)).getResult()).contains(Q_KEY)
+ .contains(Q_VALUE);
}
- private static class MyValid extends Validated {
- private boolean valid;
- private int index;
+ @Test
+ public void testValidateEntryValueNotNull() {
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(TEXT, OTHER))).isNull();
- public MyValid(int index, boolean valid) {
- this.index = index;
- this.valid = valid;
- }
+ // blanks should have no impact
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(BLANKS, OTHER))).isNull();
+ assertThat(Validated.validateEntryNotBlankNotNull(makeEntry(TEXT, BLANKS))).isNull();
- @Override
- public PfValidationResult validate(PfValidationResult result) {
- if (!valid) {
- this.addError(this, "index." + index, result, "wrong value");
- }
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(null, OTHER)).getResult()).contains(Q_KEY)
+ .contains(Validated.IS_NULL).doesNotContain(Q_VALUE);
- return result;
- }
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(TEXT, null)).getResult()).contains(Q_VALUE)
+ .contains(Validated.IS_NULL).doesNotContain(Q_KEY);
- @Override
- public String toString() {
- return MY_TO_STRING;
- }
+ // should invoke the value's validate() method, which should return success
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(TEXT, new MyString(TEXT)))).isNull();
+
+ // should invoke the value's validate() method, which should return failure
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(TEXT, new MyString(OTHER))).getResult())
+ .contains(Q_VALUE).contains(NOT_SAME).doesNotContain(Q_KEY);
+
+ // both invalid
+ assertThat(Validated.validateEntryValueNotNull(makeEntry(null, null)).getResult()).contains(Q_KEY)
+ .contains(Q_VALUE);
}
- private static class MyConcept extends PfConceptKey {
- private static final long serialVersionUID = 1L;
+ @Test
+ public void testGetKeyId() {
+ // not a key field - should just use the given value
+ BeanValidationResult result = new BeanValidationResult("", this);
+ Validated.addResult(result, MY_FIELD, TEXT, "some message");
+ assertThat(result.getResult()).contains(MY_FIELD).contains(TEXT).contains("some message");
+
+ // repeat with a key field - should use the key's ID
+ result = new BeanValidationResult("", this);
+ Validated.addResult(result, MY_FIELD, new PfConceptKey(NAME, VERSION), "some message");
+ assertThat(result.getResult()).contains(MY_FIELD).contains("myKey:1.0.0").contains("some message");
+ }
- private boolean valid;
- private int index;
+ private <V> Map.Entry<String, V> makeEntry(String key, V value) {
+ Map<String, V> map = new HashMap<>();
+ map.put(key, value);
+ return map.entrySet().iterator().next();
+ }
- public MyConcept(int index, boolean valid) {
- this.index = index;
- this.valid = valid;
- }
+ @AllArgsConstructor
+ private static class MyString extends Validated {
+ private final String text;
@Override
- public PfValidationResult validate(PfValidationResult result) {
- if (!valid) {
- new Validated().addError(this, "index." + index, result, "wrong value");
+ public ValidationResult validate(String fieldName) {
+ if (TEXT.equals(text)) {
+ return null;
}
- return result;
- }
-
- @Override
- public String toString() {
- return MY_TO_STRING;
+ return new ObjectValidationResult(fieldName, text, ValidationStatus.INVALID, NOT_SAME);
}
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java b/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java
deleted file mode 100644
index 6030d2ab9..000000000
--- a/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 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.
- * 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.onap.policy.models.base;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
-
-public class ValidationTest {
-
- private static final String HELLO = "hello";
- private static final String SOME_MESSAGE = "Some message";
-
- @Test
- public void testValidation1() {
- PfValidationResult result = new PfValidationResult();
- PfConceptKey pfKeyey = new PfConceptKey("PK", "0.0.1");
- result = pfKeyey.validate(result);
-
- assertNotNull(result);
- assertTrue(result.isOk());
- assertTrue(result.isValid());
- assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
- assertNotNull(result.getMessageList());
-
- PfValidationMessage vmess0 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.VALID, SOME_MESSAGE);
- result.addValidationMessage(vmess0);
-
- assertTrue(result.isOk());
- assertTrue(result.isValid());
- assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
- assertNotNull(result.getMessageList());
- assertNotNull(HELLO, result.toString());
-
- PfValidationMessage vmess1 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.OBSERVATION, SOME_MESSAGE);
- result.addValidationMessage(vmess1);
-
- assertTrue(result.isOk());
- assertTrue(result.isValid());
- assertEquals(PfValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
- assertNotNull(result.getMessageList());
- assertNotNull(HELLO, result.toString());
- }
-
-
- @Test
- public void testValidation2() {
- PfValidationResult result = new PfValidationResult();
-
- PfValidationMessage vmess2 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.WARNING, SOME_MESSAGE);
- result.addValidationMessage(vmess2);
-
- assertFalse(result.isOk());
- assertTrue(result.isValid());
- assertEquals(PfValidationResult.ValidationResult.WARNING, result.getValidationResult());
- assertNotNull(result.getMessageList());
- assertNotNull(HELLO, result.toString());
-
- PfValidationMessage vmess3 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.INVALID, SOME_MESSAGE);
- result.addValidationMessage(vmess3);
-
- assertFalse(result.isOk());
- assertFalse(result.isValid());
- assertEquals(PfValidationResult.ValidationResult.INVALID, result.getValidationResult());
- assertNotNull(result.getMessageList());
- assertNotNull(HELLO, result.toString());
-
- assertEquals(PfValidationResult.ValidationResult.INVALID, result.getMessageList().get(1).getValidationResult());
- assertEquals(SOME_MESSAGE, result.getMessageList().get(1).getMessage());
- assertEquals(PfConceptKey.class.getName(), result.getMessageList().get(1).getObservedClass());
- assertEquals(PfConceptKey.getNullKey(), result.getMessageList().get(1).getObservedKey());
- }
-
- @Test
- public void testValidationAppend() {
- PfValidationResult result = new PfValidationResult();
-
- PfValidationResult result2 = new PfValidationResult();
- PfValidationMessage vmess1 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.OBSERVATION, "Message 1");
- result2.addValidationMessage(vmess1);
-
- result.append(result2);
- assertEquals(1, result.getMessageList().size());
- assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
-
- PfValidationResult result3 = new PfValidationResult();
- PfValidationMessage vmess2 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.WARNING, "Message 2");
- result3.addValidationMessage(vmess2);
- result.append(result3);
- assertEquals(2, result.getMessageList().size());
- assertEquals(ValidationResult.WARNING, result.getValidationResult());
-
- PfValidationResult result4 = new PfValidationResult();
- PfValidationMessage vmess3 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.INVALID, "Message 3");
- PfValidationMessage vmess4 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
- ValidationResult.VALID, "Message 4");
- result4.addValidationMessage(vmess3);
- result4.addValidationMessage(vmess4);
- result.append(result4);
- assertEquals(4, result.getMessageList().size());
- assertEquals(ValidationResult.INVALID, result.getValidationResult());
- }
-}
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 be398b95f..67a450702 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
@@ -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.
@@ -27,13 +27,12 @@ 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.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.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
@Data
@EqualsAndHashCode(callSuper = false)
@@ -102,20 +101,11 @@ public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuth
}
@Override
- public PfValidationResult validate(PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public ValidationResult 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 && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property description may not be blank"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateNotBlank("description", description, false));
return result;
}
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 81ebb6e59..5a5891ad6 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
@@ -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.
@@ -24,9 +24,9 @@ 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.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfValidationResult;
public class DummyPfKey extends PfKey {
private static final long serialVersionUID = 1L;
@@ -75,7 +75,7 @@ public class DummyPfKey extends PfKey {
}
@Override
- public PfValidationResult validate(PfValidationResult result) {
+ public ValidationResult validate(@NonNull String fieldName) {
return null;
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java
index 764b91b24..f828fba09 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.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,13 @@ import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
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.PfModel;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationResult;
@Data
@EqualsAndHashCode(callSuper = true)
@@ -108,11 +109,12 @@ public class DummyPfModel extends PfModel {
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
+ int count = 0;
for (PfKey pfKey : keyList) {
- result = pfKey.validate(result);
+ result.addResult(pfKey.validate("keyList." + (count++)));
}
return result;
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java b/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java
index 665651599..4ef3eb94d 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/DummyConceptEntity.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.
@@ -31,11 +31,11 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
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.PfValidationResult;
@Entity
@Table(name = "DummyConceptEntity")
@@ -100,8 +100,10 @@ public class DummyConceptEntity extends PfConcept {
}
@Override
- public PfValidationResult validate(final PfValidationResult result) {
- return key.validate(result);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
+ result.addResult(key.validate("key"));
+ return result;
}
@Override
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java b/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java
index ee755b4f2..abd9e53ca 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/DummyReferenceEntity.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.
@@ -30,11 +30,11 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
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.PfValidationResult;
@Entity
@Table(name = "DummyReferenceEntity")
@@ -82,8 +82,10 @@ public class DummyReferenceEntity extends PfConcept {
}
@Override
- public PfValidationResult validate(final PfValidationResult result) {
- return key.validate(result);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
+ result.addResult(key.validate("key"));
+ return result;
}
@Override
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/DummyTimestampEntity.java b/models-dao/src/test/java/org/onap/policy/models/dao/DummyTimestampEntity.java
index 18d87aeba..37b18c113 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/DummyTimestampEntity.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/DummyTimestampEntity.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.
@@ -29,10 +30,10 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
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.PfValidationResult;
@Entity
@Table(name = "DummyTimestampEntity")
@@ -80,8 +81,10 @@ public class DummyTimestampEntity extends PfConcept {
}
@Override
- public PfValidationResult validate(final PfValidationResult result) {
- return key.validate(result);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
+ result.addResult(key.validate("key"));
+ return result;
}
@Override
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
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java
index 63945174a..81c46423a 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignment.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.
@@ -24,7 +25,6 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
@@ -34,14 +34,13 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
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.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.tosca.authorative.concepts.ToscaCapabilityAssignment;
/**
@@ -160,78 +159,13 @@ public class JpaToscaCapabilityAssignment extends JpaToscaEntityType<ToscaCapabi
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (properties != null) {
- result.append(validateProperties(new PfValidationResult()));
- }
-
- if (attributes != null) {
- result.append(validateAttributes(new PfValidationResult()));
- }
-
- if (occurrences != null) {
- result.append(validateOccurrences(new PfValidationResult()));
- }
-
- return result;
- }
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
+ validateMap(result, "attributes", attributes, Validated::validateEntryValueNotNull);
- /**
- * Validate the properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (Entry<String, String> propertyEntry : properties.entrySet()) {
- if (propertyEntry.getValue() == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "capability assignment property " + propertyEntry.getKey() + " value may not be null"));
- }
- }
- return result;
- }
-
- /**
- * Validate the attributes.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateAttributes(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (Entry<String, String> attributeEntry : attributes.entrySet()) {
- if (attributeEntry.getValue() == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "capability assignment attribute " + attributeEntry.getKey() + " value may not be null"));
- }
- }
- return result;
- }
-
- /**
- * Validate the occurrences.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateOccurrences(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (Integer occurrence : occurrences) {
- if (occurrence == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "capability assignment occurrence value may not be null "));
- } else if (occurrence < 0 && !occurrence.equals(JPA_UNBOUNDED_VALUE)) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "capability assignment occurrence value may not be negative"));
- }
- }
+ validateList(result, "occurrences", occurrences, validateMin(0, JPA_UNBOUNDED_VALUE, true));
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java
index 5afc89275..18e77bbf1 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignments.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.
@@ -31,10 +32,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -105,8 +106,8 @@ public class JpaToscaCapabilityAssignments
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
for (JpaToscaCapabilityAssignment assignment : this.getConceptMap().values()) {
ToscaUtils.getEntityTypeAncestors(this, assignment, result);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java
index 4db779557..3a4956c4f 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityType.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.
@@ -37,15 +38,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
+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.tosca.authorative.concepts.ToscaCapabilityType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -156,41 +156,16 @@ public class JpaToscaCapabilityType extends JpaToscaEntityType<ToscaCapabilityTy
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (getKey().isNullVersion()) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "key version is a null version"));
- }
+ result.addResult(validateKeyVersionNotNull("key", getKey()));
- if (properties != null) {
- result = validateProperties(result);
- }
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
return result;
}
- /**
- * Validate the capabiltiy type properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaProperty property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "capability type property may not be null "));
- } else {
- result = property.validate(result);
- }
- }
- return result;
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java
index 6ec6de56e..e1feaed95 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypes.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.
@@ -31,9 +32,9 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -99,8 +100,8 @@ public class JpaToscaCapabilityTypes extends PfConceptContainer<JpaToscaCapabili
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
// Check that all ancestors of this policy type exist
for (JpaToscaCapabilityType capabilityType : this.getConceptMap().values()) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
index 58ac9e326..d80c14a97 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
@@ -41,15 +41,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
+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.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -165,54 +164,15 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (constraints != null) {
- validateConstraints(result);
- }
-
- if (properties != null) {
- result = validateProperties(result);
- }
+ validateList(result, "constraints", constraints, Validated::validateNotNull);
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
return result;
}
- /**
- * Validate the constraints.
- *
- * @param result where to put the validation results
- */
- private void validateConstraints(@NonNull final PfValidationResult result) {
- for (JpaToscaConstraint constraint : constraints) {
- if (constraint == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "data type constraint may not be null "));
- }
- }
- }
-
- /**
- * Validate the properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaProperty property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "data type property may not be null "));
- } else {
- result = property.validate(result);
- }
- }
- return result;
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java
index e570c05bb..faa1ce186 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java
@@ -30,11 +30,10 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -103,8 +102,8 @@ public class JpaToscaDataTypes extends PfConceptContainer<JpaToscaDataType, Tosc
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
for (JpaToscaDataType dataType : this.getConceptMap().values()) {
ToscaUtils.getEntityTypeAncestors(this, dataType, result);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
index 549d93e8a..169d7f244 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -35,15 +35,13 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-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.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.tosca.authorative.concepts.ToscaEntity;
/**
@@ -188,38 +186,17 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
}
@Override
- public PfValidationResult validate(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));
- if (derivedFrom != null && derivedFrom.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "derived from key is a null key"));
- }
-
- if (metadata != null) {
- for (Entry<String, String> metadataEntry : metadata.entrySet()) {
- if (!ParameterValidationUtils.validateStringParameter(metadataEntry.getKey())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property metadata key may not be null"));
- }
- if (!ParameterValidationUtils.validateStringParameter(metadataEntry.getValue())) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property metadata value may not be null"));
- }
- }
+ if (derivedFrom != null) {
+ result.addResult(validateKeyNotNull("derivedFrom", derivedFrom));
}
- if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property description may not be blank"));
- }
+ validateMap(result, "metadata", metadata, Validated::validateEntryNotBlankNotBlank);
+ result.addResult(validateNotBlank("description", description, false));
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java
index 90bb0a89e..f0d7b9caa 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.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-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,13 +34,11 @@ 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.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.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* Class to represent the EventFilter in TOSCA definition.
@@ -124,30 +122,13 @@ public class JpaToscaEventFilter extends PfConcept {
}
@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 (node == null || node.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "node on an event filter may not be null"));
- }
-
- if (requirement != null && requirement.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "event filter requirement may not be blank"));
- }
-
- if (capability != null && capability.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "event filter capability may not be blank"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("node", node));
+ result.addResult(validateNotBlank("requirement", requirement, false));
+ result.addResult(validateNotBlank("capability", capability, false));
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java
index d65689d8e..c86c34b92 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -32,12 +32,12 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
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.PfModel;
import org.onap.policy.models.base.PfModelService;
-import org.onap.policy.models.base.PfValidationResult;
/**
* A container class for a TOSCA model with multiple service templates. This class is a container class that allows a
@@ -117,10 +117,12 @@ public class JpaToscaModel extends PfModel {
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- return serviceTemplates.validate(result);
+ result.addResult(serviceTemplates.validate("serviceTemplates"));
+
+ return result;
}
@Override
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
index 5fccbe27a..05aefa797 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.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.
@@ -41,7 +42,7 @@ 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.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfAuthorative;
@@ -50,9 +51,7 @@ import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelRuntimeException;
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.tosca.authorative.concepts.ToscaCapabilityAssignment;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -231,44 +230,15 @@ public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate>
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (StringUtils.isBlank(type)) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "node template type may not be null"));
- }
-
- if (properties != null) {
- result.append(validateProperties(new PfValidationResult()));
- }
+ result.addResult(validateNotBlank("type", type, true));
- if (requirements != null) {
- result.append(requirements.validate(result));
- }
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
+ validateOptional(result, "requirements", requirements);
+ validateOptional(result, "capabilities", capabilities);
- if (capabilities != null) {
- result.append(validateProperties(capabilities.validate(result)));
- }
-
- return result;
- }
-
- /**
- * Validate the properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (String property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "topology template property may not be null "));
- }
- }
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java
index 6c83f67c5..6cc7a1f4e 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplates.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.
@@ -29,11 +30,10 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -99,8 +99,8 @@ public class JpaToscaNodeTemplates extends PfConceptContainer<JpaToscaNodeTempla
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
// Check that all ancestors of this node template exist
for (JpaToscaNodeTemplate nodeTemplate : this.getConceptMap().values()) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java
index 26684b583..f39f9b914 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.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.
@@ -43,15 +44,14 @@ import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
+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.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -185,42 +185,14 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "key version is a null version"));
- }
-
- if (properties != null) {
- result = validateProperties(result);
- }
-
- if (requirements != null) {
- result = requirements.validate(result);
- }
-
- return result;
- }
+ result.addResult(validateKeyVersionNotNull("key", getKey()));
- /**
- * Validate the capabiltiy type properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
+ validateOptional(result, "requirements", requirements);
- for (JpaToscaProperty property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "node type property may not be null "));
- } else {
- result = property.validate(result);
- }
- }
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java
index 5eb5a2c49..b1fe40b78 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTypes.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.
@@ -29,11 +30,10 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -99,8 +99,8 @@ public class JpaToscaNodeTypes extends PfConceptContainer<JpaToscaNodeType, Tosc
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
// Check that all ancestors of this policy type exist
for (JpaToscaNodeType nodeType : this.getConceptMap().values()) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java
index 216e877cc..19e0e5fd5 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaParameter.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.
@@ -31,15 +32,13 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
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.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
/**
@@ -161,20 +160,11 @@ public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaP
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (key.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "paremeter key is a null key"));
- }
-
- result = key.validate(result);
-
- if (type == null || type.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "parameter type may not be null"));
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("type", type));
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java
index ba32ac314..7c1022c84 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java
@@ -30,12 +30,11 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -105,8 +104,8 @@ public class JpaToscaPolicies extends PfConceptContainer<JpaToscaPolicy, ToscaPo
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
for (JpaToscaPolicy policy : this.getConceptMap().values()) {
ToscaUtils.getEntityTypeAncestors(this, policy, result);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
index 518a0884b..ae7b34297 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
@@ -26,7 +26,6 @@ package org.onap.policy.models.tosca.simple.concepts;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
@@ -40,18 +39,16 @@ import javax.ws.rs.core.Response;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
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.PfModelRuntimeException;
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.tosca.authorative.concepts.ToscaPolicy;
/**
@@ -234,67 +231,15 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "key version is a null version"));
- }
-
- if (type == null || type.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "type is null or a null key"));
- } else {
- result = type.validate(result);
- }
-
- if (properties != null) {
- validateProperties(result);
- }
+ result.addResult(validateKeyVersionNotNull("key", getKey()));
+ result.addResult(validateKeyNotNull("type", type));
- if (targets != null) {
- result = validateTargets(result);
- }
-
- return result;
- }
+ validateMap(result, "properties", properties, Validated::validateEntryNotBlankNotNull);
+ validateList(result, "targets", targets, Validated::validateNotNull);
- /**
- * Validate the policy properties.
- *
- * @param result where to put the validation results
- */
- private void validateProperties(final PfValidationResult result) {
-
- for (Entry<String, String> propertyEntry : properties.entrySet()) {
- if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy property key may not be null "));
- } else if (propertyEntry.getValue() == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy property value may not be null "));
- }
- }
- }
-
- /**
- * Validate the policy targets.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateTargets(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (PfConceptKey target : targets) {
- if (target == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy target may not be null "));
- } else {
- result = target.validate(result);
- }
- }
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
index 7a5493ce1..665c79d1f 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.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-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,15 +40,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
+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.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -188,86 +187,15 @@ public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> impl
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "key version is a null version"));
- }
-
- if (properties != null) {
- result = validateProperties(result);
- }
-
- if (targets != null) {
- result = validateTargets(result);
- }
-
- if (triggers != null) {
- result = validateTriggers(result);
- }
+ result.addResult(validateKeyVersionNotNull("key", getKey()));
- return result;
- }
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
+ validateList(result, "targets", targets, Validated::validateNotNull);
+ validateList(result, "triggers", triggers, Validated::validateNotNull);
- /**
- * Validate the policy properties.
- *
- * @param result The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaProperty property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy property may not be null "));
- } else {
- result = property.validate(result);
- }
- }
- return result;
- }
-
- /**
- * Validate the policy targets.
- *
- * @param result The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateTargets(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (PfConceptKey target : targets) {
- if (target == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy target may not be null "));
- } else {
- result = target.validate(result);
- }
- }
- return result;
- }
-
- /**
- * Validate the policy triggers.
- *
- * @param result The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateTriggers(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaTrigger trigger : triggers) {
- if (trigger == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy trigger may not be null "));
- } else {
- result = trigger.validate(result);
- }
- }
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java
index 0a3d070ca..c20cada8f 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java
@@ -30,11 +30,10 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -103,8 +102,8 @@ public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType,
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
// Check that all ancestors of this policy type exist
for (JpaToscaPolicyType policyType : this.getConceptMap().values()) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java
index c56dc6a42..a7156bbab 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.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-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,6 +38,7 @@ 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.utils.coder.YamlJsonTranslator;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
@@ -45,9 +46,7 @@ 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.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status;
@@ -241,52 +240,18 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative<ToscaPr
}
@Override
- public PfValidationResult validate(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 (type == null || type.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property type may not be null"));
- }
-
- return validateFields(result);
- }
-
- /**
- * Validate the property fields.
- *
- * @param resultIn the incoming validation results so far
- * @return the validation results including this validation
- */
- private PfValidationResult validateFields(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateKeyNotNull("type", type));
+ result.addResult(validateNotBlank("description", description, false));
+ result.addResult(validateNotBlank("defaultValue", defaultValue, false));
- if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property description may not be blank"));
- }
+ validateList(result, "constraints", constraints, Validated::validateNotNull);
+ validateOptional(result, "entrySchema", entrySchema);
- if (defaultValue != null && defaultValue.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property default value may not be null"));
- }
-
- if (constraints != null) {
- for (JpaToscaConstraint constraint : constraints) {
- if (constraint == null) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property constraint may not be null "));
- }
- }
- }
- return (entrySchema != null ? entrySchema.validate(result) : result);
+ return result;
}
@Override
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java
index d3d06d4a0..4bbcea4ed 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipType.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.
@@ -37,15 +38,14 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
+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.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -153,41 +153,16 @@ public class JpaToscaRelationshipType extends JpaToscaEntityType<ToscaRelationsh
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "key version is a null version"));
- }
+ result.addResult(validateKeyVersionNotNull("key", getKey()));
- if (properties != null) {
- result = validateProperties(result);
- }
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
return result;
}
- /**
- * Validate the capabiltiy type properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaProperty property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "relationship type property may not be null "));
- } else {
- result = property.validate(result);
- }
- }
- return result;
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
if (otherConcept == null) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java
index 28e1d602c..eed351df5 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRelationshipTypes.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.
@@ -29,11 +30,10 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -100,8 +100,8 @@ public class JpaToscaRelationshipTypes extends PfConceptContainer<JpaToscaRelati
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
// Check that all ancestors of this policy type exist
for (JpaToscaRelationshipType relationshipType : this.getConceptMap().values()) {
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java
index aebc31caf..bf1249d4b 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirement.java
@@ -37,14 +37,13 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
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.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement;
/**
@@ -63,7 +62,7 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
private static final long serialVersionUID = 2785481541573683089L;
private static final String AUTHORATIVE_UNBOUNDED_LITERAL = "UNBOUNDED";
- private static final Double JPA_UNBOUNDED_VALUE = -1.0;
+ private static final Integer JPA_UNBOUNDED_VALUE = -1;
@Column
private String capability;
@@ -75,7 +74,7 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
private String relationship;
@ElementCollection
- private List<Double> occurrences;
+ private List<Integer> occurrences;
@ElementCollection
@Lob
@@ -133,11 +132,11 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
if (occurrences != null) {
List<Object> occurrencesList = new ArrayList<>(occurrences);
- for (Double occurrence : occurrences) {
- if (occurrence == JPA_UNBOUNDED_VALUE) {
+ for (Integer occurrence : occurrences) {
+ if (JPA_UNBOUNDED_VALUE.equals(occurrence)) {
occurrencesList.add(AUTHORATIVE_UNBOUNDED_LITERAL);
} else {
- occurrencesList.add(occurrence.doubleValue());
+ occurrencesList.add(occurrence);
}
}
toscaRequirement.setOccurrences(occurrencesList);
@@ -170,7 +169,7 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
if (occurrence.equals(AUTHORATIVE_UNBOUNDED_LITERAL)) {
occurrences.add(JPA_UNBOUNDED_VALUE);
} else {
- occurrences.add((Double) occurrence);
+ occurrences.add(((Number) occurrence).intValue());
}
}
}
@@ -186,11 +185,6 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
}
@Override
- public List<PfKey> getKeys() {
- return super.getKeys();
- }
-
- @Override
public void clean() {
super.clean();
@@ -202,58 +196,11 @@ public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
-
- if (properties != null) {
- result = validateProperties(result);
- }
-
- if (occurrences != null) {
- result = validateOccurrences(result);
- }
-
- return result;
- }
-
- /**
- * Validate the properties.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateProperties(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (String property : properties.values()) {
- if (property == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(),
- PfValidationResult.ValidationResult.INVALID, "topology template property may not be null "));
- }
- }
- return result;
- }
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- /**
- * Validate the occurrences.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateOccurrences(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (Double occurrence : occurrences) {
- if (occurrence == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(),
- PfValidationResult.ValidationResult.INVALID, "requirement occurrence value may not be null "));
- }
- if (occurrence < -1.0) {
- result.addValidationMessage(
- new PfValidationMessage(getKey(), this.getClass(), PfValidationResult.ValidationResult.INVALID,
- "requirement occurrence value may not be negative"));
- }
- }
+ validateMap(result, "properties", properties, Validated::validateEntryValueNotNull);
+ validateList(result, "occurrences", occurrences, validateMin(0, JPA_UNBOUNDED_VALUE, true));
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java
index 08dbb43de..283c161d0 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirements.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.
@@ -29,12 +30,11 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement;
import org.onap.policy.models.tosca.utils.ToscaUtils;
@@ -104,8 +104,8 @@ public class JpaToscaRequirements extends PfConceptContainer<JpaToscaRequirement
}
@Override
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
for (JpaToscaRequirement requirement : this.getConceptMap().values()) {
ToscaUtils.getEntityTypeAncestors(this, requirement, result);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java
index 6bd1b44cd..bae36299a 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinition.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-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,14 +33,13 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
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.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
@@ -53,14 +52,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
-public class JpaToscaSchemaDefinition
+public class JpaToscaSchemaDefinition extends Validated
implements PfAuthorative<ToscaSchemaDefinition>, Serializable, Comparable<JpaToscaSchemaDefinition> {
private static final long serialVersionUID = 3645882081163287058L;
- // Recurring string constants
- private static final String ENTRY_SCHEMA = "EntrySchema";
-
@Column
private PfConceptKey type;
@@ -147,34 +143,14 @@ public class JpaToscaSchemaDefinition
description = (description != null ? description.trim() : null);
}
- /**
- * Validate the entry schema.
- *
- * @param resultIn the incoming result
- * @return the ooutput result witht he result of this validation
- */
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- if (type == null || type.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
- this.getClass(), ValidationResult.INVALID, "entry schema type may not be null"));
- }
+ @Override
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ BeanValidationResult result = new BeanValidationResult(fieldName, this);
- if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
- this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank"));
- }
+ result.addResult(validateKeyNotNull("type", type));
+ result.addResult(validateNotBlank("description", description, false));
- if (constraints != null) {
- for (JpaToscaConstraint constraint : constraints) {
- if (constraint == null) {
- result.addValidationMessage(
- new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
- this.getClass(), ValidationResult.INVALID, "property constraint may not be null "));
- }
- }
- }
+ validateList(result, "constraints", constraints, Validated::validateNotNull);
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
index 791801616..d4e51840b 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -41,14 +41,11 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-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.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
@@ -363,46 +360,28 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
- PfValidationResult result = super.validate(resultIn);
+ public BeanValidationResult validate(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
- if (!ParameterValidationUtils.validateStringParameter(toscaDefinitionsVersion)) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "service template tosca definitions version may not be null"));
- }
-
- if (dataTypes != null) {
- result = dataTypes.validate(result);
- }
-
- if (capabilityTypes != null) {
- result = capabilityTypes.validate(result);
- }
-
- if (relationshipTypes != null) {
- result = relationshipTypes.validate(result);
- }
-
- if (nodeTypes != null) {
- result = nodeTypes.validate(result);
- }
-
- if (policyTypes != null) {
- result = policyTypes.validate(result);
- }
+ result.addResult(validateNotBlank("toscaDefinitionsVersion", toscaDefinitionsVersion, true));
- if (topologyTemplate != null) {
- result = topologyTemplate.validate(result);
- }
+ validateOptional(result, "dataTypes", dataTypes);
+ validateOptional(result, "capabilityTypes", capabilityTypes);
+ validateOptional(result, "relationshipTypes", relationshipTypes);
+ validateOptional(result, "nodeTypes", nodeTypes);
+ validateOptional(result, "policyTypes", policyTypes);
+ validateOptional(result, "topologyTemplate", topologyTemplate);
// No point in validating cross references if the structure of the individual parts are not valid
- if (!result.isOk()) {
+ if (!result.isValid()) {
return result;
}
validateReferencedDataTypes(result);
- return validatePolicyTypesInPolicies(result);
+ validatePolicyTypesInPolicies(result);
+
+ return result;
}
@Override
@@ -471,39 +450,35 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
* Validate that all data types referenced in policy types exist.
*
* @param result the validation result object to use for the validation result
- * @return the validation result object
+ * @param result where the results are added
*/
- private PfValidationResult validateReferencedDataTypes(final PfValidationResult result) {
+ private void validateReferencedDataTypes(final BeanValidationResult result) {
if (policyTypes == null) {
- return result;
+ return;
}
if (dataTypes != null) {
for (JpaToscaDataType dataType : dataTypes.getAll(null)) {
- validateReferencedDataTypesExists(dataType.getKey(), dataType.getReferencedDataTypes(), result);
+ validateReferencedDataTypesExists(dataType.getReferencedDataTypes(), result);
}
}
for (JpaToscaPolicyType policyType : policyTypes.getAll(null)) {
- validateReferencedDataTypesExists(policyType.getKey(), policyType.getReferencedDataTypes(), result);
+ validateReferencedDataTypesExists(policyType.getReferencedDataTypes(), result);
}
-
- return result;
}
/**
* Validate that the referenced data types exist for a collection of data type keys.
*
- * @param referencingEntityKey the key of the referencing entity
* @param dataTypeKeyCollection the data type key collection
- * @param result the result of the validation
+ * @param result where the results are added
*/
- private void validateReferencedDataTypesExists(final PfConceptKey referencingEntityKey,
- final Collection<PfConceptKey> dataTypeKeyCollection, final PfValidationResult result) {
+ private void validateReferencedDataTypesExists(
+ final Collection<PfConceptKey> dataTypeKeyCollection, final BeanValidationResult result) {
for (PfConceptKey dataTypeKey : dataTypeKeyCollection) {
if (dataTypes == null || dataTypes.get(dataTypeKey) == null) {
- result.addValidationMessage(new PfValidationMessage(referencingEntityKey, this.getClass(),
- ValidationResult.INVALID, "referenced data type " + dataTypeKey.getId() + " not found"));
+ addResult(result, "data type", dataTypeKey.getId(), NOT_FOUND);
}
}
}
@@ -511,30 +486,24 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
/**
* Validate that all policy types referenced in policies exist.
*
- * @param result the validation result object to use for the validation result
- * @return the validation result object
+ * @param result where the results are added
*/
- private PfValidationResult validatePolicyTypesInPolicies(PfValidationResult result) {
+ private void validatePolicyTypesInPolicies(BeanValidationResult result) {
if (topologyTemplate == null || topologyTemplate.getPolicies() == null
|| topologyTemplate.getPolicies().getConceptMap().isEmpty()) {
- return result;
+ return;
}
if (policyTypes == null || policyTypes.getConceptMap().isEmpty()) {
- result.addValidationMessage(new PfValidationMessage(this.getKey(), this.getClass(),
- ValidationResult.INVALID,
- "no policy types are defined on the service template for the policies in the topology template"));
- return result;
+ addResult(result, "policyTypes", policyTypes,
+ "no policy types are defined on the service template for the policies in the topology template");
+ return;
}
for (JpaToscaPolicy policy : topologyTemplate.getPolicies().getAll(null)) {
if (policyTypes.get(policy.getType()) == null) {
- result.addValidationMessage(
- new PfValidationMessage(policy.getKey(), this.getClass(), ValidationResult.INVALID,
- "policy type " + policy.getType().getId() + " referenced in policy not found"));
+ addResult(result, "policy type", policy.getType().getId(), NOT_FOUND);
}
}
-
- return result;
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
index 783e2b576..a8a21c3f0 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.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-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,13 +34,11 @@ import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
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.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* Class to represent the TimeInterval in TOSCA definition.
@@ -117,30 +115,21 @@ public class JpaToscaTimeInterval extends PfConcept {
}
@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);
+ result.addResult(validateKeyNotNull("key", key));
if (startTime == null || startTime.getTime() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "start time on time interval may not be null or zero"));
+ addResult(result, "startTime", startTime, "is null or zero");
}
if (endTime == null || endTime.getTime() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "end time on time interval may not be null or zero"));
+ addResult(result, "endTime", endTime, "is null or zero");
}
if (startTime != null && endTime != null && endTime.before(startTime)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "end time \"" + endTime.toString() + "\" on time interval may not be before start time \""
- + startTime.toString() + "\""));
+ addResult(result, "endTime", endTime, "is before startTime");
}
return result;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
index 32c459cc9..538680f5f 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -43,14 +43,13 @@ 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.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.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.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
@@ -241,54 +240,17 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
}
@Override
- public PfValidationResult validate(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 && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property description may not be blank"));
- }
-
- if (inputs != null) {
- result = validateInputs(result);
- }
-
-
- if (nodeTemplates != null) {
- result = nodeTemplates.validate(result);
- }
+ result.addResult(validateKeyNotNull("key", key));
+ result.addResult(validateNotBlank("description", description, false));
- if (policies != null) {
- result = policies.validate(result);
- }
+ validateMap(result, "inputs", inputs, Validated::validateEntryValueNotNull);
- return result;
- }
+ validateOptional(result, "nodeTemplates", nodeTemplates);
+ validateOptional(result, "policies", policies);
- /**
- * Validate the inputs.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateInputs(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaParameter input : inputs.values()) {
- if (input == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "topology template input may not be null "));
- } else {
- result = input.validate(result);
- }
- }
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java
index 10a9d2f66..e30754007 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.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-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,13 +36,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
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;
/**
* Class to represent the trigger of policy type in TOSCA definition.
@@ -177,57 +174,23 @@ public class JpaToscaTrigger extends PfConcept {
}
@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 && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "trigger description may not be blank"));
- }
+ result.addResult(validateKeyNotNull("key", key));
- if (!ParameterValidationUtils.validateStringParameter(eventType)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "event type on trigger must be defined"));
- }
+ result.addResult(validateNotBlank("description", description, false));
+ result.addResult(validateNotBlank("eventType", eventType, true));
- result = validateOptionalFields(result);
+ validateOptional(result, "schedule", schedule);
+ validateOptional(result, "targetFilter", targetFilter);
if (evaluations < 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "evaluations on trigger must be zero or a positive integer"));
- }
-
- if (method != null && method.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "method on trigger may not be blank"));
- }
-
- if (!ParameterValidationUtils.validateStringParameter(action)) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "action on trigger must be defined"));
+ addResult(result, "evaluations", evaluations, "is negative");
}
- return result;
- }
-
- /**
- * Validate optional fields.
- *
- * @param resultIn the validation result so far
- * @return the validation resutls including these fields
- */
- private PfValidationResult validateOptionalFields(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- result = (schedule != null ? schedule.validate(result) : result);
- result = (targetFilter != null ? targetFilter.validate(result) : result);
+ result.addResult(validateNotBlank("method", method, false));
+ result.addResult(validateNotBlank("action", action, true));
return result;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
index 459a32934..8fb4a7711 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.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.
@@ -26,13 +27,13 @@ import java.util.List;
import javax.ws.rs.core.Response;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptFilter;
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.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
@@ -107,9 +108,9 @@ public class SimpleToscaProvider {
ToscaServiceTemplateUtils.addFragment(dbServiceTemplate, incomingServiceTemplateFragment);
}
- PfValidationResult result = serviceTemplateToWrite.validate(new PfValidationResult());
+ BeanValidationResult result = serviceTemplateToWrite.validate("service template");
if (!result.isValid()) {
- throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString());
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.getResult());
}
new SimpleToscaServiceTemplateProvider().write(dao, serviceTemplateToWrite);
@@ -454,9 +455,11 @@ public class SimpleToscaProvider {
POLICY_TYPE + policyTypeKey.getId() + NOT_FOUND);
}
+ BeanValidationResult result = new BeanValidationResult("policy types", serviceTemplate);
+
for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) {
Collection<JpaToscaEntityType<ToscaEntity>> ancestorList = ToscaUtils
- .getEntityTypeAncestors(serviceTemplate.getPolicyTypes(), policyType, new PfValidationResult());
+ .getEntityTypeAncestors(serviceTemplate.getPolicyTypes(), policyType, result);
if (ancestorList.contains(policyType4Deletion)) {
throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, POLICY_TYPE + policyTypeKey.getId()
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java
index 7bf4d29e8..fe5299337 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java
@@ -25,12 +25,11 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelRuntimeException;
-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.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -57,12 +56,13 @@ public class ToscaServiceTemplateUtils {
*/
public static JpaToscaServiceTemplate addFragment(@NonNull final JpaToscaServiceTemplate originalTemplate,
@NonNull final JpaToscaServiceTemplate fragmentTemplate) {
- PfValidationResult result = new PfValidationResult();
+
+ BeanValidationResult result = new BeanValidationResult("incoming fragment", fragmentTemplate);
if (originalTemplate.compareToWithoutEntities(fragmentTemplate) != 0) {
- result.addValidationMessage(new PfValidationMessage(originalTemplate.getKey(),
- ToscaServiceTemplateUtils.class, ValidationResult.INVALID,
- "service template in incoming fragment does not equal existing service template"));
+ Validated.addResult(result, "service template",
+ originalTemplate.getKey(),
+ "does not equal existing service template");
}
JpaToscaServiceTemplate compositeTemplate = new JpaToscaServiceTemplate(originalTemplate);
@@ -79,20 +79,20 @@ public class ToscaServiceTemplateUtils {
.setPolicies(addFragmentEntitites(compositeTemplate.getTopologyTemplate().getPolicies(),
fragmentTemplate.getTopologyTemplate().getPolicies(), result));
} else {
- result.addValidationMessage(new PfValidationMessage(originalTemplate.getTopologyTemplate().getKey(),
- ToscaServiceTemplateUtils.class, ValidationResult.INVALID,
- "topology template in incoming fragment does not equal existing topology template"));
+ Validated.addResult(result, "topology template",
+ originalTemplate.getTopologyTemplate().getKey(),
+ "does not equal existing topology template");
}
} else if (fragmentTemplate.getTopologyTemplate() != null) {
compositeTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate(fragmentTemplate.getTopologyTemplate()));
}
if (result.isValid()) {
- result = compositeTemplate.validate(result);
+ result.addResult(compositeTemplate.validate("composite template"));
}
if (!result.isValid()) {
- String message = result.toString();
+ String message = result.getResult();
throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, message);
}
@@ -113,7 +113,7 @@ public class ToscaServiceTemplateUtils {
private static
<S extends PfConceptContainer<? extends JpaToscaEntityType<? extends ToscaEntity>, ? extends ToscaEntity>>
S addFragmentEntitites(final S compositeContainer, final S fragmentContainer,
- final PfValidationResult result) {
+ final BeanValidationResult result) {
if (compositeContainer == null) {
return fragmentContainer;
@@ -123,17 +123,22 @@ public class ToscaServiceTemplateUtils {
return compositeContainer;
}
+ BeanValidationResult result2 = new BeanValidationResult("incoming fragment", fragmentContainer);
+
for (Entry<PfConceptKey, ? extends JpaToscaEntityType<? extends ToscaEntity>> fragmentEntry : fragmentContainer
.getConceptMap().entrySet()) {
JpaToscaEntityType<? extends ToscaEntity> containerEntity =
compositeContainer.getConceptMap().get(fragmentEntry.getKey());
if (containerEntity != null && containerEntity.compareTo(fragmentEntry.getValue()) != 0) {
- result.addValidationMessage(new PfValidationMessage(fragmentEntry.getKey(),
- ToscaServiceTemplateUtils.class,
- ValidationResult.INVALID, "entity in incoming fragment does not equal existing entity"));
+ Validated.addResult(result, "entity", fragmentEntry.getKey(),
+ "does not equal existing entity");
}
}
+ if (!result2.isClean()) {
+ result.addResult(result2);
+ }
+
// This use of a generic map is required to get around typing errors in directly adding the fragment map to the
// original map
@SuppressWarnings("rawtypes")
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
index 70c5027d7..b806e4152 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.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.
@@ -27,15 +28,16 @@ import java.util.function.Function;
import javax.ws.rs.core.Response;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptContainer;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfNameVersion;
-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.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -219,7 +221,7 @@ public final class ToscaUtils {
*/
public static Collection<JpaToscaEntityType<ToscaEntity>> getEntityTypeAncestors(
@NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
- @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) {
+ @NonNull JpaToscaEntityType<?> entityType, @NonNull final BeanValidationResult result) {
PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom();
if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) {
@@ -227,9 +229,9 @@ public final class ToscaUtils {
}
if (entityType.getKey().equals(parentEntityTypeKey)) {
- result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
- ValidationResult.INVALID, "entity cannot be an ancestor of itself"));
- throw new PfModelRuntimeException(Response.Status.CONFLICT, result.toString());
+ result.addResult(new ObjectValidationResult("entity type", entityType.getKey().getId(),
+ ValidationStatus.INVALID, "ancestor of itself"));
+ throw new PfModelRuntimeException(Response.Status.CONFLICT, result.getResult());
}
@SuppressWarnings("unchecked")
@@ -237,8 +239,8 @@ public final class ToscaUtils {
.getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySetToReturn = new HashSet<>(ancestorEntitySet);
if (ancestorEntitySet.isEmpty()) {
- result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
- ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found"));
+ result.addResult(new ObjectValidationResult("parent", parentEntityTypeKey.getId(),
+ ValidationStatus.INVALID, Validated.NOT_FOUND));
} else {
for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) {
ancestorEntitySetToReturn.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result));
@@ -258,7 +260,7 @@ public final class ToscaUtils {
@NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
final String entityName, final String entityVersion) {
- PfValidationResult result = new PfValidationResult();
+ BeanValidationResult result = new BeanValidationResult("entity", entityName);
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<?>> filteredEntitySet =
@@ -270,7 +272,7 @@ public final class ToscaUtils {
}
if (!result.isValid()) {
- throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString());
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.getResult());
}
entityTypes.getConceptMap().entrySet()
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
index 5258053e9..c4d903986 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
@@ -31,7 +31,6 @@ import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -72,7 +71,7 @@ public class ToscaServiceTemplateMappingTest {
JpaToscaServiceTemplate internalServiceTemplate =
ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, policyFragmentServiceTemplate);
- assertTrue(internalServiceTemplate.validate(new PfValidationResult()).isValid());
+ assertTrue(internalServiceTemplate.validate("").isValid());
ToscaServiceTemplate plainPolicies2 = internalServiceTemplate.toAuthorative();
ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
@@ -92,11 +91,11 @@ public class ToscaServiceTemplateMappingTest {
ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate();
internalPolicyTypes.fromAuthorative(plainPolicyTypes);
- assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid());
+ assertTrue(internalPolicyTypes.validate("").isValid());
ToscaServiceTemplate plainPolicyTypes2 = internalPolicyTypes.toAuthorative();
JpaToscaServiceTemplate internalPolicyTypes2 = new JpaToscaServiceTemplate();
internalPolicyTypes2.fromAuthorative(plainPolicyTypes2);
- assertTrue(internalPolicyTypes2.validate(new PfValidationResult()).isValid());
+ assertTrue(internalPolicyTypes2.validate("").isValid());
assertEquals(0, internalPolicyTypes.compareTo(internalPolicyTypes2));
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
index ee2fee86b..9637d4252 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.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.
@@ -31,7 +32,7 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
/**
@@ -69,7 +70,7 @@ public class JpaToscaCapabilityAssignmentTest {
assertEquals(caKey, ca.getKeys().get(0));
ca.clean();
- ca.validate(new PfValidationResult());
+ ca.validate("");
assertThat(ca.getProperties()).isNullOrEmpty();
assertThat(ca.getAttributes()).isNullOrEmpty();
@@ -77,7 +78,7 @@ public class JpaToscaCapabilityAssignmentTest {
ca.setAttributes(null);
ca.setOccurrences(null);
ca.clean();
- ca.validate(new PfValidationResult());
+ ca.validate("");
assertEquals(null, ca.getProperties());
assertEquals(null, ca.getAttributes());
@@ -94,7 +95,7 @@ public class JpaToscaCapabilityAssignmentTest {
ca.setOccurrences(occurrences);
ca.clean();
- ca.validate(new PfValidationResult());
+ ca.validate("");
assertEquals("Untrimmed Value", ca.getProperties().get("Key0"));
assertEquals("Untrimmed Value", ca.getAttributes().get("Key0"));
@@ -102,10 +103,10 @@ public class JpaToscaCapabilityAssignmentTest {
ca.getAttributes().put("Key1", null);
ca.getOccurrences().add(null);
ca.getOccurrences().add(-12345);
- PfValidationResult result = ca.validate(new PfValidationResult());
- assertThat(result.toString()).contains("capability assignment property Key1 value may not be null");
- assertThat(result.toString()).contains("capability assignment attribute Key1 value may not be null");
- assertThat(result.toString()).contains("capability assignment occurrence value may not be negative");
+ assertThat(ca.validate("").getResult())
+ .contains("properties").contains("Key1").contains(Validated.IS_NULL)
+ .contains("attributes").contains("Key1").contains(Validated.IS_NULL)
+ .contains("occurrence").contains("value").contains("is below the minimum value: 0");
}
@Test
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
index 7168f488c..44bc5346b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
@@ -36,7 +36,6 @@ import org.junit.Test;
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.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
@@ -109,22 +108,22 @@ public class JpaToscaDataTypeTest {
tdt.clean();
assertEquals(tdtClone0, tdt);
- assertFalse(new JpaToscaDataType().validate(new PfValidationResult()).isValid());
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaDataType().validate("").isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.getConstraints().add(null);
- assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(tdt.validate("").isValid());
tdt.getConstraints().remove(null);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.getProperties().put(null, null);
- assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(tdt.validate("").isValid());
tdt.getProperties().remove(null);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
assertThatThrownBy(() -> {
tdt.validate(null);
- }).hasMessageMatching("result is marked .*on.*ull but is null");
+ }).hasMessageMatching("fieldName is marked .*on.*ull but is null");
ToscaDataType dat = new ToscaDataType();
dat.setName("name");
@@ -153,21 +152,21 @@ public class JpaToscaDataTypeTest {
JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop0"));
prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION));
- assertTrue(prop0.validate(new PfValidationResult()).isValid());
+ assertTrue(prop0.validate("").isValid());
dt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
assertTrue(dt0.getReferencedDataTypes().isEmpty());
JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop1"));
prop1.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
- assertTrue(prop1.validate(new PfValidationResult()).isValid());
+ assertTrue(prop1.validate("").isValid());
dt0.getProperties().put(prop1.getKey().getLocalName(), prop1);
assertEquals(1, dt0.getReferencedDataTypes().size());
JpaToscaProperty prop2 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop2"));
prop2.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
- assertTrue(prop2.validate(new PfValidationResult()).isValid());
+ assertTrue(prop2.validate("").isValid());
dt0.getProperties().put(prop2.getKey().getLocalName(), prop2);
assertEquals(1, dt0.getReferencedDataTypes().size());
@@ -176,7 +175,7 @@ public class JpaToscaDataTypeTest {
prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
prop3.setEntrySchema(new JpaToscaSchemaDefinition());
prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1"));
- assertTrue(prop3.validate(new PfValidationResult()).isValid());
+ assertTrue(prop3.validate("").isValid());
dt0.getProperties().put(prop3.getKey().getLocalName(), prop3);
assertEquals(3, dt0.getReferencedDataTypes().size());
@@ -185,7 +184,7 @@ public class JpaToscaDataTypeTest {
prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
prop4.setEntrySchema(new JpaToscaSchemaDefinition());
prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1"));
- assertTrue(prop4.validate(new PfValidationResult()).isValid());
+ assertTrue(prop4.validate("").isValid());
dt0.getProperties().put(prop4.getKey().getLocalName(), prop4);
assertEquals(3, dt0.getReferencedDataTypes().size());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
index 910db3654..83d040398 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -33,8 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
public class JpaToscaDataTypesTest {
@@ -71,23 +72,24 @@ public class JpaToscaDataTypesTest {
dtMapList.get(0).put("dt0", dt0);
assertNotNull(new JpaToscaDataTypes(dtMapList));
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
assertThatThrownBy(() -> new JpaToscaDataTypes(dtMapList).validate(null))
- .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ .hasMessageMatching("fieldName is marked .*on.*ull but is null");
dt0.setDerivedFrom(null);
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
dt0.setDerivedFrom("tosca.datatypes.Root");
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
dt0.setDerivedFrom("some.other.Thing");
- PfValidationResult result = new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult());
+ BeanValidationResult result = new JpaToscaDataTypes(dtMapList).validate("");
assertFalse(result.isValid());
- assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+ assertThat(result.getResult()).contains("parent").contains("some.other.Thing:0.0.0")
+ .contains(Validated.NOT_FOUND);
dt0.setDerivedFrom(null);
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
ToscaDataType dt1 = new ToscaDataType();
dt1.setName("dt1");
@@ -95,17 +97,17 @@ public class JpaToscaDataTypesTest {
dt1.setDescription("dt1 description");
dtMapList.get(0).put("dt1", dt1);
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
dt1.setDerivedFrom("dt0");
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
dt1.setDerivedFrom("dt2");
- result = new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult());
+ result = new JpaToscaDataTypes(dtMapList).validate("");
assertFalse(result.isValid());
- assertThat(result.toString()).contains("parent dt2:0.0.0 of entity not found");
+ assertThat(result.getResult()).contains("parent").contains("dt2:0.0.0").contains(Validated.NOT_FOUND);
dt1.setDerivedFrom("dt0");
- assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate("").isValid());
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
index f07a18223..ecffec877 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
@@ -31,7 +31,6 @@ 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;
/**
* DAO test for ToscaEventFilter.
@@ -107,30 +106,30 @@ public class JpaToscaEventFilterTest {
tef.clean();
assertEquals(tdtClone0, tef);
- assertFalse(new JpaToscaEventFilter().validate(new PfValidationResult()).isValid());
- assertTrue(tef.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaEventFilter().validate("").isValid());
+ assertTrue(tef.validate("").isValid());
tef.setRequirement(null);
- assertTrue(tef.validate(new PfValidationResult()).isValid());
+ assertTrue(tef.validate("").isValid());
tef.setRequirement("");
- assertFalse(tef.validate(new PfValidationResult()).isValid());
+ assertFalse(tef.validate("").isValid());
tef.setRequirement(A_REQUREMENT);
- assertTrue(tef.validate(new PfValidationResult()).isValid());
+ assertTrue(tef.validate("").isValid());
tef.setCapability(null);
- assertTrue(tef.validate(new PfValidationResult()).isValid());
+ assertTrue(tef.validate("").isValid());
tef.setCapability("");
- assertFalse(tef.validate(new PfValidationResult()).isValid());
+ assertFalse(tef.validate("").isValid());
tef.setCapability(A_CAPABILITY);
- assertTrue(tef.validate(new PfValidationResult()).isValid());
+ assertTrue(tef.validate("").isValid());
tef.setNode(null);
- assertFalse(tef.validate(new PfValidationResult()).isValid());
+ assertFalse(tef.validate("").isValid());
tef.setNode(PfConceptKey.getNullKey());
- assertFalse(tef.validate(new PfValidationResult()).isValid());
+ assertFalse(tef.validate("").isValid());
tef.setNode(nodeKey);
- assertTrue(tef.validate(new PfValidationResult()).isValid());
+ assertTrue(tef.validate("").isValid());
- assertThatThrownBy(() -> tef.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tef.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
index 61118c4b6..f0f42e647 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
@@ -33,7 +33,6 @@ import java.util.TreeMap;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelService;
-import org.onap.policy.models.base.PfValidationResult;
/**
* DAO test for ToscaDatatype.
@@ -101,13 +100,13 @@ public class JpaToscaModelTest {
tm.clean();
assertEquals(tttClone0, tm);
- assertFalse(new JpaToscaModel().validate(new PfValidationResult()).isValid());
- assertTrue(tm.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaModel().validate("").isValid());
+ assertTrue(tm.validate("").isValid());
tm.register();
assertTrue(PfModelService.existsModel(tm.getServiceTemplates().getId()));
PfModelService.deregisterModel(tm.getServiceTemplates().getId());
- assertThatThrownBy(() -> tm.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tm.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
index 47e34335b..15bde0b47 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -33,8 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
public class JpaToscaPoliciesTest {
@@ -73,23 +74,24 @@ public class JpaToscaPoliciesTest {
polMapList.get(0).put("pol0", pol0);
assertNotNull(new JpaToscaPolicies(polMapList));
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
assertThatThrownBy(() -> new JpaToscaPolicies(polMapList).validate(null))
- .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ .hasMessageMatching("fieldName is marked .*on.*ull but is null");
pol0.setDerivedFrom(null);
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
pol0.setDerivedFrom("tosca.Policies.Root");
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
pol0.setDerivedFrom("some.other.Thing");
- PfValidationResult result = new JpaToscaPolicies(polMapList).validate(new PfValidationResult());
+ BeanValidationResult result = new JpaToscaPolicies(polMapList).validate("");
assertFalse(result.isValid());
- assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+ assertThat(result.getResult()).contains("parent").contains("some.other.Thing:0.0.0")
+ .contains(Validated.NOT_FOUND);
pol0.setDerivedFrom(null);
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
ToscaPolicy pol1 = new ToscaPolicy();
pol1.setName("pol1");
@@ -99,17 +101,17 @@ public class JpaToscaPoliciesTest {
pol1.setTypeVersion("0.0.1");
polMapList.get(0).put("pol1", pol1);
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
pol1.setDerivedFrom("pol0");
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
pol1.setDerivedFrom("pol2");
- result = new JpaToscaPolicies(polMapList).validate(new PfValidationResult());
+ result = new JpaToscaPolicies(polMapList).validate("");
assertFalse(result.isValid());
- assertThat(result.toString()).contains("parent pol2:0.0.0 of entity not found");
+ assertThat(result.getResult()).contains("parent").contains("pol2:0.0.0").contains(Validated.NOT_FOUND);
pol1.setDerivedFrom("pol0");
- assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicies(polMapList).validate("").isValid());
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
index 7f356224f..48bcb0bee 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
@@ -37,7 +37,6 @@ import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
@@ -130,41 +129,41 @@ public class JpaToscaPolicyTest {
tp.clean();
assertEquals(tdtClone0, tp);
- assertFalse(new JpaToscaPolicy().validate(new PfValidationResult()).isValid());
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaPolicy().validate("").isValid());
+ assertTrue(tp.validate("").isValid());
tp.getProperties().put(null, null);
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.getProperties().remove(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.getProperties().put("Key", null);
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.getProperties().remove("Key");
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.getProperties().put(null, "Value");
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.getProperties().remove(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.getTargets().add(null);
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.getTargets().remove(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
PfConceptKey tpTypeKey = tp.getKey();
assertNotNull(tpTypeKey);
tp.setType(null);
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.setType(PfConceptKey.getNullKey());
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.setType(tpTypeKey);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
assertThatThrownBy(() -> {
tp.validate(null);
- }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ }).hasMessageMatching("fieldName is marked .*on.*ull but is null");
assertNotNull(tp.toAuthorative());
tp.getType().setVersion(PfKey.NULL_KEY_VERSION);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
index 43cacda19..b2f59c459 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
@@ -37,7 +37,6 @@ import org.junit.Test;
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.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
@@ -132,46 +131,46 @@ public class JpaToscaPolicyTypeTest {
tpt.clean();
assertEquals(tdtClone0, tpt);
- assertFalse(new JpaToscaPolicyType().validate(new PfValidationResult()).isValid());
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaPolicyType().validate("").isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.getProperties().put(null, null);
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.getProperties().remove(null);
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.getTargets().add(null);
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.getTargets().remove(null);
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.getTriggers().add(null);
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.getTriggers().remove(null);
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.getMetadata().put(null, null);
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.getMetadata().remove(null);
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.getMetadata().put("nullKey", null);
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.getMetadata().remove("nullKey");
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.setDescription("");
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.setDescription(A_DESCRIPTION);
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
tpt.setDerivedFrom(PfConceptKey.getNullKey());
- assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ assertFalse(tpt.validate("").isValid());
tpt.setDerivedFrom(derivedFromKey);
- assertTrue(tpt.validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate("").isValid());
- assertThatThrownBy(() -> tpt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tpt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null))
.hasMessageMatching("key is marked .*on.*ull but is null");
@@ -200,21 +199,21 @@ public class JpaToscaPolicyTypeTest {
JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0"));
prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION));
- assertTrue(prop0.validate(new PfValidationResult()).isValid());
+ assertTrue(prop0.validate("").isValid());
pt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
assertTrue(pt0.getReferencedDataTypes().isEmpty());
JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop1"));
prop1.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
- assertTrue(prop1.validate(new PfValidationResult()).isValid());
+ assertTrue(prop1.validate("").isValid());
pt0.getProperties().put(prop1.getKey().getLocalName(), prop1);
assertEquals(1, pt0.getReferencedDataTypes().size());
JpaToscaProperty prop2 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop2"));
prop2.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
- assertTrue(prop2.validate(new PfValidationResult()).isValid());
+ assertTrue(prop2.validate("").isValid());
pt0.getProperties().put(prop2.getKey().getLocalName(), prop2);
assertEquals(1, pt0.getReferencedDataTypes().size());
@@ -223,7 +222,7 @@ public class JpaToscaPolicyTypeTest {
prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
prop3.setEntrySchema(new JpaToscaSchemaDefinition());
prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1"));
- assertTrue(prop3.validate(new PfValidationResult()).isValid());
+ assertTrue(prop3.validate("").isValid());
pt0.getProperties().put(prop3.getKey().getLocalName(), prop3);
assertEquals(3, pt0.getReferencedDataTypes().size());
@@ -232,7 +231,7 @@ public class JpaToscaPolicyTypeTest {
prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
prop4.setEntrySchema(new JpaToscaSchemaDefinition());
prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1"));
- assertTrue(prop4.validate(new PfValidationResult()).isValid());
+ assertTrue(prop4.validate("").isValid());
pt0.getProperties().put(prop4.getKey().getLocalName(), prop4);
assertEquals(3, pt0.getReferencedDataTypes().size());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
index bbd407a14..76f91c56a 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -33,8 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
public class JpaToscaPolicyTypesTest {
@@ -71,23 +72,24 @@ public class JpaToscaPolicyTypesTest {
ptMapList.get(0).put("pt0", pt0);
assertNotNull(new JpaToscaPolicyTypes(ptMapList));
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
assertThatThrownBy(() -> new JpaToscaPolicyTypes(ptMapList).validate(null))
- .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ .hasMessageMatching("fieldName is marked .*on.*ull but is null");
pt0.setDerivedFrom(null);
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
pt0.setDerivedFrom("tosca.PolicyTypes.Root");
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
pt0.setDerivedFrom("some.other.Thing");
- PfValidationResult result = new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult());
+ BeanValidationResult result = new JpaToscaPolicyTypes(ptMapList).validate("");
assertFalse(result.isValid());
- assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+ assertThat(result.getResult()).contains("parent").contains("some.other.Thing:0.0.0")
+ .contains(Validated.NOT_FOUND);
pt0.setDerivedFrom(null);
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
ToscaPolicyType pt1 = new ToscaPolicyType();
pt1.setName("pt1");
@@ -95,17 +97,17 @@ public class JpaToscaPolicyTypesTest {
pt1.setDescription("pt1 description");
ptMapList.get(0).put("pt1", pt1);
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
pt1.setDerivedFrom("pt0");
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
pt1.setDerivedFrom("pt2");
- result = new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult());
+ result = new JpaToscaPolicyTypes(ptMapList).validate("");
assertFalse(result.isValid());
- assertThat(result.toString()).contains("parent pt2:0.0.0 of entity not found");
+ assertThat(result.getResult()).contains("parent").contains("pt2:0.0.0").contains(Validated.NOT_FOUND);
pt1.setDerivedFrom("pt0");
- assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate("").isValid());
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
index 0fa0d3f14..b82888108 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
@@ -36,7 +36,6 @@ import java.util.TreeMap;
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.tosca.authorative.concepts.ToscaProperty;
/**
@@ -158,42 +157,42 @@ public class JpaToscaPropertyTest {
tp.clean();
assertEquals(tdtClone0, tp);
- assertFalse(new JpaToscaProperty().validate(new PfValidationResult()).isValid());
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaProperty().validate("").isValid());
+ assertTrue(tp.validate("").isValid());
tp.setDescription(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.setDescription("");
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.setDescription(A_DESCRIPTION);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.setType(null);
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.setType(typeKey);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.setType(PfConceptKey.getNullKey());
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.setType(typeKey);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.setDefaultValue(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.setDefaultValue("");
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.setDefaultValue(DEFAULT_KEY);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.getConstraints().add(null);
- assertFalse(tp.validate(new PfValidationResult()).isValid());
+ assertFalse(tp.validate("").isValid());
tp.getConstraints().remove(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
tp.setMetadata(null);
- assertTrue(tp.validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate("").isValid());
- assertThatThrownBy(() -> tp.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tp.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
@Test
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java
index e7163f756..7248b45ec 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java
@@ -32,7 +32,6 @@ import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
/**
* DAO test for ToscaEntrySchema.
@@ -96,27 +95,27 @@ public class JpaToscaSchemaDefinitionTest {
tes.clean();
assertEquals(tdtClone0, tes);
- assertTrue(new JpaToscaSchemaDefinition(typeKey).validate(new PfValidationResult()).isValid());
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaSchemaDefinition(typeKey).validate("").isValid());
+ assertTrue(tes.validate("").isValid());
tes.setType(PfConceptKey.getNullKey());
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.setType(null);
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.setType(typeKey);
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate("").isValid());
tes.setDescription("");
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.setDescription(A_DESCRIPTION);
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate("").isValid());
tes.getConstraints().add(null);
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.getConstraints().remove(null);
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate("").isValid());
- assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
index bb0d2dcb5..d6266b49a 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
@@ -33,9 +33,10 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
+import org.onap.policy.common.parameters.BeanValidationResult;
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;
/**
* DAO test for ToscaDatatype.
@@ -126,31 +127,31 @@ public class JpaToscaServiceTemplateTest {
tst.clean();
assertEquals(tttClone0, tst);
- assertTrue(new JpaToscaServiceTemplate().validate(new PfValidationResult()).isValid());
- assertTrue(tst.validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaServiceTemplate().validate("").isValid());
+ assertTrue(tst.validate("").isValid());
tst.setDescription(null);
- assertTrue(tst.validate(new PfValidationResult()).isValid());
+ assertTrue(tst.validate("").isValid());
tst.setDescription("");
- assertFalse(tst.validate(new PfValidationResult()).isValid());
+ assertFalse(tst.validate("").isValid());
tst.setDescription("A Description");
- assertTrue(tst.validate(new PfValidationResult()).isValid());
+ assertTrue(tst.validate("").isValid());
- assertThatThrownBy(() -> tst.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tst.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
tst.setToscaDefinitionsVersion(null);
- PfValidationResult result = tst.validate(new PfValidationResult());
- assertThat(result.toString()).contains("service template tosca definitions version may not be null");
+ BeanValidationResult result = tst.validate("");
+ assertThat(result.getResult()).contains("toscaDefinitionsVersion").contains(Validated.IS_BLANK);
tst.setToscaDefinitionsVersion(JpaToscaServiceTemplate.DEFAULT_TOSCA_DEFINTIONS_VERISON);
tst.setDataTypes(null);
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1"));
tst.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0);
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0"));
@@ -158,81 +159,82 @@ public class JpaToscaServiceTemplateTest {
pt0.setProperties(new LinkedHashMap<>());
pt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains("referenced data type dt0:0.0.1 not found");
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("data type").contains("dt0:0.0.1").contains(Validated.NOT_FOUND);
tst.setDataTypes(null);
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains("referenced data type dt0:0.0.1 not found");
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("data type").contains("dt0:0.0.1").contains(Validated.NOT_FOUND);
tst.setDataTypes(new JpaToscaDataTypes());
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains("referenced data type dt0:0.0.1 not found");
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("data type").contains("dt0:0.0.1").contains(Validated.NOT_FOUND);
tst.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
tst.setTopologyTemplate(null);
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
tst.setTopologyTemplate(new JpaToscaTopologyTemplate());
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
tst.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
tst.setPolicyTypes(null);
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
JpaToscaPolicy pol0 = new JpaToscaPolicy(new PfConceptKey("pol0:0.0.1"));
tst.getTopologyTemplate().getPolicies().getConceptMap().put(pol0.getKey(), pol0);
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains("type is null or a null key");
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("type").contains(Validated.IS_A_NULL_KEY);
pol0.setType(new PfConceptKey("i.dont.Exist:0.0.1"));
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains(
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains(
"no policy types are defined on the service template for the policies in the topology template");
tst.setPolicyTypes(policyTypes);
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains("policy type i.dont.Exist:0.0.1 referenced in policy not found");
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("policy type").contains("i.dont.Exist:0.0.1")
+ .contains(Validated.NOT_FOUND);
pol0.setType(dt0.getKey());
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains("policy type dt0:0.0.1 referenced in policy not found");
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains("policy type").contains("dt0:0.0.1").contains(Validated.NOT_FOUND);
pol0.setType(pt0.getKey());
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
tst.setPolicyTypes(null);
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains(
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains(
"no policy types are defined on the service template for the policies in the topology template");
tst.setPolicyTypes(policyTypes);
pol0.setType(pt0.getKey());
- result = tst.validate(new PfValidationResult());
- assertTrue(result.isOk());
+ result = tst.validate("");
+ assertTrue(result.isValid());
tst.setPolicyTypes(new JpaToscaPolicyTypes());
- result = tst.validate(new PfValidationResult());
- assertFalse(result.isOk());
- assertThat(result.toString()).contains(
+ result = tst.validate("");
+ assertFalse(result.isValid());
+ assertThat(result.getResult()).contains(
"no policy types are defined on the service template for the policies in the topology template");
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
index ef9039af9..2d52f504b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
@@ -32,7 +32,6 @@ import java.util.Date;
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;
/**
* DAO test for ToscaTimeInterval.
@@ -109,23 +108,23 @@ public class JpaToscaTimeIntervalTest {
tti.clean();
assertEquals(tdtClone0, tti);
- assertFalse(new JpaToscaTimeInterval().validate(new PfValidationResult()).isValid());
- assertTrue(tti.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaTimeInterval().validate("").isValid());
+ assertTrue(tti.validate("").isValid());
tti.setStartTime(null);
- assertFalse(tti.validate(new PfValidationResult()).isValid());
+ assertFalse(tti.validate("").isValid());
tti.setStartTime(new Date(endTime.getTime() + 1));
- assertFalse(tti.validate(new PfValidationResult()).isValid());
+ assertFalse(tti.validate("").isValid());
tti.setStartTime(startTime);
- assertTrue(tti.validate(new PfValidationResult()).isValid());
+ assertTrue(tti.validate("").isValid());
tti.setEndTime(null);
- assertFalse(tti.validate(new PfValidationResult()).isValid());
+ assertFalse(tti.validate("").isValid());
tti.setEndTime(new Date(startTime.getTime() - 1));
- assertFalse(tti.validate(new PfValidationResult()).isValid());
+ assertFalse(tti.validate("").isValid());
tti.setEndTime(endTime);
- assertTrue(tti.validate(new PfValidationResult()).isValid());
+ assertTrue(tti.validate("").isValid());
- assertThatThrownBy(() -> tti.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tti.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
index d42dfb09d..714b6722c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
@@ -33,7 +33,6 @@ import java.util.TreeMap;
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.tosca.authorative.concepts.ToscaTopologyTemplate;
/**
@@ -108,21 +107,21 @@ public class JpaToscaTopologyTemplateTest {
ttt.clean();
assertEquals(tttClone0, ttt);
- assertTrue(new JpaToscaTopologyTemplate().validate(new PfValidationResult()).isValid());
- assertTrue(ttt.validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaTopologyTemplate().validate("").isValid());
+ assertTrue(ttt.validate("").isValid());
ttt.setKey(PfReferenceKey.getNullKey());
- assertFalse(ttt.validate(new PfValidationResult()).isValid());
+ assertFalse(ttt.validate("").isValid());
ttt.setKey(tttKey);
- assertTrue(ttt.validate(new PfValidationResult()).isValid());
+ assertTrue(ttt.validate("").isValid());
ttt.setDescription(null);
- assertTrue(ttt.validate(new PfValidationResult()).isValid());
+ assertTrue(ttt.validate("").isValid());
ttt.setDescription("");
- assertFalse(ttt.validate(new PfValidationResult()).isValid());
+ assertFalse(ttt.validate("").isValid());
ttt.setDescription(A_DESCRIPTION);
- assertTrue(ttt.validate(new PfValidationResult()).isValid());
+ assertTrue(ttt.validate("").isValid());
- assertThatThrownBy(() -> ttt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> ttt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
index 3b196c478..2eb6b10e0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
@@ -33,7 +33,6 @@ import java.util.Date;
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;
/**
* DAO test for ToscaTrigger.
@@ -153,28 +152,28 @@ public class JpaToscaTriggerTest {
tdt.clean();
assertEquals(tdtClone0, tdt);
- assertFalse(new JpaToscaTrigger().validate(new PfValidationResult()).isValid());
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(new JpaToscaTrigger().validate("").isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.setDescription(null);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.setDescription("");
- assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(tdt.validate("").isValid());
tdt.setDescription(A_DESCRIPTION);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.setEvaluations(-1);
- assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(tdt.validate("").isValid());
tdt.setEvaluations(100);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.setMethod(null);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
tdt.setMethod("");
- assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ assertFalse(tdt.validate("").isValid());
tdt.setMethod(A_METHOD);
- assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate("").isValid());
- assertThatThrownBy(() -> tdt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ assertThatThrownBy(() -> tdt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
index 3c363b364..a926ca149 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -38,6 +38,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfReferenceKey;
+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;
@@ -418,7 +419,8 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
- }).hasMessageContaining("policy type IDontExist:99.100.101 referenced in policy not found");
+ }).hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101")
+ .hasMessageContaining(Validated.NOT_FOUND);
toscaPolicy.setType("IDontExist");
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -523,8 +525,8 @@ public class SimpleToscaProviderTest {
serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt);
assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment))
- .hasMessageContaining(
- "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key");
+ .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0")
+ .hasMessageContaining(Validated.IS_A_NULL_KEY);
}
@Test
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
index 87a52242f..98ced3b41 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
@@ -36,7 +36,6 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -179,8 +178,8 @@ public class MonitoringPolicySerializationTest {
// Sanity check the entire structure
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+ LOGGER.info(serviceTemplate.validate("").toString());
+ assertTrue(serviceTemplate.validate("").isValid());
// Check tosca_definitions_version
assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion());
@@ -211,8 +210,8 @@ public class MonitoringPolicySerializationTest {
// Sanity check the entire structure
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+ LOGGER.info(serviceTemplate.validate("").toString());
+ assertTrue(serviceTemplate.validate("").isValid());
// Check tosca_definitions_version
assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion());
@@ -243,8 +242,8 @@ public class MonitoringPolicySerializationTest {
// Sanity check the entire structure
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+ LOGGER.info(serviceTemplate.validate("").toString());
+ assertTrue(serviceTemplate.validate("").isValid());
// Check tosca_definitions_version
assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
index 4a8378f21..7135da0bf 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
@@ -34,7 +34,6 @@ import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
@@ -140,8 +139,8 @@ public class MonitoringPolicyTypeSerializationTest {
// Sanity check the entire structure
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+ LOGGER.info(serviceTemplate.validate("").toString());
+ assertTrue(serviceTemplate.validate("").isValid());
// Check tosca_definitions_version
assertEquals("tosca_simple_yaml_1_1_0", serviceTemplate.getToscaDefinitionsVersion());
@@ -361,8 +360,8 @@ public class MonitoringPolicyTypeSerializationTest {
// Sanity check the entire structure
assertNotNull(serviceTemplate);
- LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
- assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+ LOGGER.info(serviceTemplate.validate("").toString());
+ assertTrue(serviceTemplate.validate("").isValid());
// Check tosca_definitions_version
assertEquals("tosca_simple_yaml_1_1_0", serviceTemplate.getToscaDefinitionsVersion());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
index c3fc8a310..ad29a7199 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.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.
@@ -26,6 +27,7 @@ import static org.junit.Assert.assertEquals;
import java.util.Iterator;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
@@ -132,13 +134,14 @@ public class ToscaServiceTemplateUtilsTest {
final JpaToscaServiceTemplate compositeTestTemplate = new JpaToscaServiceTemplate(compositeTemplate00);
assertThatThrownBy(() -> {
ToscaServiceTemplateUtils.addFragment(compositeTestTemplate, fragmentTemplate03);
- }).hasMessageContaining("entity in incoming fragment does not equal existing entity");
+ }).hasMessageContaining("incoming fragment").hasMessageContaining("entity").hasMessageContaining("dt0:0.0.1")
+ .hasMessageContaining("does not equal existing entity");
JpaToscaServiceTemplate fragmentTemplate04 = new JpaToscaServiceTemplate();
fragmentTemplate04.setDescription("Another service template");
assertThatThrownBy(() -> {
ToscaServiceTemplateUtils.addFragment(compositeTestTemplate, fragmentTemplate04);
- }).hasMessageContaining("service template in incoming fragment does not equal existing service template");
+ }).hasMessageContaining("service template").hasMessageContaining("does not equal existing service template");
JpaToscaServiceTemplate fragmentTemplate05 = new JpaToscaServiceTemplate();
fragmentTemplate05.setTopologyTemplate(new JpaToscaTopologyTemplate());
@@ -159,7 +162,8 @@ public class ToscaServiceTemplateUtilsTest {
fragmentTemplate07.getTopologyTemplate().setDescription("topology template other description");
assertThatThrownBy(() -> {
ToscaServiceTemplateUtils.addFragment(compositeTemplate04, fragmentTemplate07);
- }).hasMessageContaining("topology template in incoming fragment does not equal existing topology template");
+ }).hasMessageContaining("incoming fragment").hasMessageContaining("topology template")
+ .hasMessageContaining("does not equal existing topology template");
JpaToscaDataType dt1 = new JpaToscaDataType();
dt1.setKey(new PfConceptKey("dt1", "0.0.1"));
@@ -189,7 +193,7 @@ public class ToscaServiceTemplateUtilsTest {
assertThatThrownBy(() -> {
ToscaServiceTemplateUtils.addFragment(compositeTemplate04, fragmentTemplate08);
- }).hasMessageContaining("JpaToscaPolicy:INVALID:type is null or a null key");
+ }).hasMessageContaining("type").hasMessageContaining(Validated.IS_A_NULL_KEY);
p0.setType(pt0.getKey());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
index d75e37be2..0880fd97b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.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.
@@ -20,6 +21,7 @@
package org.onap.policy.models.tosca.utils;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
@@ -28,9 +30,10 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+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.PfValidationResult;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
@@ -149,7 +152,7 @@ public class ToscaUtilsTest {
}).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
- ToscaUtils.getEntityTypeAncestors(null, null, new PfValidationResult());
+ ToscaUtils.getEntityTypeAncestors(null, null, new BeanValidationResult("", null));
}).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
@@ -157,7 +160,7 @@ public class ToscaUtilsTest {
}).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
- ToscaUtils.getEntityTypeAncestors(null, new JpaToscaDataType(), new PfValidationResult());
+ ToscaUtils.getEntityTypeAncestors(null, new JpaToscaDataType(), new BeanValidationResult("", null));
}).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
@@ -165,7 +168,7 @@ public class ToscaUtilsTest {
}).hasMessageMatching("entityType is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
- ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), null, new PfValidationResult());
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), null, new BeanValidationResult("", null));
}).hasMessageMatching("entityType is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
@@ -176,7 +179,7 @@ public class ToscaUtilsTest {
JpaToscaDataType dt0 = new JpaToscaDataType();
dt0.setKey(new PfConceptKey("dt0", "0.0.1"));
dt0.setDescription("dt0 description");
- PfValidationResult result = new PfValidationResult();
+ BeanValidationResult result = new BeanValidationResult("", null);
assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
@@ -195,9 +198,10 @@ public class ToscaUtilsTest {
dt0.setDerivedFrom(new PfConceptKey("some.thing.Else", PfKey.NULL_KEY_VERSION));
assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
assertFalse(result.isValid());
- assertTrue(result.toString().contains("parent some.thing.Else:0.0.0 of entity not found"));
+ assertThat(result.getResult()).contains("parent").contains("some.thing.Else:0.0.0")
+ .contains(Validated.NOT_FOUND);
- result = new PfValidationResult();
+ result = new BeanValidationResult("", null);
dt0.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
JpaToscaDataType dt1 = new JpaToscaDataType();
@@ -233,8 +237,8 @@ public class ToscaUtilsTest {
dt0.setDerivedFrom(dt0.getKey());
assertThatThrownBy(() -> {
- ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, new PfValidationResult());
- }).hasMessageContaining("entity cannot be an ancestor of itself");
+ ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, new BeanValidationResult("", null));
+ }).hasMessageContaining("entity type").hasMessageContaining("ancestor of itself");
dt0.setDerivedFrom(null);
assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
@@ -250,7 +254,7 @@ public class ToscaUtilsTest {
dataTypes.getConceptMap().remove(dt1.getKey());
assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
assertFalse(result.isValid());
- assertTrue(result.toString().contains("parent dt1:0.0.1 of entity not found"));
+ assertThat(result.getResult()).contains("parent").contains("dt1:0.0.1").contains(Validated.NOT_FOUND);
}
@Test
@@ -369,6 +373,7 @@ public class ToscaUtilsTest {
assertThatThrownBy(() -> {
final JpaToscaDataTypes badDataTypes = new JpaToscaDataTypes(dataTypes);
ToscaUtils.getEntityTree(badDataTypes, dt9.getKey().getName(), dt9.getKey().getVersion());
- }).hasMessageContaining("parent i.dont.Exist:0.0.0 of entity not found");
+ }).hasMessageContaining("parent").hasMessageContaining("i.dont.Exist:0.0.0")
+ .hasMessageContaining(Validated.NOT_FOUND);
}
}