/*-
* ============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.
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.
*
/*-
* ============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.
}
}
- /**
- * 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 <A extends ToscaEntity, R> Map<String, R> listToDocMap(List<Map<String, A>> source,
- Function<A, R> 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.
*
/*-
* ============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.
* @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);
* @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!";
}
private static boolean isTypePresent(String key, Set<String> reference) {
- if (reference == null || reference.isEmpty()) {
+ if (reference.isEmpty()) {
return false;
}
return reference.contains(key);
}
private static boolean isTypePresent(DocConceptKey key, Set<String> reference) {
- if (reference == null || reference.isEmpty()) {
+ if (reference.isEmpty()) {
return false;
}
return reference.contains(key.getId());
* @param result the result of the ancestor search with any warnings or errors
*/
private static void validEntityTypeAncestors(Map<String, ? extends DocToscaEntity<?>> entityTypes,
- Set<String> reference, @NonNull final BeanValidationResult result) {
+ Set<String> reference, final BeanValidationResult result) {
if (entityTypes != null) {
for (var entityType : entityTypes.values()) {
var parentEntityTypeKey = extractDerivedFrom(entityType, result);
* @param result the result of the ancestor search with any warnings or errors
*/
private static <T extends DocToscaEntity<?>> void validEntityTypeAncestors(List<Map<String, T>> entityTypesList,
- Set<String> reference, @NonNull final BeanValidationResult result) {
+ Set<String> reference, final BeanValidationResult result) {
if (entityTypesList != null) {
for (var entityTypes : entityTypesList) {
for (var entityType : entityTypes.values()) {
/*-
* ============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.
@Override
public int compareTo(DocToscaEntity<ToscaCapabilityAssignment> otherConcept) {
- if (this == otherConcept) {
- return 0;
- }
-
int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
/*-
* ============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.
@Override
public int compareTo(DocToscaEntity<ToscaDataType> otherConcept) {
- if (this == otherConcept) {
- return 0;
- }
-
int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
/*-
* ============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.
@Override
public int compareTo(DocToscaEntity<ToscaNodeTemplate> otherConcept) {
- if (this == otherConcept) {
- return 0;
- }
-
int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
/*-
* ============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.
@Override
public int compareTo(DocToscaEntity<ToscaNodeType> otherConcept) {
- if (this == otherConcept) {
- return 0;
- }
-
int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
/*-
* ============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.
this.capability = copyConcept.capability;
this.node = copyConcept.node;
this.relationship = copyConcept.relationship;
- this.occurrences = new ArrayList<>(copyConcept.occurrences);
+ if (copyConcept.occurrences != null) {
+ this.occurrences = new ArrayList<>(copyConcept.occurrences);
+ }
}
@Override
@Override
public int compareTo(DocToscaEntity<ToscaRequirement> otherConcept) {
- if (this == otherConcept) {
- return 0;
- }
-
int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
/*-
* ============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.
.setRelationshipTypes(DocUtil.docMapToMap(relationshipTypes, DocToscaRelationshipType::toAuthorative));
toscaServiceTemplate.setNodeTypes(DocUtil.docMapToMap(nodeTypes, DocToscaNodeType::toAuthorative));
toscaServiceTemplate.setPolicyTypes(DocUtil.docMapToMap(policyTypes, DocToscaPolicyType::toAuthorative));
- toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate.toAuthorative());
+ if (toscaTopologyTemplate != null) {
+ toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate.toAuthorative());
+ }
return toscaServiceTemplate;
}
toscaDefinitionsVersion = toscaServiceTemplate.getToscaDefinitionsVersion();
- dataTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getDataTypes(), DocToscaDataType::new);
+ dataTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getDataTypes(), DocToscaDataType::new,
+ new LinkedHashMap<>());
- 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());
}
/**
- * Compare this service template to another service template, ignoring contained entitites.
+ * Compare this service template to another service template, ignoring contained entities.
*
* @param otherConcept the other topology template
* @return the result of the comparison
*/
public int compareToWithoutEntities(final DocToscaEntity<ToscaServiceTemplate> 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);
}
}
/*-
* ============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.
@Override
public int compareTo(final DocToscaEntity<T> otherConcept) {
- if (this == otherConcept) {
- return 0;
- }
-
int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
--- /dev/null
+/*-
+ * ============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<String, PfNameVersion> map = null;
+ List<Map<String, PfNameVersion>> 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();
+ }
+}
--- /dev/null
+/*-
+ * ============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;
+ }
+}
--- /dev/null
+/*-
+ * ============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());
+ }
+}
--- /dev/null
+/*-
+ * ============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<ToscaServiceTemplate>();
+ 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);
+ }
+}
--- /dev/null
+/*-
+ * ============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());
+ }
+}
--- /dev/null
+/*-
+ * ============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);
+ }
+}
instanceElement.elementId(), DeployState.UNDEPLOYED, null,\r
StateChangeResult.NO_ERROR, "Prepare completed");\r
}\r
+\r
+ @Override\r
+ public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement, int nextStage)\r
+ throws PfModelException {\r
+ prepare(compositionElement, instanceElement);\r
+ }\r
}\r
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");
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<String, Object> 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);
+ }
}
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();
}
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;
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);
+ }
}