From 3ebeed66d44b562676e3e8fd5b096b4849272132 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 20 Jan 2026 13:42:41 +0000 Subject: [PATCH] Refactor clamp models to isolate any business logic Issue-ID: POLICY-5549 Change-Id: Ib92ff2a261882050932f1c72fe1c784a7d62ebc6 Signed-off-by: FrancescoFioraEst --- .../clamp/models/acm/concepts/AcElementDeploy.java | 5 +-- .../models/acm/concepts/AcElementRestart.java | 5 +-- .../acm/concepts/AutomationCompositionElement.java | 6 +-- .../models/acm/document/base/DocConceptKey.java | 14 ------ .../clamp/models/acm/document/base/DocUtil.java | 12 ++--- .../base/ToscaServiceTemplateValidation.java | 8 ++-- .../concepts/DocToscaServiceTemplateTest.java | 1 - .../org/onap/policy/models/base/PfConcept.java | 43 ------------------ .../org/onap/policy/models/base/PfConceptKey.java | 12 +---- .../java/org/onap/policy/models/base/PfKey.java | 12 +---- .../org/onap/policy/models/base/PfKeyImpl.java | 45 +------------------ .../java/org/onap/policy/models/base/PfUtils.java | 51 +++++++++++++++++++++- .../validation/annotations/VerifyKeyValidator.java | 9 ++-- .../onap/policy/models/base/PfConceptKeyTest.java | 23 +++------- .../org/onap/policy/models/base/PfKeyImplTest.java | 17 +++----- 15 files changed, 90 insertions(+), 173 deletions(-) diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java index 1ab8456fb..645f3a58a 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeploy.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-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. @@ -28,7 +28,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; -import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -44,7 +43,7 @@ public class AcElementDeploy { private UUID id = UUID.randomUUID(); @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfUtils.getNullKey()); @NonNull private DeployOrder orderedState = DeployOrder.DEPLOY; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java index e80fa5e29..d9083046c 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-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,7 +27,6 @@ import java.util.function.UnaryOperator; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; -import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -40,7 +39,7 @@ public class AcElementRestart { private UUID id = UUID.randomUUID(); @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfUtils.getNullKey()); private UUID participantId; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index 54ab13264..8e6b188e7 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.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. @@ -28,7 +28,7 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.ToString; import org.onap.policy.clamp.models.acm.utils.AcmUtils; -import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** @@ -42,7 +42,7 @@ public class AutomationCompositionElement { private UUID id = UUID.randomUUID(); @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfUtils.getNullKey()); @NonNull private UUID participantId = UUID.randomUUID(); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocConceptKey.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocConceptKey.java index 7044b1c50..eaa3d30da 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocConceptKey.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocConceptKey.java @@ -23,14 +23,12 @@ package org.onap.policy.clamp.models.acm.document.base; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.validation.constraints.Pattern; import java.io.Serial; -import java.util.List; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import lombok.ToString; import org.onap.policy.common.utils.validation.Assertions; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfKeyImpl; @Data @@ -54,12 +52,6 @@ public class DocConceptKey extends PfKeyImpl { this(NULL_KEY_NAME, NULL_KEY_VERSION); } - @Override - @JsonIgnore - public String getId() { - return name + ":" + version; - } - /** * Copy constructor. * @@ -94,10 +86,4 @@ public class DocConceptKey extends PfKeyImpl { public PfKeyImpl getKey() { return this; } - - @Override - @JsonIgnore - public List getKeys() { - return super.getKeys(); - } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocUtil.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocUtil.java index 55b62f0f6..f466f14ca 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocUtil.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/DocUtil.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022,2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2022,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,6 +42,7 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfNameVersion; +import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -134,7 +135,7 @@ public final class DocUtil { var authoritiveImpl = mapFunc.apply(incomingConceptEntry.getValue()); // After all that, save the map entry - conceptMap.put(conceptKey.getId(), authoritiveImpl); + conceptMap.put(PfUtils.getId(conceptKey), authoritiveImpl); } return conceptMap; @@ -148,8 +149,9 @@ public final class DocUtil { if (StringUtils.isBlank(conceptField) || keyFieldValue.equals(conceptField)) { return keyFieldValue; } else { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Key " + conceptKey.getId() + " field " - + keyFieldValue + " does not match the value " + conceptField + " in the concept field"); + var msg = "Key " + PfUtils.getId(conceptKey) + " field " + + keyFieldValue + " does not match the value " + conceptField + " in the concept field"; + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, msg); } } @@ -300,7 +302,7 @@ public final class DocUtil { private static > Set toSetToscaReferences(Map map) { Set result = new HashSet<>(); for (var entity : map.values()) { - result.add(entity.getDocConceptKey().getId()); // ref for type + result.add(PfUtils.getId(entity.getDocConceptKey())); // ref for type result.add(entity.getDocConceptKey().getName()); // ref for derived from } return result; 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 b1ff46b05..d6208553d 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 @@ -32,6 +32,7 @@ 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.PfUtils; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ToscaServiceTemplateValidation { @@ -153,7 +154,8 @@ 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, NOT_FOUND); + result.addResult( + "data type", PfUtils.getId(dataTypeKey), ValidationStatus.INVALID, NOT_FOUND); } } } @@ -198,7 +200,7 @@ public final class ToscaServiceTemplateValidation { if (reference.isEmpty()) { return false; } - return reference.contains(key.getId()); + return reference.contains(PfUtils.getId(key)); } private static String extractDerivedFrom(DocToscaEntity entityType, final BeanValidationResult result) { @@ -211,7 +213,7 @@ public final class ToscaServiceTemplateValidation { return null; } if (entityType.getName().equals(parentEntityTypeKey)) { - result.addResult("entity type", entityType.getDocConceptKey().getId(), ValidationStatus.INVALID, + result.addResult("entity type", PfUtils.getId(entityType.getDocConceptKey()), ValidationStatus.INVALID, "ancestor of itself"); return null; } 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 6abd5355c..130f294d1 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 @@ -235,6 +235,5 @@ class DocToscaServiceTemplateTest { assertThatThrownBy(() -> docConceptKey.setName(null)). isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> docConceptKey.setVersion(null)). isInstanceOf(NullPointerException.class); assertEquals("NULL", docConceptKey.getKey().getName()); - assertThat(docConceptKey.getKeys()).hasSize(1); } } 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 ae8983b37..695ffbf84 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 @@ -23,7 +23,6 @@ package org.onap.policy.models.base; import java.io.Serial; import java.io.Serializable; -import java.util.List; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -54,37 +53,6 @@ public abstract class PfConcept implements Serializable, Comparable { */ public abstract PfKey getKey(); - /** - * Gets a list of all keys for this concept and all concepts that are defined or referenced by this concept and its - * sub-concepts. - * - * @return the keys used by this concept and its contained concepts - */ - public abstract List getKeys(); - - /** - * Clean this concept, tidy up any superfluous information such as leading and trailing white space. - */ - public abstract void clean(); - - @Override - public abstract boolean equals(Object otherObject); - - @Override - public abstract String toString(); - - @Override - public abstract int hashCode(); - - /** - * Gets the ID string of this concept. - * - * @return the ID string of this concept - */ - public String getId() { - return getKey().getId(); - } - /** * Gets the name of this concept. * @@ -102,15 +70,4 @@ public abstract class PfConcept implements Serializable, Comparable { public String getVersion() { return getKey().getVersion(); } - - /** - * Checks if this key matches the given key ID. - * - * @param id the key ID to match against - * @return true, if this key matches the ID - */ - public final boolean matchesId(@NonNull final String id) { - // Check the ID - return getId().equals(id); - } } diff --git a/policy-models/src/main/java/org/onap/policy/models/base/PfConceptKey.java b/policy-models/src/main/java/org/onap/policy/models/base/PfConceptKey.java index 2d3255c84..11dacce3f 100644 --- a/policy-models/src/main/java/org/onap/policy/models/base/PfConceptKey.java +++ b/policy-models/src/main/java/org/onap/policy/models/base/PfConceptKey.java @@ -33,8 +33,7 @@ import org.onap.policy.common.utils.validation.Assertions; /** * A concept key uniquely identifies every first order entity in the system. Every first order concept in the system - * must have an {@link PfConceptKey} to identify it. Concepts that are wholly contained in another concept are - * identified using a {@link PfReferenceKey} key. + * must have an {@link PfConceptKey} to identify it. * *

Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP * regular expressions respectively. @@ -97,13 +96,4 @@ public class PfConceptKey extends PfKeyImpl { public void setVersion(@NonNull final String version) { this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx()); } - - /** - * Get a null concept key. - * - * @return a null concept key - */ - public static PfConceptKey getNullKey() { - return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION); - } } diff --git a/policy-models/src/main/java/org/onap/policy/models/base/PfKey.java b/policy-models/src/main/java/org/onap/policy/models/base/PfKey.java index e69f9f904..ed3a763ce 100644 --- a/policy-models/src/main/java/org/onap/policy/models/base/PfKey.java +++ b/policy-models/src/main/java/org/onap/policy/models/base/PfKey.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019, 2023 Nordix Foundation. + * Copyright (C) 2019, 2023,2026 OpenInfra Foundation Europe. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -83,9 +83,6 @@ public abstract class PfKey extends PfConcept { super(copyConcept); } - @Override - public abstract String getId(); - /** * Return the result of a compatibility check of two keys. * @@ -93,11 +90,4 @@ public abstract class PfKey extends PfConcept { * @return the compatibility result of the check */ public abstract Compatibility getCompatibility(@NonNull PfKey otherKey); - - /** - * Check if a key equals its null key. - * - * @return true, if the key is a null key - */ - public abstract boolean isNullKey(); } diff --git a/policy-models/src/main/java/org/onap/policy/models/base/PfKeyImpl.java b/policy-models/src/main/java/org/onap/policy/models/base/PfKeyImpl.java index 5a84a92e6..2bd4554c5 100644 --- a/policy-models/src/main/java/org/onap/policy/models/base/PfKeyImpl.java +++ b/policy-models/src/main/java/org/onap/policy/models/base/PfKeyImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020, 2023 Nordix Foundation. + * Copyright (C) 2019-2020, 2023,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"); @@ -22,8 +22,6 @@ package org.onap.policy.models.base; import java.io.Serial; -import java.util.ArrayList; -import java.util.List; import lombok.Getter; import lombok.NonNull; import lombok.ToString; @@ -99,41 +97,6 @@ public abstract class PfKeyImpl extends PfKey { return this; } - @Override - public List getKeys() { - final List keyList = new ArrayList<>(); - keyList.add(getKey()); - return keyList; - } - - @Override - public String getId() { - return getName() + ':' + getVersion(); - } - - @Override - public boolean isNullKey() { - return (PfKey.NULL_KEY_NAME.equals(getName()) && PfKey.NULL_KEY_VERSION.equals(getVersion())); - } - - /** - * Determines if the name is "null". - * - * @return {@code true} if the name is null, {@code false} otherwise - */ - public boolean isNullName() { - return PfKey.NULL_KEY_NAME.equals(getName()); - } - - /** - * Determines if the version is "null". - * - * @return {@code true} if the version is null, {@code false} otherwise - */ - public boolean isNullVersion() { - return PfKey.NULL_KEY_VERSION.equals(getVersion()); - } - @Override public PfKey.Compatibility getCompatibility(@NonNull final PfKey otherKey) { if (!(otherKey instanceof PfKeyImpl otherConceptKey)) { @@ -163,12 +126,6 @@ public abstract class PfKeyImpl extends PfKey { return Compatibility.PATCH; } - @Override - public void clean() { - setName(getName()); - setVersion(getVersion()); - } - @Override public int compareTo(@NonNull final PfConcept otherObj) { Assertions.argumentNotNull(otherObj, "comparison object may not be null"); diff --git a/policy-models/src/main/java/org/onap/policy/models/base/PfUtils.java b/policy-models/src/main/java/org/onap/policy/models/base/PfUtils.java index eb7f201cf..165f1f464 100644 --- a/policy-models/src/main/java/org/onap/policy/models/base/PfUtils.java +++ b/policy-models/src/main/java/org/onap/policy/models/base/PfUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021, 2023-2024 Nordix Foundation. + * Copyright (C) 2019-2021, 2023-2024,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"); @@ -41,6 +41,55 @@ import org.apache.commons.collections4.MapUtils; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class PfUtils { + /** + * Gets the ID string of this concept. + * + * @param key the PfKey object + * @return the ID string of this concept + */ + public static String getId(PfKey key) { + return key.getName() + ':' + key.getVersion(); + } + + /** + * Determines if the name is "null". + * + * @param key the PfKeyImpl object + * @return {@code true} if the name is null, {@code false} otherwise + */ + public static boolean isNullName(PfKeyImpl key) { + return PfKey.NULL_KEY_NAME.equals(key.getName()); + } + + /** + * Determines if the version is "null". + * + * @param key the PfKeyImpl object + * @return {@code true} if the version is null, {@code false} otherwise + */ + public static boolean isNullVersion(PfKeyImpl key) { + return PfKey.NULL_KEY_VERSION.equals(key.getVersion()); + } + + /** + * Check if a key equals its null key. + * + * @param key the PfKey object + * @return true, if the key is a null key + */ + public static boolean isNullKey(PfKey key) { + return (PfKey.NULL_KEY_NAME.equals(key.getName()) && PfKey.NULL_KEY_VERSION.equals(key.getVersion())); + } + + /** + * Get a null concept key. + * + * @return a null concept key + */ + public static PfConceptKey getNullKey() { + return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION); + } + /** * Compare two objects using their equals methods, nulls are allowed. * diff --git a/policy-models/src/main/java/org/onap/policy/models/base/validation/annotations/VerifyKeyValidator.java b/policy-models/src/main/java/org/onap/policy/models/base/validation/annotations/VerifyKeyValidator.java index 33048d9e1..508ef5d3c 100644 --- a/policy-models/src/main/java/org/onap/policy/models/base/validation/annotations/VerifyKeyValidator.java +++ b/policy-models/src/main/java/org/onap/policy/models/base/validation/annotations/VerifyKeyValidator.java @@ -24,6 +24,7 @@ import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfKeyImpl; +import org.onap.policy.models.base.PfUtils; public class VerifyKeyValidator implements ConstraintValidator { @@ -43,19 +44,19 @@ public class VerifyKeyValidator implements ConstraintValidator context.disableDefaultConstraintViolation(); boolean valid = true; - if (annotation.keyNotNull() && pfkey.isNullKey()) { + if (annotation.keyNotNull() && PfUtils.isNullKey(pfkey)) { context.buildConstraintViolationWithTemplate("is a null key").addConstraintViolation(); return false; } - if (pfkey instanceof PfKeyImpl keyimpl) { - if (annotation.nameNotNull() && keyimpl.isNullName()) { + if (pfkey instanceof PfKeyImpl keyImpl) { + if (annotation.nameNotNull() && PfUtils.isNullName(keyImpl)) { context.buildConstraintViolationWithTemplate("is null") .addPropertyNode("name").addConstraintViolation(); valid = false; } - if (annotation.versionNotNull() && keyimpl.isNullVersion()) { + if (annotation.versionNotNull() && PfUtils.isNullVersion(keyImpl)) { context.buildConstraintViolationWithTemplate("is null") .addPropertyNode("version").addConstraintViolation(); valid = false; diff --git a/policy-models/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java b/policy-models/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java index 753cbe44a..39d4a7a65 100644 --- a/policy-models/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java +++ b/policy-models/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java @@ -32,38 +32,27 @@ import org.junit.jupiter.api.Test; class PfConceptKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String ID_IS_NULL = "id is marked non-null but is null$"; @Test void testConceptKey() { PfConceptKey someKey0 = new PfConceptKey(); - assertEquals(PfConceptKey.getNullKey(), someKey0); - assertTrue(someKey0.isNullKey()); + assertEquals(PfUtils.getNullKey(), someKey0); + assertTrue(PfUtils.isNullKey(someKey0)); assertEquals("PfConceptKey(name=NULL, version=0.0.0)", someKey0.toString()); PfConceptKey someKey1 = new PfConceptKey("my-name", VERSION001); PfConceptKey someKey2 = new PfConceptKey(someKey1); - PfConceptKey someKey3 = new PfConceptKey(someKey1.getId()); + PfConceptKey someKey3 = new PfConceptKey(PfUtils.getId(someKey1)); assertEquals(someKey1, someKey2); assertEquals(someKey1, someKey3); - assertFalse(someKey1.isNullVersion()); - assertFalse(someKey1.isNullName()); + assertFalse(PfUtils.isNullVersion(someKey1)); + assertFalse(PfUtils.isNullName(someKey1)); assertEquals("PfConceptKey(name=my-name, version=0.0.1)", someKey1.toString()); assertEquals("my-name", someKey1.getName()); assertEquals(VERSION001, someKey1.getVersion()); - assertEquals(someKey2, someKey1.getKey()); - assertEquals(1, someKey1.getKeys().size()); - - PfConcept pfc = new PfConceptKey(); - assertEquals(PfConceptKey.getNullKey().getId(), pfc.getId()); - - assertTrue(PfConceptKey.getNullKey().matchesId(pfc.getId())); - - assertTrue(PfConceptKey.getNullKey().isNullKey()); - - assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessageMatching(ID_IS_NULL); + assertTrue(PfUtils.isNullKey(PfUtils.getNullKey())); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) .hasMessageMatching("^name is marked non-null but is null$"); 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 f0b5bfc88..3d3853f4a 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 @@ -55,7 +55,6 @@ class PfKeyImplTest { private static final MyKey buildKey1 = new MyKey(NAME, "0.0.3+1"); private static final MyKey buildKey2 = new MyKey(NAME, "0.1.0-1"); private static final MyKey buildKey3 = new MyKey(NAME, "3.0.0-SNAPSHOT"); - private static final MyKey buildKey4 = new MyKey(NAME, "1.0.0-rc.1"); /** * Sets data in Keys for the tests. @@ -67,7 +66,7 @@ class PfKeyImplTest { someKey0 = new MyKey(); someKey1 = new MyKey(NAME, VERSION001); someKey2 = new MyKey(someKey1); - someKey3 = new MyKey(someKey1.getId()); + someKey3 = new MyKey(PfUtils.getId(someKey1)); someKey0.setName("zero"); someKey0.setVersion("0.0.2"); @@ -95,24 +94,23 @@ class PfKeyImplTest { assertThatThrownBy(() -> new MyKey((MyKey) null)) .hasMessageMatching("^copyConcept is marked non-null but is null$"); - assertTrue(someKey.isNullKey()); + assertTrue(PfUtils.isNullKey(someKey)); assertEquals(new MyKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION), someKey); MyKey someKey11 = new MyKey(NAME, VERSION001); MyKey someKey22 = new MyKey(someKey11); - MyKey someKey33 = new MyKey(someKey11.getId()); + MyKey someKey33 = new MyKey(PfUtils.getId(someKey11)); assertEquals(someKey11, someKey22); assertEquals(someKey11, someKey33); - assertFalse(someKey11.isNullKey()); - assertFalse(someKey11.isNullVersion()); + assertFalse(PfUtils.isNullKey(someKey11)); + assertFalse(PfUtils.isNullVersion(someKey11)); assertEquals(someKey22, someKey11.getKey()); - assertEquals(1, someKey11.getKeys().size()); } @Test void testCompatibilityConceptKey() { - assertEquals("name:0.1.2", someKey4.getId()); + assertEquals("name:0.1.2", PfUtils.getId(someKey4)); assertThatThrownBy(() -> someKey0.getCompatibility(null)).isInstanceOf(NullPointerException.class) .hasMessageMatching("^otherKey is marked non-null but is null$"); @@ -135,7 +133,6 @@ class PfKeyImplTest { @Test void testCleanConceptKey() { - someKey0.clean(); assertNotNull(someKey0.toString()); MyKey someKey7 = new MyKey(someKey1); @@ -151,7 +148,7 @@ class PfKeyImplTest { MyKey someKey8 = new MyKey(); someKey8.setVersion(VERSION001); - assertFalse(someKey8.isNullKey()); + assertFalse(PfUtils.isNullKey(someKey8)); } @Test -- 2.16.6