summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java/org
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-02-07 11:06:01 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-02-08 11:43:43 +0000
commitc1fce9211058bf91b40415022a819d3b410f711e (patch)
tree17dfdfd8e6f3df63c886c406b091becd727f29e0 /runtime-acm/src/test/java/org
parentf15329432ee82d48d7ead388ba1866ebbba8efd8 (diff)
Implement AC Element Instance Locking and Unlocking on ACM-R
Issue-ID: POLICY-4509 Change-Id: I8bca27cfa2a417314a27e2bec3938b538f05e346 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test/java/org')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java18
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java100
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java260
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java5
5 files changed, 113 insertions, 282 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 019d53c0b..1acaebea6 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -88,7 +88,7 @@ class AutomationCompositionInstantiationProviderTest {
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var acProvider = mock(AutomationCompositionProvider.class);
var instantiationProvider =
- new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null);
+ new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null);
var automationCompositionCreate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationCompositionCreate.setCompositionId(compositionId);
@@ -140,7 +140,7 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
@@ -169,7 +169,7 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
@@ -197,7 +197,7 @@ class AutomationCompositionInstantiationProviderTest {
.thenReturn(automationCompositionCreate);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
var instantiationResponse = instantiationProvider.createAutomationComposition(
automationCompositionCreate.getCompositionId(), automationCompositionCreate);
@@ -223,7 +223,7 @@ class AutomationCompositionInstantiationProviderTest {
var acProvider = mock(AutomationCompositionProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
@@ -245,7 +245,7 @@ class AutomationCompositionInstantiationProviderTest {
.thenReturn(automationComposition);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
var compositionId = automationComposition.getCompositionId();
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
index a5ffacc6a..534762299 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -65,21 +64,6 @@ public class InstantiationUtils {
}
/**
- * Gets InstantiationCommand from Resource.
- *
- * @param path path of the resource
- * @return the InstantiationCommand
- */
- public static InstantiationCommand getInstantiationCommandFromResource(final String path) {
- try {
- return CODER.decode(new File(path), InstantiationCommand.class);
- } catch (CoderException e) {
- fail("Cannot read or decode " + path);
- return null;
- }
- }
-
- /**
* Assert that Instantiation Response contains proper AutomationCompositions.
*
* @param response InstantiationResponse
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
new file mode 100644
index 000000000..e16672d14
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -0,0 +1,100 @@
+/*-
+ * ============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.acm.runtime.supervision;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+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.messages.dmaap.participant.AutomationCompositionDeployAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
+
+class SupervisionAcHandlerTest {
+ private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
+ private static final UUID IDENTIFIER = UUID.randomUUID();
+
+ @Test
+ void testHandleAutomationCompositionStateChangeAckMessage() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
+ .thenReturn(Optional.of(automationComposition));
+
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
+
+ var automationCompositionAckMessage =
+ new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
+ for (var elementEntry : automationComposition.getElements().entrySet()) {
+ var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
+ automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
+ acElementDeployAck);
+ }
+ automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
+
+ handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ }
+
+ @Test
+ void testHandleAutomationCompositionUpdateAckMessage() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
+ .thenReturn(Optional.of(automationComposition));
+
+ var automationCompositionAckMessage =
+ new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
+ for (var elementEntry : automationComposition.getElements().entrySet()) {
+ var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.LOCKED, true, "");
+ automationCompositionAckMessage
+ .setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
+ }
+ automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
+
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
+
+ handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ }
+}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index 0fa15b62d..d4cc5e310 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -20,232 +20,22 @@
package org.onap.policy.clamp.acm.runtime.supervision;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
-import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
-import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
-import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-
class SupervisionHandlerTest {
- private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
- private static final UUID IDENTIFIER = UUID.randomUUID();
-
- @Test
- void testTriggerAutomationCompositionSupervision() throws AutomationCompositionException {
- var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
- var handler = createSupervisionHandlerForTrigger(automationCompositionDeployPublisher);
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionDeployPublisher).send(automationComposition);
- }
-
- @Test
- void testAcUninitialisedToUninitialised() {
- var handler = createSupervisionHandlerForTrigger();
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state UNINITIALISED");
- }
-
- @Test
- void testAcUninitialisedToPassive() throws AutomationCompositionException {
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- automationComposition.setState(AutomationCompositionState.PASSIVE);
- automationComposition.setCompositionId(UUID.randomUUID());
-
- var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
- var acDefinition = new AutomationCompositionDefinition();
- acDefinition.setCompositionId(automationComposition.getCompositionId());
- acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
- when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
-
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
-
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher);
-
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(1));
- }
-
- @Test
- void testAcPassiveToPassive() {
- var handler = createSupervisionHandlerForTrigger();
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.PASSIVE);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state PASSIVE");
- }
-
- @Test
- void testAcTransitioning() {
- var handler = createSupervisionHandlerForTrigger();
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- automationComposition.setState(AutomationCompositionState.PASSIVE2UNINITIALISED);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state "
- + "PASSIVE2UNINITIALISED and transitioning to state UNINITIALISED");
-
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state "
- + "UNINITIALISED2PASSIVE and transitioning to state PASSIVE");
-
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.PASSIVE2RUNNING);
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state "
- + "PASSIVE2RUNNING and transitioning to state RUNNING");
- }
-
- @Test
- void testAcRunningToPassive() throws AutomationCompositionException {
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.RUNNING);
-
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(1));
- }
-
- @Test
- void testAcRunningToRunning() {
- var handler = createSupervisionHandlerForTrigger();
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.RUNNING);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state RUNNING");
- }
-
- @Test
- void testAcRunningToUninitialised() {
- var handler = createSupervisionHandlerForTrigger();
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching(
- "Automation composition can't transition from state UNINITIALISED to state RUNNING");
- }
-
- @Test
- void testAcPassiveToRunning() throws AutomationCompositionException {
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.PASSIVE);
-
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(0));
- }
-
- @Test
- void testHandleAutomationCompositionStateChangeAckMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = createSupervisionHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
- var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- var acElementDeployAck =
- new AcElementDeployAck(AutomationCompositionState.PASSIVE, DeployState.DEPLOYED, true, "");
- automationCompositionAckMessage.setAutomationCompositionResultMap(
- Map.of(UUID.fromString("709c62b3-8918-41b9-a747-d21eb79c6c20"), acElementDeployAck));
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
-
- handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
-
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
- }
-
- @Test
- void testHandleAutomationCompositionUpdateAckMessage() {
- var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
- automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
- var acElementDeployAck =
- new AcElementDeployAck(AutomationCompositionState.PASSIVE, DeployState.DEPLOYED, true, "");
- automationCompositionAckMessage.setAutomationCompositionResultMap(
- Map.of(UUID.fromString("709c62b3-8918-41b9-a747-d21eb79c6c20"), acElementDeployAck));
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = createSupervisionHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
-
- handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
-
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
- }
@Test
void testParticipantPrimeAckNotFound() {
@@ -253,9 +43,7 @@ class SupervisionHandlerTest {
participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId());
participantPrimeAckMessage.setState(ParticipantState.ON_LINE);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
+ var handler = new SupervisionHandler(acDefinitionProvider);
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
@@ -275,9 +63,7 @@ class SupervisionHandlerTest {
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
.thenReturn(Optional.of(acDefinition));
- var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
+ var handler = new SupervisionHandler(acDefinitionProvider);
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
@@ -297,50 +83,10 @@ class SupervisionHandlerTest {
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
.thenReturn(Optional.of(acDefinition));
- var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
+ var handler = new SupervisionHandler(acDefinitionProvider);
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
verify(acDefinitionProvider).updateAcDefinition(any());
}
-
- private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider,
- AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
- AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
- AutomationCompositionOrderedState orderedState, AutomationCompositionState state) {
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
-
- automationComposition.setOrderedState(orderedState);
- automationComposition.setState(state);
- when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
- .thenReturn(Optional.of(automationComposition));
-
- var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
- when(acDefinitionProvider.getServiceTemplateList(any(), any())).thenReturn(List
- .of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML))));
-
- var acDefinition = new AutomationCompositionDefinition();
- acDefinition.setCompositionId(automationComposition.getCompositionId());
- acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
- when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
-
- return new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
- automationCompositionDeployPublisher, automationCompositionStateChangePublisher);
- }
-
- private SupervisionHandler createSupervisionHandlerForTrigger() {
- return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
- }
-
- private SupervisionHandler createSupervisionHandlerForTrigger(
- AutomationCompositionDeployPublisher automationCompositionDeployPublisher) {
-
- return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
- automationCompositionDeployPublisher, mock(AutomationCompositionStateChangePublisher.class));
- }
}
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 c2d4e0ff7..0072a1042 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
@@ -35,6 +35,7 @@ import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
@@ -225,7 +226,7 @@ class SupervisionMessagesTest {
void testAutomationCompositionUpdateAckListener() {
final var automationCompositionAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionAcHandler.class);
var acUpdateAckListener = new AutomationCompositionUpdateAckListener(supervisionHandler);
acUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
verify(supervisionHandler).handleAutomationCompositionUpdateAckMessage(automationCompositionAck);
@@ -235,7 +236,7 @@ class SupervisionMessagesTest {
void testAutomationCompositionStateChangeAckListener() {
final var automationCompositionAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionAcHandler.class);
var acStateChangeAckListener = new AutomationCompositionStateChangeAckListener(supervisionHandler);
acStateChangeAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
verify(supervisionHandler).handleAutomationCompositionStateChangeAckMessage(automationCompositionAck);