From 85751a7d52cc6efbea69c08f71f550ae32c61043 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 27 Jun 2023 16:40:31 +0100 Subject: Add restart publisher to support participant restart scenario in ACM Issue-ID: POLICY-4743 Change-Id: Iecb8b4f5f5bf9be788d3507354f267f73d8c53d8 Signed-off-by: FrancescoFioraEst --- .../dmaap/participant/ParticipantPrimeTest.java | 30 +------- .../dmaap/participant/ParticipantRestartTest.java | 81 ++++++++++++++++++++++ .../clamp/models/acm/utils/AcmUtilsTest.java | 9 +++ .../clamp/models/acm/utils/CommonTestData.java | 22 ++++++ 4 files changed, 113 insertions(+), 29 deletions(-) create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java (limited to 'models/src/test/java/org') diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java index 890fc55ae..859b4224d 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java @@ -29,13 +29,10 @@ import java.time.Instant; import java.util.List; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; 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; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** * Test the copy constructor. @@ -52,21 +49,9 @@ class ParticipantPrimeTest { orig.setMessageId(UUID.randomUUID()); orig.setTimestamp(Instant.ofEpochMilli(3000)); - var toscaServiceTemplate = new ToscaServiceTemplate(); - toscaServiceTemplate.setName("serviceTemplate"); - toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); - toscaServiceTemplate.setDescription("Description of serviceTemplate"); - toscaServiceTemplate.setVersion("1.2.3"); - - var toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - var participantDefinitionUpdate = new ParticipantDefinition(); var type = new ToscaConceptIdentifier("id", "1.2.3"); - var acDefinition = getAcElementDefinition(type); + var acDefinition = CommonTestData.getAcElementDefinition(type); participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); @@ -76,17 +61,4 @@ class ParticipantPrimeTest { assertSerializable(orig, ParticipantPrime.class); } - - private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { - var toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - var acDefinition = new AutomationCompositionElementDefinition(); - acDefinition.setAcElementDefinitionId(id); - acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); - return acDefinition; - } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java new file mode 100644 index 000000000..1ae607ebe --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +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.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; +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 ParticipantRestartTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantRestart(null)).isInstanceOf(NullPointerException.class); + + final var orig = new ParticipantRestart(); + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRestart(orig).toString())); + + orig.setMessageId(UUID.randomUUID()); + orig.setCompositionId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + orig.setParticipantId(CommonTestData.getParticipantId()); + + var participantDefinitionUpdate = new ParticipantDefinition(); + var type = new ToscaConceptIdentifier("id", "1.2.3"); + var acDefinition = CommonTestData.getAcElementDefinition(type); + participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); + orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); + + var acElement = new AcElementDeploy(); + acElement.setId(UUID.randomUUID()); + var id = new ToscaConceptIdentifier("id", "1.2.3"); + acElement.setDefinition(id); + + var acRestart = new ParticipantRestartAc(); + acRestart.setAcElementList(List.of(acElement)); + acRestart.setAutomationCompositionId(UUID.randomUUID()); + acRestart.setDeployState(DeployState.DEPLOYED); + acRestart.setLockState(LockState.LOCKED); + + orig.setAutocompositionList(List.of(acRestart)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRestart(orig).toString())); + + assertSerializable(orig, ParticipantRestart.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java index 046d1b848..7e8f60525 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -183,6 +183,15 @@ class AcmUtilsTest { assertFalse(AcmUtils.isForward(DeployState.UNDEPLOYING, LockState.LOCKED)); } + @Test + void testCreateAcElementDeploy() { + var element = getDummyAutomationComposition().getElements().values().iterator().next(); + var result = AcmUtils.createAcElementDeploy(element, DeployOrder.DEPLOY); + assertEquals(DeployOrder.DEPLOY, result.getOrderedState()); + assertEquals(element.getId(), result.getId()); + assertEquals(element.getDefinition(), result.getDefinition()); + } + private AutomationComposition getDummyAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setCompositionId(UUID.randomUUID()); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java index 21666e484..03a3fb11a 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java @@ -23,9 +23,12 @@ package org.onap.policy.clamp.models.acm.utils; import static org.junit.jupiter.api.Assertions.fail; import java.util.UUID; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** @@ -78,4 +81,23 @@ public class CommonTestData { return null; } } + + /** + * Get new AutomationCompositionElementDefinition. + * + * @param id the ToscaConceptIdentifier + * @return a new AutomationCompositionElementDefinition + */ + public static AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + var acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(id); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + return acDefinition; + } } -- cgit 1.2.3-korg