From 6345dce40405740dc09176c45dae03baeb939b8e Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 17 Dec 2020 12:07:14 -0500 Subject: Use ValidationResult for models v2.0 Policy models uses PfValidationXxx classes which are totally unrelated to ValidationResult in policy common. This precludes the use of various utility methods and annotations for doing validation. Modified policy models to use ValidationResult instead. This approach uses function calls, though a future approach could make use of annotations instead. Issue-ID: POLICY-2648 Change-Id: I9760f1dc46902ab6bef7f440f3caf5e951660a5d Signed-off-by: Jim Hahn --- .../concepts/JpaToscaCapabilityAssignment.java | 82 ++------------- .../concepts/JpaToscaCapabilityAssignments.java | 7 +- .../simple/concepts/JpaToscaCapabilityType.java | 39 ++------ .../simple/concepts/JpaToscaCapabilityTypes.java | 7 +- .../tosca/simple/concepts/JpaToscaDataType.java | 52 ++-------- .../tosca/simple/concepts/JpaToscaDataTypes.java | 7 +- .../tosca/simple/concepts/JpaToscaEntityType.java | 43 ++------ .../tosca/simple/concepts/JpaToscaEventFilter.java | 35 ++----- .../tosca/simple/concepts/JpaToscaModel.java | 12 ++- .../simple/concepts/JpaToscaNodeTemplate.java | 48 ++------- .../simple/concepts/JpaToscaNodeTemplates.java | 8 +- .../tosca/simple/concepts/JpaToscaNodeType.java | 44 ++------- .../tosca/simple/concepts/JpaToscaNodeTypes.java | 8 +- .../tosca/simple/concepts/JpaToscaParameter.java | 22 ++--- .../tosca/simple/concepts/JpaToscaPolicies.java | 7 +- .../tosca/simple/concepts/JpaToscaPolicy.java | 71 ++----------- .../tosca/simple/concepts/JpaToscaPolicyType.java | 90 ++--------------- .../tosca/simple/concepts/JpaToscaPolicyTypes.java | 7 +- .../tosca/simple/concepts/JpaToscaProperty.java | 59 +++-------- .../simple/concepts/JpaToscaRelationshipType.java | 39 ++------ .../simple/concepts/JpaToscaRelationshipTypes.java | 8 +- .../tosca/simple/concepts/JpaToscaRequirement.java | 77 +++------------ .../simple/concepts/JpaToscaRequirements.java | 8 +- .../simple/concepts/JpaToscaSchemaDefinition.java | 44 ++------- .../simple/concepts/JpaToscaServiceTemplate.java | 93 ++++++----------- .../simple/concepts/JpaToscaTimeInterval.java | 27 ++--- .../simple/concepts/JpaToscaTopologyTemplate.java | 58 ++--------- .../tosca/simple/concepts/JpaToscaTrigger.java | 61 +++--------- .../tosca/simple/provider/SimpleToscaProvider.java | 11 ++- .../tosca/utils/ToscaServiceTemplateUtils.java | 37 ++++--- .../onap/policy/models/tosca/utils/ToscaUtils.java | 24 ++--- .../provider/ToscaServiceTemplateMappingTest.java | 7 +- .../concepts/JpaToscaCapabilityAssignmentTest.java | 17 ++-- .../simple/concepts/JpaToscaDataTypeTest.java | 25 +++-- .../simple/concepts/JpaToscaDataTypesTest.java | 30 +++--- .../simple/concepts/JpaToscaEventFilterTest.java | 25 +++-- .../tosca/simple/concepts/JpaToscaModelTest.java | 7 +- .../simple/concepts/JpaToscaPoliciesTest.java | 30 +++--- .../tosca/simple/concepts/JpaToscaPolicyTest.java | 29 +++--- .../simple/concepts/JpaToscaPolicyTypeTest.java | 45 +++++---- .../simple/concepts/JpaToscaPolicyTypesTest.java | 30 +++--- .../simple/concepts/JpaToscaPropertyTest.java | 33 +++---- .../concepts/JpaToscaSchemaDefinitionTest.java | 21 ++-- .../concepts/JpaToscaServiceTemplateTest.java | 110 +++++++++++---------- .../simple/concepts/JpaToscaTimeIntervalTest.java | 19 ++-- .../concepts/JpaToscaTopologyTemplateTest.java | 17 ++-- .../tosca/simple/concepts/JpaToscaTriggerTest.java | 23 +++-- .../simple/provider/SimpleToscaProviderTest.java | 10 +- .../MonitoringPolicySerializationTest.java | 13 ++- .../MonitoringPolicyTypeSerializationTest.java | 9 +- .../tosca/utils/ToscaServiceTemplateUtilsTest.java | 12 ++- .../policy/models/tosca/utils/ToscaUtilsTest.java | 27 ++--- 52 files changed, 535 insertions(+), 1139 deletions(-) (limited to 'models-tosca/src') 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 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 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 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 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 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 } @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 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 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 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 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 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 private String relationship; @ElementCollection - private List occurrences; + private List occurrences; @ElementCollection @Lob @@ -133,11 +132,11 @@ public class JpaToscaRequirement extends JpaToscaEntityType if (occurrences != null) { List 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 if (occurrence.equals(AUTHORATIVE_UNBOUNDED_LITERAL)) { occurrences.add(JPA_UNBOUNDED_VALUE); } else { - occurrences.add((Double) occurrence); + occurrences.add(((Number) occurrence).intValue()); } } } @@ -185,11 +184,6 @@ public class JpaToscaRequirement extends JpaToscaEntityType } - @Override - public List getKeys() { - return super.getKeys(); - } - @Override public void clean() { super.clean(); @@ -202,58 +196,11 @@ public class JpaToscaRequirement extends JpaToscaEntityType } @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, Serializable, Comparable { 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 dataTypeKeyCollection, final PfValidationResult result) { + private void validateReferencedDataTypesExists( + final Collection 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> 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 , ? 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> fragmentEntry : fragmentContainer .getConceptMap().entrySet()) { JpaToscaEntityType 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> getEntityTypeAncestors( @NonNull PfConceptContainer 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> 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 entityTypes, final String entityName, final String entityVersion) { - PfValidationResult result = new PfValidationResult(); + BeanValidationResult result = new BeanValidationResult("entity", entityName); @SuppressWarnings("unchecked") Set> 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((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); } } -- cgit 1.2.3-korg