From 318f3b4e9d324608458086ea6cfa1b8fd89e9a66 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 18 Nov 2025 11:21:14 +0000 Subject: [PATCH] Add Unit tests for code coverage in ACM Issue-ID: POLICY-5403 Change-Id: I99e8197ace28c781fcfc10afabde516d8cf97442 Signed-off-by: FrancescoFioraEst --- .../models/acm/document/base/DocConceptKey.java | 11 +- .../clamp/models/acm/document/base/DocUtil.java | 16 +- .../base/ToscaServiceTemplateValidation.java | 14 +- .../concepts/DocToscaCapabilityAssignment.java | 6 +- .../acm/document/concepts/DocToscaDataType.java | 6 +- .../document/concepts/DocToscaNodeTemplate.java | 6 +- .../acm/document/concepts/DocToscaNodeType.java | 6 +- .../acm/document/concepts/DocToscaRequirement.java | 10 +- .../document/concepts/DocToscaServiceTemplate.java | 40 ++-- .../concepts/DocToscaWithToscaProperties.java | 6 +- .../models/acm/document/base/DocUtilTest.java | 52 +++++ .../base/ToscaServiceTemplateValidationTest.java | 139 ++++++++++++ .../concepts/DocToscaNodeTemplateTest.java | 97 +++++++++ .../concepts/DocToscaServiceTemplateTest.java | 241 +++++++++++++++++++++ .../concepts/DocToscaTopologyTemplateTest.java | 78 +++++++ .../kafka/participant/PropertiesUpdateTest.java | 58 +++++ .../intermediary/api/impl/AcElementListenerV3.java | 6 + .../api/impl/AcElementListenerV3Test.java | 2 +- .../impl/ParticipantIntermediaryApiImplTest.java | 15 ++ .../intermediary/handler/MsgExecutorTest.java | 2 +- .../supervision/comm/SupervisionMessagesTest.java | 10 + 21 files changed, 734 insertions(+), 87 deletions(-) create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/document/base/DocUtilTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidationTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/PropertiesUpdateTest.java 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 eb6df02f9..735d4535b 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,2025 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. @@ -65,15 +65,6 @@ public class DocConceptKey extends PfKeyImpl { super(copyConcept); } - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public DocConceptKey(final DocConceptKey copyConcept) { - this(copyConcept.getName(), copyConcept.getVersion()); - } - /** * Temporary Constructor to create a key with the specified name and version. * 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 143ee233a..55b62f0f6 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 Nordix Foundation. + * Copyright (C) 2022,2025 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. @@ -153,20 +153,6 @@ public final class DocUtil { } } - /** - * Convenience method to apply a mapping function to all of the values of a list of maps, generating a new map. - * - * @param source list of maps whose values are to be mapped, or {@code null} - * @param mapFunc mapping function - * @return a new map, containing mappings of all of the items in the original map, or {@code null} if the source is - * {@code null} - */ - public static Map listToDocMap(List> source, - Function mapFunc) { - - return listToDocMap(source, mapFunc, null); - } - /** * Convenience method to apply a mapping function to all of the values of a list of maps, generating a new map. * 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 0053ca0ca..c13ca9497 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 Nordix Foundation. + * Copyright (C) 2022-2023,2025 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. @@ -46,7 +46,7 @@ public final class ToscaServiceTemplateValidation { * @param result the result * @param serviceTemplate the serviceTemplate to validate */ - public static void validate(final BeanValidationResult result, DocToscaServiceTemplate serviceTemplate, + public static void validate(final @NonNull BeanValidationResult result, DocToscaServiceTemplate serviceTemplate, String toscaCompositionName) { var references = DocUtil.getToscaReferences(serviceTemplate); @@ -96,7 +96,7 @@ public final class ToscaServiceTemplateValidation { * @param topologyTemplate the ToscaServiceTemplate * @param toscaCompositionName the name of the ToscaComposition */ - public static void validateToscaTopologyTemplate(BeanValidationResult result, + public static void validateToscaTopologyTemplate(final @NonNull BeanValidationResult result, DocToscaTopologyTemplate topologyTemplate, String toscaCompositionName) { String acNodeTypeNotPresent = "NodeTemplate with type " + toscaCompositionName + " must exist!"; @@ -188,14 +188,14 @@ public final class ToscaServiceTemplateValidation { } private static boolean isTypePresent(String key, Set reference) { - if (reference == null || reference.isEmpty()) { + if (reference.isEmpty()) { return false; } return reference.contains(key); } private static boolean isTypePresent(DocConceptKey key, Set reference) { - if (reference == null || reference.isEmpty()) { + if (reference.isEmpty()) { return false; } return reference.contains(key.getId()); @@ -225,7 +225,7 @@ public final class ToscaServiceTemplateValidation { * @param result the result of the ancestor search with any warnings or errors */ private static void validEntityTypeAncestors(Map> entityTypes, - Set reference, @NonNull final BeanValidationResult result) { + Set reference, final BeanValidationResult result) { if (entityTypes != null) { for (var entityType : entityTypes.values()) { var parentEntityTypeKey = extractDerivedFrom(entityType, result); @@ -246,7 +246,7 @@ public final class ToscaServiceTemplateValidation { * @param result the result of the ancestor search with any warnings or errors */ private static > void validEntityTypeAncestors(List> entityTypesList, - Set reference, @NonNull final BeanValidationResult result) { + Set reference, final BeanValidationResult result) { if (entityTypesList != null) { for (var entityTypes : entityTypesList) { for (var entityType : entityTypes.values()) { diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java index e675e2387..64aa45e80 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022,2024 Nordix Foundation. + * Copyright (C) 2022,2024-2025 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. @@ -90,10 +90,6 @@ public class DocToscaCapabilityAssignment extends DocToscaWithTypeAndStringPrope @Override public int compareTo(DocToscaEntity otherConcept) { - if (this == otherConcept) { - return 0; - } - int result = super.compareTo(otherConcept); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaDataType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaDataType.java index e305f5dcf..dffb4cfc4 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaDataType.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaDataType.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,2025 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. @@ -73,10 +73,6 @@ public class DocToscaDataType extends DocToscaWithToscaProperties @Override public int compareTo(DocToscaEntity otherConcept) { - if (this == otherConcept) { - return 0; - } - int result = super.compareTo(otherConcept); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplate.java index 4a3d92c33..8a20c12bd 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplate.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplate.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,2025 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. @@ -93,10 +93,6 @@ public class DocToscaNodeTemplate extends DocToscaWithTypeAndStringProperties otherConcept) { - if (this == otherConcept) { - return 0; - } - int result = super.compareTo(otherConcept); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeType.java index 3d42582bd..6e4059284 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeType.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeType.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,2025 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. @@ -76,10 +76,6 @@ public class DocToscaNodeType extends DocToscaWithToscaProperties @Override public int compareTo(DocToscaEntity otherConcept) { - if (this == otherConcept) { - return 0; - } - int result = super.compareTo(otherConcept); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java index 9d3cc1051..1aeb66d81 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022,2024 Nordix Foundation. + * Copyright (C) 2022,2024-2025 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. @@ -60,7 +60,9 @@ public class DocToscaRequirement extends DocToscaWithTypeAndStringProperties(copyConcept.occurrences); + if (copyConcept.occurrences != null) { + this.occurrences = new ArrayList<>(copyConcept.occurrences); + } } @Override @@ -95,10 +97,6 @@ public class DocToscaRequirement extends DocToscaWithTypeAndStringProperties otherConcept) { - if (this == otherConcept) { - return 0; - } - int result = super.compareTo(otherConcept); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplate.java index 904cbfc4e..42f7099eb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplate.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplate.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,2025 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. @@ -118,7 +118,9 @@ public class DocToscaServiceTemplate extends DocToscaEntity()); - capabilityTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getCapabilityTypes(), DocToscaCapabilityType::new); + capabilityTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getCapabilityTypes(), DocToscaCapabilityType::new, + new LinkedHashMap<>()); relationshipTypes = - DocUtil.mapToDocMap(toscaServiceTemplate.getRelationshipTypes(), DocToscaRelationshipType::new); + DocUtil.mapToDocMap(toscaServiceTemplate.getRelationshipTypes(), DocToscaRelationshipType::new, + new LinkedHashMap<>()); - nodeTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getNodeTypes(), DocToscaNodeType::new); + nodeTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getNodeTypes(), DocToscaNodeType::new, + new LinkedHashMap<>()); - if (toscaServiceTemplate.getPolicyTypes() != null) { - policyTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getPolicyTypes(), DocToscaPolicyType::new); - } + policyTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getPolicyTypes(), DocToscaPolicyType::new, + new LinkedHashMap<>()); if (toscaServiceTemplate.getToscaTopologyTemplate() != null) { toscaTopologyTemplate = new DocToscaTopologyTemplate(toscaServiceTemplate.getToscaTopologyTemplate()); @@ -191,27 +196,18 @@ public class DocToscaServiceTemplate extends DocToscaEntity otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); + int result = super.compareTo(otherConcept); + if (result != 0) { + return result; } final var other = (DocToscaServiceTemplate) otherConcept; - if (!super.equals(other)) { - return super.compareTo(other); - } - return ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java index bcb63a2f1..5aa3aad9b 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022,2024 Nordix Foundation. + * Copyright (C) 2022,2024-2025 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. @@ -126,10 +126,6 @@ public class DocToscaWithToscaProperties ext @Override public int compareTo(final DocToscaEntity otherConcept) { - if (this == otherConcept) { - return 0; - } - int result = super.compareTo(otherConcept); if (result != 0) { return result; diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/document/base/DocUtilTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/document/base/DocUtilTest.java new file mode 100644 index 000000000..4a643c341 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/document/base/DocUtilTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 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.clamp.models.acm.document.base; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate; +import org.onap.policy.models.base.PfNameVersion; + +class DocUtilTest { + + @Test + void testDocMapToList() { + Map map = null; + List> defaultValue = List.of(); + var result = DocUtil.docMapToList(map, Function.identity(), defaultValue); + assertThat(result).isEqualTo(defaultValue); + } + + @Test + void testGetToscaReferences() { + var docServiceTemplate = new DocToscaServiceTemplate(); + var result = DocUtil.getToscaReferences(docServiceTemplate); + assertThat(result).isNotEmpty(); + docServiceTemplate.setToscaTopologyTemplate(new DocToscaTopologyTemplate()); + result = DocUtil.getToscaReferences(docServiceTemplate); + assertThat(result).isNotEmpty(); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidationTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidationTest.java new file mode 100644 index 000000000..1568af18b --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidationTest.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 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.clamp.models.acm.document.base; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaDataType; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaNodeTemplate; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaPolicy; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaProperty; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaRequirement; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate; +import org.onap.policy.common.parameters.BeanValidationResult; + +class ToscaServiceTemplateValidationTest { + + public static final String AUTOMATION_COMPOSITION_ELEMENT = + "org.onap.policy.clamp.acm.AutomationCompositionElement"; + public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition"; + private static final String NAME_VERSION1 = "name:1.0.0"; + private static final String NAME_VERSION2 = "name:1.0.1"; + private static final String NAME = "name"; + private static final String TYPE = "type"; + private static final String VERSION = "1.0.0"; + + @Test + void testValidate() { + var doc = new DocToscaServiceTemplate(); + assertThatThrownBy( + () -> ToscaServiceTemplateValidation.validate(null, doc, AUTOMATION_COMPOSITION_NODE_TYPE)) + .isInstanceOf(NullPointerException.class); + var result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + + var docDataType = new DocToscaDataType(); + docDataType.setName(NAME); + docDataType.setVersion(VERSION); + var docProperty = new DocToscaProperty(); + docProperty.setType(TYPE); + docProperty.setTypeVersion(VERSION); + docDataType.setProperties(Map.of(NAME_VERSION1, docProperty)); + docDataType.setDerivedFrom("NotExist"); + doc.setDataTypes(Map.of(NAME_VERSION1, docDataType)); + result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + + // ancestor of itself + docDataType.setDerivedFrom(NAME); + result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + + doc.setDataTypes(null); + var docTopologyTemplate = new DocToscaTopologyTemplate(); + doc.setToscaTopologyTemplate(docTopologyTemplate); + result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + + var docPolicy = new DocToscaPolicy(); + docPolicy.setType(TYPE); + docPolicy.setTypeVersion(VERSION); + docTopologyTemplate.setPolicies(Map.of(NAME_VERSION1, docPolicy)); + result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + + docTopologyTemplate.setPolicies(null); + var docNodeTemplates = new DocToscaNodeTemplate(); + docNodeTemplates.setType(TYPE); + docNodeTemplates.setTypeVersion(VERSION); + var docRequirement = new DocToscaRequirement(); + docRequirement.setType(TYPE); + docRequirement.setTypeVersion(VERSION); + docNodeTemplates.setRequirements(List.of(Map.of(NAME_VERSION1, docRequirement))); + docTopologyTemplate.setNodeTemplates(Map.of(NAME_VERSION1, docNodeTemplates)); + result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + + docRequirement.setDerivedFrom("NotExist"); + result = getValidate(doc); + assertThat(result.isValid()).isFalse(); + } + + private BeanValidationResult getValidate(DocToscaServiceTemplate doc) { + var result = new BeanValidationResult("DocToscaServiceTemplate", doc); + ToscaServiceTemplateValidation.validate(result, doc, AUTOMATION_COMPOSITION_NODE_TYPE); + return result; + } + + @Test + void testValidateToscaTopologyTemplate() { + var result = getValidateToscaTopologyTemplate(null); + assertThat(result.isValid()).isFalse(); + + var doc = new DocToscaTopologyTemplate(); + assertThatThrownBy(() -> ToscaServiceTemplateValidation + .validateToscaTopologyTemplate(null, doc, AUTOMATION_COMPOSITION_NODE_TYPE)) + .isInstanceOf(NullPointerException.class); + result = getValidateToscaTopologyTemplate(doc); + assertThat(result.isValid()).isFalse(); + + var docNodeTemplate1 = new DocToscaNodeTemplate(); + docNodeTemplate1.setType(AUTOMATION_COMPOSITION_NODE_TYPE); + docNodeTemplate1.setTypeVersion(VERSION); + var docNodeTemplate2 = new DocToscaNodeTemplate(); + docNodeTemplate2.setType(AUTOMATION_COMPOSITION_NODE_TYPE); + docNodeTemplate2.setTypeVersion("1.0.1"); + doc.setNodeTemplates(Map.of(NAME_VERSION1, docNodeTemplate1, NAME_VERSION2, docNodeTemplate2)); + result = getValidateToscaTopologyTemplate(doc); + assertThat(result.isValid()).isFalse(); + } + + private BeanValidationResult getValidateToscaTopologyTemplate(DocToscaTopologyTemplate doc) { + var result = new BeanValidationResult("DocToscaTopologyTemplate", doc); + ToscaServiceTemplateValidation.validateToscaTopologyTemplate(result, doc, AUTOMATION_COMPOSITION_NODE_TYPE); + return result; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplateTest.java new file mode 100644 index 000000000..d98772578 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaNodeTemplateTest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 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.clamp.models.acm.document.concepts; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement; + +class DocToscaNodeTemplateTest { + + private static final String NAME = "name"; + private static final String TYPE = "type"; + private static final String VERSION = "1.0.0"; + private static final String NAME_VERSION = "name:0.0.0"; + + @Test + void testToscaNodeTemplate() { + var nodeTemplate = new ToscaNodeTemplate(); + nodeTemplate.setType(TYPE); + nodeTemplate.setTypeVersion(VERSION); + var doc = new DocToscaNodeTemplate(nodeTemplate); + assertThat(doc) + .isNotEqualByComparingTo(null) + .isEqualByComparingTo(doc); + + var requirement = new ToscaRequirement(); + requirement.setType(TYPE); + requirement.setTypeVersion(VERSION); + nodeTemplate.setRequirements(List.of(Map.of(NAME, requirement))); + var doc2 = new DocToscaNodeTemplate(doc); + doc = new DocToscaNodeTemplate(nodeTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setRequirements(doc.getRequirements()); + assertThat(doc).isEqualByComparingTo(doc2); + + var capabilityAssignment = new ToscaCapabilityAssignment(); + capabilityAssignment.setType(TYPE); + capabilityAssignment.setTypeVersion(VERSION); + nodeTemplate.setCapabilities(Map.of(NAME, capabilityAssignment)); + doc = new DocToscaNodeTemplate(nodeTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setCapabilities(doc.getCapabilities()); + assertThat(doc).isEqualByComparingTo(doc2); + + capabilityAssignment.setAttributes(Map.of("key", "value")); + doc = new DocToscaNodeTemplate(nodeTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + var docCapabilityAssignment = doc.getCapabilities().get(NAME_VERSION); + assertThat(docCapabilityAssignment) + .isNotEqualByComparingTo(null) + .isEqualByComparingTo(docCapabilityAssignment); + + doc2.getCapabilities().get(NAME_VERSION).setAttributes(docCapabilityAssignment.getAttributes()); + assertThat(doc).isEqualByComparingTo(doc2); + + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + doc2 = new DocToscaNodeTemplate(doc); + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + + capabilityAssignment.setAttributes(null); + capabilityAssignment.setOccurrences(List.of(NAME)); + doc = new DocToscaNodeTemplate(nodeTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + docCapabilityAssignment = doc.getCapabilities().get(NAME_VERSION); + + doc2.getCapabilities().get(NAME_VERSION).setAttributes(docCapabilityAssignment.getAttributes()); + doc2.getCapabilities().get(NAME_VERSION).setOccurrences(docCapabilityAssignment.getOccurrences()); + assertThat(doc).isEqualByComparingTo(doc2); + + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + doc2 = new DocToscaNodeTemplate(doc); + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + } +} 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 new file mode 100644 index 000000000..0f18e8e00 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaServiceTemplateTest.java @@ -0,0 +1,241 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 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.clamp.models.acm.document.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.document.base.DocConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; +import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; + +class DocToscaServiceTemplateTest { + + private static final String NAME = "name"; + private static final String NAME_VERSION = "name:0.0.0"; + + @Test + void test() { + var serviceTemplate = new ToscaServiceTemplate(); + serviceTemplate.setName(PfKey.NULL_KEY_NAME); + serviceTemplate.setVersion(PfKey.NULL_KEY_VERSION); + var doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc.toAuthorative()).isNotNull(); + assertThat(doc).isNotEqualByComparingTo(null) + .isEqualByComparingTo(doc); + + var doc2 = new DocToscaServiceTemplate(doc); + assertThat(doc2.toAuthorative()).isNotNull(); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setToscaTopologyTemplate(doc.getToscaTopologyTemplate()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setDataTypes(Map.of(NAME, new ToscaDataType())); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setDataTypes(doc.getDataTypes()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setCapabilityTypes(Map.of(NAME, new ToscaCapabilityType())); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setCapabilityTypes(doc.getCapabilityTypes()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setRelationshipTypes(Map.of(NAME, new ToscaRelationshipType())); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setRelationshipTypes(doc.getRelationshipTypes()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setNodeTypes(Map.of(NAME, new ToscaNodeType())); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setNodeTypes(doc.getNodeTypes()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setPolicyTypes(Map.of(NAME, new ToscaPolicyType())); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + 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"); + doc.fromAuthorative(serviceTemplate); + assertThat(doc.toAuthorative()).isNotNull(); + } + + @Test + void testToscaDataType() { + var serviceTemplate = new ToscaServiceTemplate(); + var dataType = new ToscaDataType(); + serviceTemplate.setDataTypes(Map.of(NAME, dataType)); + var toscaConstraint = new ToscaConstraint(); + toscaConstraint.setRangeValues(List.of("value")); + toscaConstraint.setValidValues(List.of("value")); + var doc = new DocToscaServiceTemplate(serviceTemplate); + var doc2 = new DocToscaServiceTemplate(doc); + + dataType.setConstraints(List.of(toscaConstraint)); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setDataTypes(Map.of(NAME_VERSION, doc.getDataTypes().get(NAME_VERSION))); + assertThat(doc).isEqualByComparingTo(doc2); + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + + var property = new ToscaProperty(); + property.setType("type"); + dataType.setProperties(Map.of(NAME, property)); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + } + + @Test + void testDocToscaEntity() { + var serviceTemplate = new ToscaServiceTemplate(); + var doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc.getType()).isNull(); + assertThat(doc.getTypeVersion()).isNull(); + assertThat(doc.getDefinedName()).isEqualTo("tosca"); + assertThat(doc.getDefinedVersion()).isEqualTo("1.0.0"); + + serviceTemplate.setDerivedFrom(NAME); + var doc2 = new DocToscaServiceTemplate(doc); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setDerivedFrom(doc.getDerivedFrom()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setDescription("Description"); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setDescription(doc.getDescription()); + assertThat(doc).isEqualByComparingTo(doc2); + + serviceTemplate.setMetadata(Map.of("key", "value")); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setMetadata(doc.getMetadata()); + assertThat(doc).isEqualByComparingTo(doc2); + + var d = new DocToscaEntity(); + var result = doc.compareTo(d); + assertThat(result).isNotZero(); + } + + @Test + void testDocToscaNodeType() { + var serviceTemplate = new ToscaServiceTemplate(); + var nodeType = new ToscaNodeType(); + serviceTemplate.setNodeTypes(Map.of(NAME, nodeType)); + var doc = new DocToscaServiceTemplate(serviceTemplate); + var doc2 = new DocToscaServiceTemplate(doc); + var docNodeType = doc.getNodeTypes().get(NAME_VERSION); + doc2.setNodeTypes(Map.of(NAME_VERSION, docNodeType)); + assertThat(doc).isEqualByComparingTo(doc2); + + var requirement = new ToscaRequirement(); + requirement.setType(NAME); + requirement.setTypeVersion("1.0.0"); + nodeType.setRequirements(List.of(Map.of(NAME, requirement))); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + docNodeType = doc.getNodeTypes().get(NAME_VERSION); + doc2.getNodeTypes().get(NAME_VERSION).setRequirements(docNodeType.getRequirements()); + assertThat(doc).isEqualByComparingTo(doc2); + + var docRequirement = docNodeType.getRequirements().get(0).get(NAME_VERSION); + assertThat(docRequirement) + .isNotEqualByComparingTo(null) + .isEqualByComparingTo(docRequirement); + + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + doc2 = new DocToscaServiceTemplate(doc); + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + } + + @Test + void testDocToscaProperty() { + var serviceTemplate = new ToscaServiceTemplate(); + var property = new ToscaProperty(); + property.setType("type"); + var nodeType = new ToscaNodeType(); + nodeType.setProperties(Map.of(NAME, property)); + serviceTemplate.setNodeTypes(Map.of(NAME, nodeType)); + var doc = new DocToscaServiceTemplate(serviceTemplate); + var doc2 = new DocToscaServiceTemplate(doc); + + property.setDescription("Description"); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + var docNodeType = doc2.getNodeTypes().get(NAME_VERSION); + var docProperty = docNodeType.getProperties().get(NAME); + docProperty.setDescription(property.getDescription()); + assertThat(doc).isEqualByComparingTo(doc2); + + property.setRequired(true); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + docProperty.setRequired(property.isRequired()); + assertThat(doc).isEqualByComparingTo(doc2); + + property.setDefaultValue("Default"); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + docProperty.setDefaultValue(property.getDefaultValue()); + assertThat(doc).isEqualByComparingTo(doc2); + + property.setStatus(ToscaProperty.Status.SUPPORTED); + doc = new DocToscaServiceTemplate(serviceTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + docProperty.setStatus(property.getStatus()); + assertThat(doc).isEqualByComparingTo(doc2); + } + + @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/document/concepts/DocToscaTopologyTemplateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplateTest.java new file mode 100644 index 000000000..40611ff0e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaTopologyTemplateTest.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 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.clamp.models.acm.document.concepts; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; + +class DocToscaTopologyTemplateTest { + + private static final String NAME = "name"; + + @Test + void testToscaTopologyTemplate() { + var topologyTemplate = new ToscaTopologyTemplate(); + var doc = new DocToscaTopologyTemplate(topologyTemplate); + assertThat(doc) + .isNotEqualByComparingTo(null) + .isEqualByComparingTo(doc); + var doc2 = new DocToscaTopologyTemplate(doc); + assertThat(doc).isEqualByComparingTo(doc2); + + var nodeTemplate = new ToscaNodeTemplate(); + nodeTemplate.setType("type"); + nodeTemplate.setTypeVersion("1.0.0"); + topologyTemplate.setNodeTemplates(Map.of(NAME, nodeTemplate)); + doc = new DocToscaTopologyTemplate(topologyTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setNodeTemplates(doc.getNodeTemplates()); + assertThat(doc).isEqualByComparingTo(doc2); + + var toscaPolicy = new ToscaPolicy(); + toscaPolicy.setType("type"); + toscaPolicy.setTypeVersion("1.0.0"); + topologyTemplate.setPolicies(List.of(Map.of(NAME, toscaPolicy))); + doc = new DocToscaTopologyTemplate(topologyTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setPolicies(doc.getPolicies()); + assertThat(doc).isEqualByComparingTo(doc2); + + topologyTemplate.setInputs(Map.of(NAME, new ToscaParameter())); + doc = new DocToscaTopologyTemplate(topologyTemplate); + assertThat(doc).isNotEqualByComparingTo(doc2); + doc2.setInputs(doc.getInputs()); + assertThat(doc).isEqualByComparingTo(doc2); + var docParameter = doc.getInputs().get(NAME); + assertThat(docParameter) + .isNotEqualByComparingTo(null) + .isEqualByComparingTo(docParameter); + + doc2 = new DocToscaTopologyTemplate(doc); + assertThat(doc.toAuthorative()).isEqualTo(doc2.toAuthorative()); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/PropertiesUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/PropertiesUpdateTest.java new file mode 100644 index 000000000..7ad2cfb85 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/PropertiesUpdateTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 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.clamp.models.acm.messages.kafka.participant; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; +import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class PropertiesUpdateTest { + + @Test + void testCopyConstructor() throws CoderException { + var acElement = new AcElementDeploy(); + acElement.setId(UUID.randomUUID()); + var id = new ToscaConceptIdentifier("id", "1.2.3"); + acElement.setDefinition(id); + var participantDeploy = new ParticipantDeploy(); + participantDeploy.setParticipantId(CommonTestData.getParticipantId()); + participantDeploy.setAcElementList(List.of(acElement)); + var orig = new PropertiesUpdate(); + orig.setParticipantUpdatesList(List.of(participantDeploy)); + orig.setCompositionId(UUID.randomUUID()); + orig.setRevisionIdComposition(UUID.randomUUID()); + orig.setAutomationCompositionId(UUID.randomUUID()); + orig.setRevisionIdInstance(UUID.randomUUID()); + + var other = new PropertiesUpdate(orig); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + assertSerializable(orig, PropertiesUpdate.class); + } +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java index 1c6c3a75c..8f13c2dd8 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3.java @@ -45,4 +45,10 @@ public abstract class AcElementListenerV3 extends AcElementListenerV4 instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Prepare completed"); } + + @Override + public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement, int nextStage) + throws PfModelException { + prepare(compositionElement, instanceElement); + } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java index 4856d03bf..273d8aa4a 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV3Test.java @@ -158,7 +158,7 @@ class AcElementListenerV3Test { var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of()); var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of()); - acElementListener.prepare(compositionElement, instanceElement); + acElementListener.prepare(compositionElement, instanceElement, 0); verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Prepare completed"); diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java index 5d602fba0..cb42e4c12 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java @@ -277,4 +277,19 @@ class ParticipantIntermediaryApiImplTest { result = apiImpl.getRollbackNextStage(compositionElementTarget, 0); assertEquals(0, result); } + + @Test + void testGetPrepareNextStage() { + var cacheProvider = mock(CacheProvider.class); + var automationCompositionHandler = mock(AutomationCompositionOutHandler.class); + var apiImpl = new ParticipantIntermediaryApiImpl(automationCompositionHandler, cacheProvider); + var prepare = Map.of("prepare", List.of(0, 2)); + Map stageSet = Map.of("stage", prepare); + var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), + stageSet, Map.of()); + var result = apiImpl.getPrepareNextStage(compositionElementTarget, 0); + assertEquals(2, result); + result = apiImpl.getPrepareNextStage(compositionElementTarget, 2); + assertEquals(2, result); + } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/MsgExecutorTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/MsgExecutorTest.java index 0a7fcb419..c12b40f92 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/MsgExecutorTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/MsgExecutorTest.java @@ -79,7 +79,7 @@ class MsgExecutorTest { CommonTestData.createAutomationCompositionElementDefinitionList(automationComposition); cacheProvider.addElementDefinition(compositionId, definitions, revisionIdComposition); msgExecutor.check(); - verify(automationCompositionHandler, timeout(100)).handleAutomationCompositionDeploy(updateMsg); + verify(automationCompositionHandler, timeout(200)).handleAutomationCompositionDeploy(updateMsg); assertThat(cacheProvider.getMessagesOnHold()).isEmpty(); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java index 776499a36..6568cd65d 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -53,6 +53,7 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMe import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegisterAck; +import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantReqSync; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.utils.AcmUtils; @@ -372,4 +373,13 @@ class SupervisionMessagesTest { acStateChangeAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck); verify(supervisionHandler).handleAutomationCompositionStateChangeAckMessage(automationCompositionAck); } + + @Test + void testParticipantReqSyncListener() { + final var participantReqSync = new ParticipantReqSync(); + var supervisionParticipantHandler = mock(SupervisionParticipantHandler.class); + var reqSyncListener = new ParticipantReqSyncListener(supervisionParticipantHandler); + reqSyncListener.onTopicEvent(INFRA, TOPIC, null, participantReqSync); + verify(supervisionParticipantHandler).handleParticipantReqSync(participantReqSync); + } } -- 2.16.6