From: danielhanrahan Date: Tue, 27 Jan 2026 19:54:48 +0000 (+0000) Subject: Remove Validated class X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=f0c5cb0492cce96139c3a9b4dd2191743aa5e697;p=policy%2Fclamp.git Remove Validated class This removes the Validated class from policy-models, using BeanValidator.validate(object) instead object.validate(). It also removes some unused code from validation classes. Issue-ID: POLICY-5509 Change-Id: Id801e24bc56cfe1b7cbaec3186b43ebbfdb547e1 Signed-off-by: danielhanrahan --- diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java index c13ca9497..b1ff46b05 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023,2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2022-2026 OpenInfra Foundation Europe. 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,13 +32,13 @@ import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplat import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.models.base.Validated; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ToscaServiceTemplateValidation { private static final String ROOT_KEY_NAME_SUFFIX = ".Root"; private static final String TOPOLOGY_TEMPLATE = "TopologyTemplate"; + private static final String NOT_FOUND = "not found"; /** * validate a serviceTemplate. @@ -153,7 +153,7 @@ public final class ToscaServiceTemplateValidation { final Collection dataTypeKeyCollection, Map> references) { for (DocConceptKey dataTypeKey : dataTypeKeyCollection) { if (!isTypePresent(dataTypeKey, references.get(DocUtil.REF_DATA_TYPES))) { - result.addResult("data type", dataTypeKey.getId(), ValidationStatus.INVALID, Validated.NOT_FOUND); + result.addResult("data type", dataTypeKey.getId(), ValidationStatus.INVALID, NOT_FOUND); } } } @@ -173,7 +173,7 @@ public final class ToscaServiceTemplateValidation { for (var policy : serviceTemplate.getToscaTopologyTemplate().getPolicies().values()) { var key = policy.getTypeDocConceptKey(); if (!isTypePresent(key, references.get(DocUtil.REF_POLICY_TYPES))) { - result.addResult("policy type", key, ValidationStatus.INVALID, Validated.NOT_FOUND); + result.addResult("policy type", key, ValidationStatus.INVALID, NOT_FOUND); } } } @@ -181,7 +181,7 @@ public final class ToscaServiceTemplateValidation { for (var nodeTemplate : serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().values()) { var key = nodeTemplate.getTypeDocConceptKey(); if (!isTypePresent(key, references.get(DocUtil.REF_NODE_TYPES))) { - result.addResult("node Template", key, ValidationStatus.INVALID, Validated.NOT_FOUND); + result.addResult("node Template", key, ValidationStatus.INVALID, NOT_FOUND); } } } @@ -233,7 +233,7 @@ public final class ToscaServiceTemplateValidation { continue; } if (!isTypePresent(parentEntityTypeKey, reference)) { - result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND); + result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, NOT_FOUND); } } } @@ -255,7 +255,7 @@ public final class ToscaServiceTemplateValidation { continue; } if (!isTypePresent(parentEntityTypeKey, reference)) { - result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND); + result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, NOT_FOUND); } } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java index 3d6d479e0..e38f01155 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java @@ -38,14 +38,13 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfNameVersion; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey; @Data -@EqualsAndHashCode(callSuper = true) +@EqualsAndHashCode @NoArgsConstructor -public class DocToscaEntity extends Validated +public class DocToscaEntity implements PfNameVersion, PfAuthorative, Serializable, Comparable> { @Serial diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplate.java index 0bb586a0f..bed773d02 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplate.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplate.java @@ -33,13 +33,12 @@ import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.clamp.models.acm.document.base.DocUtil; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; @Data @NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class DocToscaTopologyTemplate extends Validated +@EqualsAndHashCode +public class DocToscaTopologyTemplate implements PfAuthorative, Serializable, Comparable { @Serial diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java index 5006b5a8b..fa6be7e30 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java @@ -52,7 +52,6 @@ import org.onap.policy.clamp.models.acm.concepts.SubState; import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.Validated; /** * Class to represent an automation composition in the database. @@ -63,9 +62,9 @@ import org.onap.policy.models.base.Validated; @Table(name = "AutomationComposition", indexes = {@Index(name = "ac_compositionId", columnList = "compositionId")}) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) +@EqualsAndHashCode @NoArgsConstructor -public class JpaAutomationComposition extends Validated +public class JpaAutomationComposition implements PfAuthorative, Comparable { @Id diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java index 95a96c2d2..c21c498db 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java @@ -48,7 +48,6 @@ import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplat import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.Validated; /** * Class to represent an automation composition definition in the database. @@ -57,9 +56,8 @@ import org.onap.policy.models.base.Validated; @Table(name = "AutomationCompositionDefinition") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaAutomationCompositionDefinition extends Validated - implements PfAuthorative { +@EqualsAndHashCode +public class JpaAutomationCompositionDefinition implements PfAuthorative { @Id @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java index e33b0abff..58668b0e0 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -47,7 +47,6 @@ import org.onap.policy.clamp.models.acm.concepts.SubState; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.Validated; import org.onap.policy.models.base.validation.annotations.VerifyKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -60,8 +59,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @Table(name = "AutomationCompositionElement") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaAutomationCompositionElement extends Validated +@EqualsAndHashCode +public class JpaAutomationCompositionElement implements PfAuthorative, Comparable { @Id diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollback.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollback.java index 64b3ccde3..229501c9f 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollback.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollback.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2025-2026 OpenInfra Foundation Europe. 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. @@ -42,14 +42,13 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionRollback; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.Validated; @Entity @Table(name = "AutomationCompositionRollback") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaAutomationCompositionRollback extends Validated +@EqualsAndHashCode +public class JpaAutomationCompositionRollback implements PfAuthorative, Comparable { @Id diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessage.java index 2696983d2..86a7c889b 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessage.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessage.java @@ -36,13 +36,12 @@ import lombok.NonNull; import org.onap.policy.clamp.models.acm.document.concepts.DocMessage; import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.Validated; @Entity @Table(name = "Message", indexes = {@Index(name = "m_identificationId", columnList = "identificationId")}) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -public class JpaMessage extends Validated implements PfAuthorative { +public class JpaMessage implements PfAuthorative { @Id @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJob.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJob.java index 8acf0b8ff..a062a36e9 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJob.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJob.java @@ -33,14 +33,13 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.onap.policy.clamp.models.acm.utils.TimestampHelper; -import org.onap.policy.models.base.Validated; @Entity @Table(name = "MessageJob") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaMessageJob extends Validated { +@EqualsAndHashCode +public class JpaMessageJob { @Id @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java index b92b239e7..01b7876a3 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java @@ -40,7 +40,6 @@ import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.Validated; import org.onap.policy.models.base.validation.annotations.VerifyKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -48,8 +47,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @Table(name = "NodeTemplateState") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaNodeTemplateState extends Validated implements PfAuthorative { +@EqualsAndHashCode +public class JpaNodeTemplateState implements PfAuthorative { @Id @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java index 9d67fbbe4..87afa179a 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java @@ -33,8 +33,6 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; -import java.io.Serial; -import java.io.Serializable; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -45,7 +43,6 @@ import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.Validated; /** * Class to represent a participant in the database. @@ -56,12 +53,8 @@ import org.onap.policy.models.base.Validated; @Table(name = "Participant") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaParticipant extends Validated - implements PfAuthorative, Comparable, Serializable { - - @Serial - private static final long serialVersionUID = -4697758484642403483L; +@EqualsAndHashCode +public class JpaParticipant implements PfAuthorative, Comparable { @Id @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java index 021842234..e20379937 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplica.java @@ -36,14 +36,13 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.Validated; @Entity @Table(name = "ParticipantReplica") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaParticipantReplica extends Validated implements PfAuthorative { +@EqualsAndHashCode +public class JpaParticipantReplica implements PfAuthorative { @Id @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java index 6ac71aba2..75dc9bc4a 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java @@ -34,14 +34,13 @@ import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.Validated; @Entity @Table(name = "ParticipantSupportedAcElements") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data -@EqualsAndHashCode(callSuper = false) -public class JpaParticipantSupportedElementType extends Validated +@EqualsAndHashCode +public class JpaParticipantSupportedElementType implements PfAuthorative, Comparable { @NotNull diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java index 6feb2b719..d7c60616f 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2026 OpenInfra Foundation Europe. 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,9 +27,9 @@ import java.util.function.Supplier; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.base.Validated; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ProviderUtils { @@ -42,7 +42,7 @@ public final class ProviderUtils { * @param conceptDescription the description used for validation result * @return the list of Jpa objects */ - public static > List getJpaAndValidateList( + public static > List getJpaAndValidateList( List authorativeConceptList, Supplier jpaSupplier, String conceptDescription) { var validationResult = new BeanValidationResult(conceptDescription + " List", authorativeConceptList); @@ -53,7 +53,7 @@ public final class ProviderUtils { jpaConcept.fromAuthorative(authorativeConcept); jpaConceptList.add(jpaConcept); - validationResult.addResult(jpaConcept.validate(conceptDescription)); + validationResult.addResult(BeanValidator.validate(conceptDescription, jpaConcept)); } if (!validationResult.isValid()) { @@ -70,7 +70,7 @@ public final class ProviderUtils { * @param conceptDescription the description used for validation result * @return the Jpa object */ - public static > J getJpaAndValidate(A authorativeConcept, + public static > J getJpaAndValidate(A authorativeConcept, Supplier jpaSupplier, String conceptDescription) { var jpaConcept = jpaSupplier.get(); jpaConcept.fromAuthorative(authorativeConcept); @@ -85,11 +85,11 @@ public final class ProviderUtils { * @param jpaConcept the Jpa of the concept * @param conceptDescription the description used for validation result */ - public static > void validate(A authorativeConcept, + public static > void validate(A authorativeConcept, J jpaConcept, String conceptDescription) { var validationResult = new BeanValidationResult(conceptDescription, authorativeConcept); - validationResult.addResult(jpaConcept.validate(conceptDescription)); + validationResult.addResult(BeanValidator.validate(conceptDescription, jpaConcept)); if (!validationResult.isValid()) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplateTest.java index c234e0a9e..6abd5355c 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplateTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplateTest.java @@ -95,7 +95,6 @@ class DocToscaServiceTemplateTest { doc2.setPolicyTypes(doc.getPolicyTypes()); assertThat(doc).isEqualByComparingTo(doc2); assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); - assertThat(doc.validate("serviceTemplate")).isNotNull(); serviceTemplate.setName(NAME); serviceTemplate.setVersion("1.1.1"); @@ -232,9 +231,6 @@ class DocToscaServiceTemplateTest { @Test void testNullPointer() { - var docCapabilityType = new DocToscaCapabilityType(); - assertThatThrownBy(() -> docCapabilityType.validate(null)). isInstanceOf(NullPointerException.class); - var docConceptKey = new DocConceptKey(); assertThatThrownBy(() -> docConceptKey.setName(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> docConceptKey.setVersion(null)). isInstanceOf(NullPointerException.class); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java index d25dd45e0..a9b69f8a8 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2021-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.MigrationState; import org.onap.policy.clamp.models.acm.concepts.SubState; import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -110,11 +111,7 @@ class JpaAutomationCompositionElementTest { @Test void testJpaAutomationCompositionElementValidation() { var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance(); - - assertThatThrownBy(() -> testJpaAutomationCompositionElement.validate(null)) - .hasMessageMatching("fieldName" + NULL_ERROR); - - assertTrue(testJpaAutomationCompositionElement.validate("").isValid()); + assertTrue(BeanValidator.isValid(testJpaAutomationCompositionElement)); } @Test diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java index e31049445..8a386c85d 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2021-2026 OpenInfra Foundation Europe. 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.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.concepts.SubState; import org.onap.policy.clamp.models.acm.utils.TimestampHelper; +import org.onap.policy.common.parameters.BeanValidator; /** * Test the{@link JpaAutomationCompositionTest} class. @@ -93,11 +94,7 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationCompositionValidation() { var testJpaAutomationComposition = new JpaAutomationComposition(createAutomationCompositionInstance()); - - assertThatThrownBy(() -> testJpaAutomationComposition.validate(null)) - .hasMessageMatching("fieldName is marked non-null but is null"); - - assertTrue(testJpaAutomationComposition.validate("").isValid()); + assertTrue(BeanValidator.isValid(testJpaAutomationComposition)); } @Test diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java index c8bc561fe..e17407549 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2025 Nordix Foundation. + * Copyright (C) 2025-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; - +import org.onap.policy.common.parameters.BeanValidator; class JpaMessageJobTest { @@ -39,12 +39,9 @@ class JpaMessageJobTest { void testJpaMessageValidation() { var jpaMessageJob = new JpaMessageJob(); - assertThatThrownBy(() -> jpaMessageJob.validate(null)) - .hasMessageMatching("fieldName is marked non-null but is null"); - - assertTrue(jpaMessageJob.validate("").isValid()); + assertTrue(BeanValidator.isValid(jpaMessageJob)); jpaMessageJob.setJobStarted(null); - assertFalse(jpaMessageJob.validate("").isValid()); + assertFalse(BeanValidator.isValid(jpaMessageJob)); } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java index 0e091ec36..dfc76bccd 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2025 Nordix Foundation. + * Copyright (C) 2025-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.document.concepts.DocMessage; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType; +import org.onap.policy.common.parameters.BeanValidator; class JpaMessageTest { @@ -46,13 +47,10 @@ class JpaMessageTest { var docMessage = createDocMessage(); var jpaMessage = new JpaMessage(docMessage.getInstanceId().toString(), docMessage); - assertThatThrownBy(() -> jpaMessage.validate(null)) - .hasMessageMatching("fieldName is marked non-null but is null"); - - assertTrue(jpaMessage.validate("").isValid()); + assertTrue(BeanValidator.isValid(jpaMessage)); jpaMessage.setLastMsg(null); - assertFalse(jpaMessage.validate("").isValid()); + assertFalse(BeanValidator.isValid(jpaMessage)); } @Test diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java index 4c2ac0ebf..7ef721e90 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2021-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import java.util.LinkedHashMap; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.common.parameters.BeanValidator; /** * Test the {@link JpaParticipant} class. @@ -86,11 +87,7 @@ class JpaParticipantTest { @Test void testJpaParticipantValidation() { var testJpaParticipant = new JpaParticipant(createParticipantInstance()); - - assertThatThrownBy(() -> testJpaParticipant.validate(null)) - .hasMessageMatching("fieldName is marked non-null but is null"); - - assertTrue(testJpaParticipant.validate("").isValid()); + assertTrue(BeanValidator.isValid(testJpaParticipant)); } @Test diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java b/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java index e16205308..cc27fd14e 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidationResult.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +22,7 @@ package org.onap.policy.common.parameters; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.function.BiConsumer; -import java.util.function.Function; /** * This class holds the result of the validation of an arbitrary bean. @@ -80,109 +76,16 @@ public class BeanValidationResult extends ValidationResultImpl { return addResult(new ObjectValidationResult(name, object, status, message)); } - /** - * Validates that a sub-object within the bean is not {@code null}. - * - * @param subName name of the sub-object - * @param subObject the sub-object - * @return {@code true} if the value is not null, {@code false} otherwise - */ - public boolean validateNotNull(String subName, Object subObject) { - var result = new ObjectValidationResult(subName, subObject); - - if (result.validateNotNull()) { - return true; - - } else { - addResult(result); - return false; - } - } - - /** - * Validates the items in a list, after validating that the list, itself, is not null. - * - * @param listName name of the list - * @param list list whose items are to be validated, or {@code null} - * @param itemValidator function to validate an item in the list - * @return {@code true} if all items in the list are valid, {@code false} otherwise - */ - public boolean validateNotNullList(String listName, Collection list, - Function itemValidator) { - - return validateNotNull(listName, list) && validateList(listName, list, itemValidator); - } - - /** - * Validates the items in a list. - * - * @param listName name of the list - * @param list list whose items are to be validated, or {@code null} - * @param itemValidator function to validate an item in the list - * @return {@code true} if all items in the list are valid, {@code false} otherwise - */ - public boolean validateList(String listName, Collection list, Function itemValidator) { - if (list == null) { - return true; - } - - var result = new BeanValidationResult(listName, null); - for (T item : list) { - if (item == null) { - result.addResult("item", item, ValidationStatus.INVALID, "null"); - } else { - result.addResult(itemValidator.apply(item)); - } - } - - if (result.isValid()) { - return true; - - } else { - addResult(result); - return false; - } - } - - /** - * Validates the entries in a map. - * - * @param mapName name of the list - * @param map map whose entries are to be validated, or {@code null} - * @param entryValidator function to validate an entry in the map - * @return {@code true} if all entries in the map are valid, {@code false} otherwise - */ - public boolean validateMap(String mapName, Map map, - BiConsumer> entryValidator) { - if (map == null) { - return true; - } - - var result = new BeanValidationResult(mapName, null); - for (Entry ent : map.entrySet()) { - entryValidator.accept(result, ent); - } - - if (result.isValid()) { - return true; - - } else { - addResult(result); - return false; - } - } - /** * Gets the validation result. * * @param initialIndentation the indentation to use on the main result output * @param subIndentation the indentation to use on sub parts of the result output - * @param showClean output information on clean fields * @return the result */ @Override - public String getResult(final String initialIndentation, final String subIndentation, final boolean showClean) { - if (!showClean && getStatus() == ValidationStatus.CLEAN) { + public String getResult(final String initialIndentation, final String subIndentation) { + if (getStatus() == ValidationStatus.CLEAN) { return null; } @@ -199,7 +102,7 @@ public class BeanValidationResult extends ValidationResultImpl { builder.append('\n'); for (ValidationResult itemResult : itemResults) { - String message = itemResult.getResult(initialIndentation + subIndentation, subIndentation, showClean); + String message = itemResult.getResult(initialIndentation + subIndentation, subIndentation); if (message != null) { builder.append(message); } diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidator.java b/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidator.java index c3ed5f5e8..95acfd295 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidator.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/BeanValidator.java @@ -52,4 +52,26 @@ public class BeanValidator { } return result; } + + /** + * Validates the given bean. + * + * @param the type of the bean + * @param bean the bean to validate + * @return the validation result + */ + public static BeanValidationResult validate(final T bean) { + return validate(bean.getClass().getSimpleName(), bean); + } + + /** + * Validates the given bean. + * + * @param the type of the bean + * @param bean the bean to validate + * @return true if the bean is valid + */ + public static boolean isValid(final T bean) { + return validate(bean).isValid(); + } } diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ObjectValidationResult.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ObjectValidationResult.java index af1884a3a..50a42b9c4 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/ObjectValidationResult.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/ObjectValidationResult.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2026 OpenInfra Foundation Europe. 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. @@ -52,12 +53,11 @@ public class ObjectValidationResult extends ValidationResultImpl { * * @param initialIndentation the result indentation * @param subIndentation the indentation to use on sub parts of the result output - * @param showClean output information on clean fields * @return the result */ @Override - public String getResult(final String initialIndentation, final String subIndentation, final boolean showClean) { - if (!showClean && getStatus() == ValidationStatus.CLEAN) { + public String getResult(final String initialIndentation, final String subIndentation) { + if (getStatus() == ValidationStatus.CLEAN) { return null; } diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterConstants.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterConstants.java deleted file mode 100644 index ea31ea347..000000000 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterConstants.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.common.parameters; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * This static class holds the values of constants for parameter handling. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ParameterConstants { - // Indentation is 0 on the left and 2 for each level of hierarchy - public static final String DEFAULT_INITIAL_RESULT_INDENTATION = ""; - public static final String DEFAULT_RESULT_INDENTATION = " "; - - // By default we do not show validation results for parameters that are validated as clean - public static final boolean DO_NOT_SHOW_CLEAN_RESULTS = false; -} diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java index 3faf5fea2..7fc0e5cf8 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java @@ -43,6 +43,6 @@ public class ParameterGroupImpl implements ParameterGroup { @Override public BeanValidationResult validate() { - return BeanValidator.validate(getClass().getSimpleName(), this); + return BeanValidator.validate(this); } } diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResult.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResult.java index e60174101..d0bb6924c 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResult.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResult.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation. + * Modifications Copyright (C) 2024-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,10 @@ package org.onap.policy.common.parameters; * This interface defines the result of a parameter validation. */ public interface ValidationResult { + // Indentation is 0 on the left and 2 for each level of hierarchy + String DEFAULT_INITIAL_RESULT_INDENTATION = ""; + String DEFAULT_RESULT_INDENTATION = " "; + /** * Gets the name of the entity being validated. * @@ -63,10 +67,7 @@ public interface ValidationResult { * @return the full validation result */ default String getResult() { - return getResult( - ParameterConstants.DEFAULT_INITIAL_RESULT_INDENTATION, - ParameterConstants.DEFAULT_RESULT_INDENTATION, - ParameterConstants.DO_NOT_SHOW_CLEAN_RESULTS); + return getResult(DEFAULT_INITIAL_RESULT_INDENTATION, DEFAULT_RESULT_INDENTATION); } /** @@ -74,10 +75,9 @@ public interface ValidationResult { * * @param initialIndentation the indentation to use on the main result output * @param subIndentation the indentation to use on sub parts of the result output - * @param showClean output information on clean fields * @return the result */ - String getResult(final String initialIndentation, final String subIndentation, final boolean showClean); + String getResult(final String initialIndentation, final String subIndentation); /** * Set a validation result. @@ -86,4 +86,4 @@ public interface ValidationResult { * @param message The validation message explaining the validation status */ void setResult(final ValidationStatus status, final String message); -} \ No newline at end of file +} diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResultImpl.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResultImpl.java index 458988185..b223dfccb 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResultImpl.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationResultImpl.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2026 OpenInfra Foundation Europe. 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. @@ -50,7 +51,7 @@ public abstract class ValidationResultImpl implements ValidationResult { /** * Validation message. */ - private String message = ITEM_HAS_STATUS_MESSAGE + status.toString(); + private String message = ITEM_HAS_STATUS_MESSAGE + status; /** @@ -64,21 +65,6 @@ public abstract class ValidationResultImpl implements ValidationResult { this.object = object; } - /** - * Validates that the value is not {@code null}. - * - * @return {@code true} if the value is not null, {@code false} otherwise - */ - public boolean validateNotNull() { - if (object == null) { - setResult(ValidationStatus.INVALID, "is null"); - return false; - - } else { - return true; - } - } - /** * Set the validation result status. On a sequence of calls, the most serious * validation status is recorded, assuming the status enum ordinals increase in order diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationStatus.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationStatus.java index 8692506f0..a34de41d2 100644 --- a/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationStatus.java +++ b/policy-common/src/main/java/org/onap/policy/common/parameters/ValidationStatus.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2026 OpenInfra Foundation Europe. 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. @@ -22,10 +23,8 @@ package org.onap.policy.common.parameters; public enum ValidationStatus { CLEAN, - OBSERVATION, - WARNING, INVALID; - + /** * The result of a validation is valid unless the status is INVALID. * @return true if the validation has passed @@ -33,7 +32,7 @@ public enum ValidationStatus { public boolean isValid() { return !this.equals(INVALID); } - + /** * Check if the validation was clean. * @return true if the validation is clean diff --git a/policy-common/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java b/policy-common/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java index ab733aed7..19b3c1a94 100644 --- a/policy-common/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java +++ b/policy-common/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2026 OpenInfra Foundation Europe. 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,12 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; -import java.util.function.BiConsumer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,17 +34,13 @@ class TestBeanValidationResult { private static final String TEXT1 = "abc"; private static final String TEXT2 = "def"; private static final String MY_LIST = "my-list"; - private static final String MY_MAP = "my-map"; private static final String OBJECT = "an object"; private static final String INITIAL_INDENT = "xx "; private static final String NEXT_INDENT = "yy "; private static final String MID_INDENT = "xx yy "; private static final String NAME = "my-name"; - private static final String MY_LIST_INVALID = " 'my-list' INVALID, item has status INVALID\n "; - private static final String MY_MAP_INVALID = " 'my-map' INVALID, item has status INVALID\n "; - private static final String BEAN_INVALID_MSG = requote("'my-name' INVALID, item has status INVALID\n"); + private static final String BEAN_INVALID_MSG = "\"my-name\" INVALID, item has status INVALID\n"; - private String cleanMsg; private String invalidMsg; private BeanValidationResult bean; @@ -63,7 +53,6 @@ class TestBeanValidationResult { @BeforeEach void setUp() { clean = new ObjectValidationResult(TEXT1, 10); - cleanMsg = clean.getResult("", "", true); invalid = new ObjectValidationResult(TEXT2, 20); invalid.setResult(ValidationStatus.INVALID, "invalid"); @@ -91,124 +80,11 @@ class TestBeanValidationResult { assertFalse(bean.isValid()); assertEquals(BEAN_INVALID_MSG + " " + invalidMsg, bean.getResult()); - assertEquals(INITIAL_INDENT + BEAN_INVALID_MSG + MID_INDENT + cleanMsg + MID_INDENT + invalidMsg, - bean.getResult(INITIAL_INDENT, NEXT_INDENT, true)); + assertEquals(INITIAL_INDENT + BEAN_INVALID_MSG + MID_INDENT + invalidMsg, + bean.getResult(INITIAL_INDENT, NEXT_INDENT)); bean = new BeanValidationResult(NAME, OBJECT); assertFalse(bean.addResult(MY_LIST, "hello", ValidationStatus.INVALID, TEXT1)); assertThat(bean.getResult()).contains("\"" + MY_LIST + "\" value \"hello\" INVALID, " + TEXT1); } - - @Test - void testValidateNotNull() { - assertTrue(bean.validateNotNull("sub-name", "sub-object")); - assertTrue(bean.isValid()); - assertNull(bean.getResult()); - - assertFalse(bean.validateNotNull("sub-name", null)); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + " item 'sub-name' value 'null' INVALID, is null\n"), bean.getResult()); - } - - @Test - void testValidateNotNullList() { - List list = List.of(clean); - assertTrue(bean.validateNotNullList(MY_LIST, list, item -> item)); - assertTrue(bean.isValid()); - assertNull(bean.getResult()); - - list = Arrays.asList(invalid, invalid); - assertFalse(bean.validateNotNullList(MY_LIST, list, item -> item)); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + MY_LIST_INVALID + invalidMsg - + " " + invalidMsg), bean.getResult()); - } - - @Test - void testValidateNotNullList_NullList() { - List list = null; - assertFalse(bean.validateNotNullList(MY_LIST, list, item -> item)); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + " item 'my-list' value 'null' INVALID, is null\n"), bean.getResult()); - - } - - @Test - void testValidateList() { - List list = null; - bean = new BeanValidationResult(NAME, OBJECT); - assertTrue(bean.validateList(MY_LIST, list, item -> item)); - assertTrue(bean.isValid()); - assertNull(bean.getResult()); - - list = List.of(clean); - bean = new BeanValidationResult(NAME, OBJECT); - assertTrue(bean.validateList(MY_LIST, list, item -> item)); - assertTrue(bean.isValid()); - assertNull(bean.getResult()); - - // null item in the list - list = Arrays.asList(clean, null); - bean = new BeanValidationResult(NAME, OBJECT); - assertFalse(bean.validateList(MY_LIST, list, item -> item)); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + MY_LIST_INVALID - + "item 'item' value 'null' INVALID, null\n"), bean.getResult()); - - list = Arrays.asList(invalid, invalid); - bean = new BeanValidationResult(NAME, OBJECT); - assertFalse(bean.validateList(MY_LIST, list, item -> item)); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + MY_LIST_INVALID + invalidMsg - + " " + invalidMsg), bean.getResult()); - - } - - @Test - void testValidateMap() { - Map map = null; - bean = new BeanValidationResult(NAME, OBJECT); - assertTrue(bean.validateMap(MY_MAP, map, validMapEntry())); - assertTrue(bean.isValid()); - assertNull(bean.getResult()); - - map = Map.of(TEXT1, clean, TEXT2, clean); - bean = new BeanValidationResult(NAME, OBJECT); - assertTrue(bean.validateMap(MY_MAP, map, validMapEntry())); - assertTrue(bean.isValid()); - assertNull(bean.getResult()); - - // null value in the map - map = new TreeMap<>(); - map.put(TEXT1, clean); - map.put(TEXT2, null); - bean = new BeanValidationResult(NAME, OBJECT); - assertFalse(bean.validateMap(MY_MAP, map, validMapEntry())); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + MY_MAP_INVALID - + "item 'def' value 'null' INVALID, is null\n"), bean.getResult()); - - map = Map.of(TEXT1, invalid, TEXT2, invalid); - bean = new BeanValidationResult(NAME, OBJECT); - assertFalse(bean.validateMap(MY_MAP, map, validMapEntry())); - assertFalse(bean.isValid()); - assertEquals(requote(BEAN_INVALID_MSG + MY_MAP_INVALID + invalidMsg - + " " + invalidMsg), bean.getResult()); - - } - - private BiConsumer> validMapEntry() { - return (result, entry) -> { - var value = entry.getValue(); - if (value == null) { - result.validateNotNull(entry.getKey(), value); - } else { - result.addResult(value); - } - }; - } - - private static String requote(String text) { - return text.replace('\'', '"'); - } } diff --git a/policy-common/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java b/policy-common/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java index c72d4f4a0..fee1b737f 100644 --- a/policy-common/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java +++ b/policy-common/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2026 OpenInfra Foundation Europe. 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 +24,6 @@ package org.onap.policy.common.parameters; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; @@ -48,27 +47,11 @@ class TestObjectValidationResult { result = new ObjectValidationResult(NAME, OBJECT); assertEquals(ValidationStatus.CLEAN, result.getStatus()); assertNull(result.getResult()); - assertEquals(requote("xxx item 'my-name' value 'my-object' CLEAN, item has status CLEAN\n"), - result.getResult("xxx ", "yyy", true)); - - result.setResult(ValidationStatus.WARNING, "a warning"); - assertEquals(ValidationStatus.WARNING, result.getStatus()); - - // should not override warning - result.setResult(ValidationStatus.OBSERVATION, "an observation"); - assertEquals(ValidationStatus.WARNING, result.getStatus()); - - assertTrue(result.isValid()); - assertEquals(requote("item 'my-name' value 'my-object' WARNING, a warning\n"), result.getResult()); result.setResult(ValidationStatus.INVALID, "is invalid"); assertEquals(ValidationStatus.INVALID, result.getStatus()); assertFalse(result.isValid()); - assertEquals(requote("item 'my-name' value 'my-object' INVALID, is invalid\n"), result.getResult()); - } - - private String requote(String text) { - return text.replace('\'', '"'); + assertEquals("item \"my-name\" value \"my-object\" INVALID, is invalid\n", result.getResult()); } } diff --git a/policy-common/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java b/policy-common/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java index f6851b5ef..1b8f4f04b 100644 --- a/policy-common/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java +++ b/policy-common/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation + * Modifications Copyright (C) 2024-2026 OpenInfra Foundation Europe. 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. @@ -23,8 +23,6 @@ package org.onap.policy.common.parameters; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,46 +47,9 @@ class TestValidationResultImpl { assertEquals("invalid data", result.getMessage()); } - @Test - void testValidateNotNull() { - assertTrue(result.validateNotNull()); - assertTrue(result.isValid()); - assertNull(result.getResult()); - - // now try with null - result = new MyResult(NAME, null); - assertFalse(result.validateNotNull()); - assertFalse(result.isValid()); - assertEquals("INVALID is null", result.getResult()); - } - - @Test - void testSetResultValidationStatus() { - result.setResult(ValidationStatus.WARNING); - assertEquals(ValidationStatus.WARNING, result.getStatus()); - - // should not override warning - result.setResult(ValidationStatus.OBSERVATION); - assertEquals(ValidationStatus.WARNING, result.getStatus()); - - assertTrue(result.isValid()); - assertEquals("WARNING item has status WARNING", result.getResult()); - } - @Test void testSetResult_testGetResult_testGetStatus() { assertEquals(ValidationStatus.CLEAN, result.getStatus()); - assertEquals("CLEAN item has status CLEAN", result.getResult("xxx ", "yyy", true)); - - result.setResult(ValidationStatus.WARNING, "a warning"); - assertEquals(ValidationStatus.WARNING, result.getStatus()); - - // should not override warning - result.setResult(ValidationStatus.OBSERVATION, "an observation"); - assertEquals(ValidationStatus.WARNING, result.getStatus()); - - assertTrue(result.isValid()); - assertEquals("WARNING a warning", result.getResult()); result.setResult(ValidationStatus.INVALID, "is invalid"); assertEquals(ValidationStatus.INVALID, result.getStatus()); @@ -112,8 +73,8 @@ class TestValidationResultImpl { } @Override - public String getResult(String initialIndentation, String subIndentation, boolean showClean) { - if (!showClean && getStatus() == ValidationStatus.CLEAN) { + public String getResult(String initialIndentation, String subIndentation) { + if (getStatus() == ValidationStatus.CLEAN) { return null; } diff --git a/policy-models/src/main/java/org/onap/policy/models/base/PfConcept.java b/policy-models/src/main/java/org/onap/policy/models/base/PfConcept.java index c8be88d22..ae8983b37 100644 --- a/policy-models/src/main/java/org/onap/policy/models/base/PfConcept.java +++ b/policy-models/src/main/java/org/onap/policy/models/base/PfConcept.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2023 Nordix Foundation. + * Copyright (C) 2019-2026 OpenInfra Foundation Europe. All rights reserved. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +34,7 @@ import lombok.NonNull; */ @NoArgsConstructor(access = AccessLevel.PROTECTED) -public abstract class PfConcept extends Validated implements Serializable, Comparable { +public abstract class PfConcept implements Serializable, Comparable { @Serial private static final long serialVersionUID = -7434939557282697490L; diff --git a/policy-models/src/main/java/org/onap/policy/models/base/Validated.java b/policy-models/src/main/java/org/onap/policy/models/base/Validated.java deleted file mode 100644 index daade23f7..000000000 --- a/policy-models/src/main/java/org/onap/policy/models/base/Validated.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024-2026 OpenInfra Foundation Europe. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.base; - -import lombok.NonNull; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.parameters.BeanValidator; - -/** - * Classes that can be validated. This can be used as a super class or as a stand-alone - * utility class. - */ -public class Validated { - public static final String NOT_FOUND = "not found"; - - /** - * Validates the fields of the object. The default method uses a {@link BeanValidator} - * to validate the object. - * - * @param fieldName name of the field containing this - * @return the result, or {@code null} - */ - public final BeanValidationResult validate(@NonNull String fieldName) { - return BeanValidator.validate(fieldName, this); - } -} diff --git a/policy-models/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java b/policy-models/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java index a24341458..c07191c8f 100644 --- a/policy-models/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java +++ b/policy-models/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * Modifications Copyright (C) 2020-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import java.io.Serializable; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.models.base.PfKey; /** @@ -38,7 +36,6 @@ public class ToscaConceptIdentifier extends ToscaNameVersion implements Serializable, Comparable { private static final long serialVersionUID = 8010649773816325786L; - public ToscaConceptIdentifier(@NonNull String name, @NonNull String version) { super(name, version); } @@ -51,20 +48,6 @@ public class ToscaConceptIdentifier extends ToscaNameVersion super(source); } - /** - * Validates that appropriate fields are populated for an incoming call to the PAP REST API. - * - * @return the validation result - */ - public ValidationResult validatePapRest() { - var result = new BeanValidationResult("identifier", this); - - result.validateNotNull("name", getName()); - result.validateNotNull("version", getVersion()); - - return result; - } - @Override public int compareTo(ToscaConceptIdentifier other) { return commonCompareTo(other); diff --git a/policy-models/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java b/policy-models/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java index ceb58c793..f0b5bfc88 100644 --- a/policy-models/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java +++ b/policy-models/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java @@ -21,7 +21,6 @@ package org.onap.policy.models.base; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,16 +29,12 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import jakarta.validation.constraints.Pattern; -import java.lang.reflect.Field; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.onap.policy.common.parameters.BeanValidator; -import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.models.base.PfKey.Compatibility; class PfKeyImplTest { @@ -138,21 +133,6 @@ class PfKeyImplTest { assertEquals(Compatibility.MAJOR, buildKey3.getCompatibility(someKey1)); } - @Test - void testValidityConceptKey() { - assertTrue(someKey0.validate("").isValid()); - assertTrue(someKey1.validate("").isValid()); - assertTrue(someKey2.validate("").isValid()); - assertTrue(someKey3.validate("").isValid()); - assertTrue(someKey4.validate("").isValid()); - assertTrue(someKey5.validate("").isValid()); - assertTrue(someKey6.validate("").isValid()); - assertTrue(buildKey1.validate("").isValid()); - assertTrue(buildKey2.validate("").isValid()); - assertTrue(buildKey3.validate("").isValid()); - assertTrue(buildKey4.validate("").isValid()); - } - @Test void testCleanConceptKey() { someKey0.clean(); @@ -190,41 +170,14 @@ class PfKeyImplTest { .hasMessageMatching("^name is marked non-null but is null$"); } - @Test - void testValidation() throws Exception { - MyKey testKey = new MyKey("TheKey", VERSION001); - assertEquals("TheKey:0.0.1", testKey.getId()); - - Field nameField = testKey.getClass().getDeclaredField(NAME); - nameField.setAccessible(true); - nameField.set(testKey, "Key Name"); - ValidationResult validationResult = testKey.validate(""); - nameField.set(testKey, "TheKey"); - nameField.setAccessible(false); - assertThat(validationResult.getResult()).contains("\"name\"").doesNotContain("\"version\"") - .contains("must match \"" + PfKey.NAME_REGEXP + "\""); - - Field versionField = testKey.getClass().getDeclaredField("version"); - versionField.setAccessible(true); - versionField.set(testKey, "Key Version"); - ValidationResult validationResult2 = testKey.validate(""); - versionField.set(testKey, VERSION001); - versionField.setAccessible(false); - assertThat(validationResult2.getResult()).doesNotContain("\"name\"").contains("\"version\"") - .contains("must match \"" + PfKey.VERSION_REGEXP + "\""); - } - @Getter @Setter @EqualsAndHashCode(callSuper = false) @NoArgsConstructor - public static class MyKey extends PfKeyImpl { + private static class MyKey extends PfKeyImpl { private static final long serialVersionUID = 1L; - @Pattern(regexp = NAME_REGEXP) private String name; - - @Pattern(regexp = VERSION_REGEXP) private String version; public MyKey(String name, String version) { diff --git a/policy-models/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierTest.java b/policy-models/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierTest.java index 17fbeeff3..c3e147598 100644 --- a/policy-models/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierTest.java +++ b/policy-models/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifierTest.java @@ -3,7 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021, 2024 Nordix Foundation. + * Modifications Copyright (C) 2021-2026 OpenInfra Foundation Europe. 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. @@ -23,13 +23,8 @@ package org.onap.policy.models.tosca.authorative.concepts; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; -import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.models.base.PfConceptKey; /** @@ -79,27 +74,6 @@ class ToscaConceptIdentifierTest extends ToscaIdentifierTestBase