/*-
* ============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.
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.
final Collection<DocConceptKey> dataTypeKeyCollection, Map<String, Set<String>> 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);
}
}
}
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);
}
}
}
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);
}
}
}
continue;
}
if (!isTypePresent(parentEntityTypeKey, reference)) {
- result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND);
+ result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, NOT_FOUND);
}
}
}
continue;
}
if (!isTypePresent(parentEntityTypeKey, reference)) {
- result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND);
+ result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, NOT_FOUND);
}
}
}
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<T extends ToscaEntity> extends Validated
+public class DocToscaEntity<T extends ToscaEntity>
implements PfNameVersion, PfAuthorative<T>, Serializable, Comparable<DocToscaEntity<T>> {
@Serial
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<ToscaTopologyTemplate>, Serializable, Comparable<DocToscaTopologyTemplate> {
@Serial
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.
@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<AutomationComposition>, Comparable<JpaAutomationComposition> {
@Id
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.
@Table(name = "AutomationCompositionDefinition")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
-@EqualsAndHashCode(callSuper = false)
-public class JpaAutomationCompositionDefinition extends Validated
- implements PfAuthorative<AutomationCompositionDefinition> {
+@EqualsAndHashCode
+public class JpaAutomationCompositionDefinition implements PfAuthorative<AutomationCompositionDefinition> {
@Id
@NotNull
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;
@Table(name = "AutomationCompositionElement")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
-@EqualsAndHashCode(callSuper = false)
-public class JpaAutomationCompositionElement extends Validated
+@EqualsAndHashCode
+public class JpaAutomationCompositionElement
implements PfAuthorative<AutomationCompositionElement>, Comparable<JpaAutomationCompositionElement> {
@Id
/*-\r
* ============LICENSE_START=======================================================\r
- * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.\r
+ * Copyright (C) 2025-2026 OpenInfra Foundation Europe. All rights reserved.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionRollback;\r
import org.onap.policy.models.base.PfAuthorative;\r
import org.onap.policy.models.base.PfUtils;\r
-import org.onap.policy.models.base.Validated;\r
\r
@Entity\r
@Table(name = "AutomationCompositionRollback")\r
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)\r
@Data\r
-@EqualsAndHashCode(callSuper = false)\r
-public class JpaAutomationCompositionRollback extends Validated\r
+@EqualsAndHashCode\r
+public class JpaAutomationCompositionRollback\r
implements PfAuthorative<AutomationCompositionRollback>, Comparable<JpaAutomationCompositionRollback> {\r
\r
@Id\r
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<DocMessage> {
+public class JpaMessage implements PfAuthorative<DocMessage> {
@Id
@NotNull
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
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;
@Table(name = "NodeTemplateState")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
-@EqualsAndHashCode(callSuper = false)
-public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
+@EqualsAndHashCode
+public class JpaNodeTemplateState implements PfAuthorative<NodeTemplateState> {
@Id
@NotNull
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;
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.
@Table(name = "Participant")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
-@EqualsAndHashCode(callSuper = false)
-public class JpaParticipant extends Validated
- implements PfAuthorative<Participant>, Comparable<JpaParticipant>, Serializable {
-
- @Serial
- private static final long serialVersionUID = -4697758484642403483L;
+@EqualsAndHashCode
+public class JpaParticipant implements PfAuthorative<Participant>, Comparable<JpaParticipant> {
@Id
@NotNull
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<ParticipantReplica> {
+@EqualsAndHashCode
+public class JpaParticipantReplica implements PfAuthorative<ParticipantReplica> {
@Id
@NotNull
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<ParticipantSupportedElementType>, Comparable<JpaParticipantSupportedElementType> {
@NotNull
/*-
* ============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.
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 {
* @param conceptDescription the description used for validation result
* @return the list of Jpa objects
*/
- public static <A, J extends Validated & PfAuthorative<A>> List<J> getJpaAndValidateList(
+ public static <A, J extends PfAuthorative<A>> List<J> getJpaAndValidateList(
List<A> authorativeConceptList, Supplier<J> jpaSupplier, String conceptDescription) {
var validationResult = new BeanValidationResult(conceptDescription + " List", authorativeConceptList);
jpaConcept.fromAuthorative(authorativeConcept);
jpaConceptList.add(jpaConcept);
- validationResult.addResult(jpaConcept.validate(conceptDescription));
+ validationResult.addResult(BeanValidator.validate(conceptDescription, jpaConcept));
}
if (!validationResult.isValid()) {
* @param conceptDescription the description used for validation result
* @return the Jpa object
*/
- public static <A, J extends Validated & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
+ public static <A, J extends PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
Supplier<J> jpaSupplier, String conceptDescription) {
var jpaConcept = jpaSupplier.get();
jpaConcept.fromAuthorative(authorativeConcept);
* @param jpaConcept the Jpa of the concept
* @param conceptDescription the description used for validation result
*/
- public static <A, J extends Validated & PfAuthorative<A>> void validate(A authorativeConcept,
+ public static <A, J extends PfAuthorative<A>> 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());
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");
@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);
/*-
* ============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.
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;
@Test
void testJpaAutomationCompositionElementValidation() {
var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
-
- assertThatThrownBy(() -> testJpaAutomationCompositionElement.validate(null))
- .hasMessageMatching("fieldName" + NULL_ERROR);
-
- assertTrue(testJpaAutomationCompositionElement.validate("").isValid());
+ assertTrue(BeanValidator.isValid(testJpaAutomationCompositionElement));
}
@Test
/*-
* ============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.
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.
@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
/*-
* ============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.
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
-
+import org.onap.policy.common.parameters.BeanValidator;
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));
}
}
/*-
* ============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.
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 {
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
/*-
* ============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.
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.
@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
/*-
* ============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.
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.
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 <T> boolean validateNotNullList(String listName, Collection<T> list,
- Function<T, ValidationResult> 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 <T> boolean validateList(String listName, Collection<T> list, Function<T, ValidationResult> 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 <V> boolean validateMap(String mapName, Map<String, V> map,
- BiConsumer<BeanValidationResult, Entry<String, V>> entryValidator) {
- if (map == null) {
- return true;
- }
-
- var result = new BeanValidationResult(mapName, null);
- for (Entry<String, V> 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;
}
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);
}
}
return result;
}
+
+ /**
+ * Validates the given bean.
+ *
+ * @param <T> the type of the bean
+ * @param bean the bean to validate
+ * @return the validation result
+ */
+ public static <T> BeanValidationResult validate(final T bean) {
+ return validate(bean.getClass().getSimpleName(), bean);
+ }
+
+ /**
+ * Validates the given bean.
+ *
+ * @param <T> the type of the bean
+ * @param bean the bean to validate
+ * @return true if the bean is valid
+ */
+ public static <T> boolean isValid(final T bean) {
+ return validate(bean).isValid();
+ }
}
/*
* ============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.
*
* @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;
}
+++ /dev/null
-/*-
- * ============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;
-}
@Override
public BeanValidationResult validate() {
- return BeanValidator.validate(getClass().getSimpleName(), this);
+ return BeanValidator.validate(this);
}
}
/*-
* ============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.
* 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.
*
* @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);
}
/**
*
* @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.
* @param message The validation message explaining the validation status
*/
void setResult(final ValidationStatus status, final String message);
-}
\ No newline at end of file
+}
* ============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.
/**
* Validation message.
*/
- private String message = ITEM_HAS_STATUS_MESSAGE + status.toString();
+ private String message = ITEM_HAS_STATUS_MESSAGE + status;
/**
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
/*-
* ============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.
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
public boolean isValid() {
return !this.equals(INVALID);
}
-
+
/**
* Check if the validation was clean.
* @return true if the validation is clean
* 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.
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;
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;
@BeforeEach
void setUp() {
clean = new ObjectValidationResult(TEXT1, 10);
- cleanMsg = clean.getResult("", "", true);
invalid = new ObjectValidationResult(TEXT2, 20);
invalid.setResult(ValidationStatus.INVALID, "invalid");
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<ValidationResult> 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<ValidationResult> 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<ValidationResult> 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<String, ValidationResult> 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<BeanValidationResult, Entry<String, ValidationResult>> 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('\'', '"');
- }
}
* 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.
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;
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());
}
}
* 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.
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;
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());
}
@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;
}
/*-
* ============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");
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public abstract class PfConcept extends Validated implements Serializable, Comparable<PfConcept> {
+public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
@Serial
private static final long serialVersionUID = -7434939557282697490L;
+++ /dev/null
-/*
- * ============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);
- }
-}
* 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.
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;
/**
implements Serializable, Comparable<ToscaConceptIdentifier> {
private static final long serialVersionUID = 8010649773816325786L;
-
public ToscaConceptIdentifier(@NonNull String name, @NonNull String version) {
super(name, version);
}
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);
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;
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 {
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();
.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) {
* 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.
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;
/**
assertEquals(origKey, new ToscaConceptIdentifier(origKey).asConceptKey());
}
- @Test
- void testValidatePapRest() throws Exception {
- ToscaConceptIdentifier ident = new ToscaConceptIdentifier(NAME, VERSION);
- ValidationResult result = ident.validatePapRest();
- assertNotNull(result);
- assertTrue(result.isValid());
- assertNull(result.getResult());
-
- ident = makeIdent(NAME, null);
- result = ident.validatePapRest();
- assertNotNull(result);
- assertFalse(result.isValid());
- assertNotNull(result.getResult());
-
- ident = makeIdent(null, VERSION);
- result = ident.validatePapRest();
- assertNotNull(result);
- assertFalse(result.isValid());
- assertNotNull(result.getResult());
- }
-
@Test
@Override
void testCompareTo() throws Exception {