summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java/org
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-26 17:31:46 +0000
committerLiam Fallon <liam.fallon@est.tech>2023-01-30 16:39:27 +0000
commit934f7bd443225a6945b0542fa5cb7c043deac426 (patch)
tree55d490b816af0a50f521ee777f82757f28f9a16e /runtime-acm/src/test/java/org
parenta178851e9f2e148c17d81c29a9310644e0330b9a (diff)
Refactor Prime and Deprime messages in ACM
Issue-ID: POLICY-4502 Change-Id: Ib0ecc513285bf971a0c25cec528dcdeec5ad63a2 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/commissioning/CommissioningProviderTest.java85
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java18
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java100
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java33
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java30
6 files changed, 190 insertions, 88 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index 6ecb8e6f2..071fc26fd 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,13 +33,16 @@ import java.util.List;
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.SupervisionHandler;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantUpdatePublisher;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
+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.Participant;
+import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate;
+import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcTypeStateResolver;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class CommissioningProviderTest {
@@ -51,16 +55,14 @@ class CommissioningProviderTest {
@Test
void testGetAutomationCompositionDefinitions() {
var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
- when(acDefinitionProvider.getServiceTemplateList(null, null))
- .thenReturn(List.of(new ToscaServiceTemplate()));
+ when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(new ToscaServiceTemplate()));
serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
assertThat(serviceTemplates.getServiceTemplates()).hasSize(1);
}
@@ -81,16 +83,11 @@ class CommissioningProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition);
- var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.getParticipants()).thenReturn(List.of(new Participant()));
var acProvider = mock(AutomationCompositionProvider.class);
- var supervisionHandler = mock(SupervisionHandler.class);
- var provider =
- new CommissioningProvider(acDefinitionProvider, acProvider, supervisionHandler, participantProvider);
- var affectedDefinitions = provider
- .createAutomationCompositionDefinition(serviceTemplate).getAffectedAutomationCompositionDefinitions();
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
+ var affectedDefinitions = provider.createAutomationCompositionDefinition(serviceTemplate)
+ .getAffectedAutomationCompositionDefinitions();
verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
- verify(supervisionHandler).handleSendCommissionMessage(acmDefinition);
// Response should return the number of node templates present in the service template
assertThat(affectedDefinitions).hasSize(7);
}
@@ -104,10 +101,8 @@ class CommissioningProviderTest {
void testGetToscaServiceTemplateList() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
- var provider =
- new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
@@ -120,12 +115,11 @@ class CommissioningProviderTest {
void testDeletecDefinitionDabRequest() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
var compositionId = UUID.randomUUID();
when(acProvider.getAcInstancesByCompositionId(compositionId)).thenReturn(List.of(new AutomationComposition()));
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId))
.hasMessageMatching("Delete instances, to commission automation composition definitions");
@@ -133,22 +127,59 @@ class CommissioningProviderTest {
@Test
void testDeleteAutomationCompositionDefinition() {
- var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.getParticipants()).thenReturn(List.of(new Participant()));
-
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var compositionId = UUID.randomUUID();
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
when(acDefinitionProvider.deleteAcDefintion(compositionId)).thenReturn(serviceTemplate);
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(compositionId);
+ acmDefinition.setServiceTemplate(serviceTemplate);
+ acmDefinition.setState(AcTypeState.COMMISSIONED);
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
+
var acProvider = mock(AutomationCompositionProvider.class);
- var supervisionHandler = mock(SupervisionHandler.class);
- var provider =
- new CommissioningProvider(acDefinitionProvider, acProvider, supervisionHandler, participantProvider);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
provider.deleteAutomationCompositionDefinition(compositionId);
- verify(supervisionHandler).handleSendDeCommissionMessage(compositionId);
verify(acDefinitionProvider).deleteAcDefintion(compositionId);
}
+
+ @Test
+ void testPriming() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acmDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.COMMISSIONED);
+ var compositionId = acmDefinition.getCompositionId();
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
+
+ var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
+ var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
+ new AcTypeStateResolver(), participantUpdatePublisher);
+
+ var acTypeStateUpdate = new AcTypeStateUpdate();
+ acTypeStateUpdate.setPrimeOrder(PrimeOrder.PRIME);
+ provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate);
+ verify(acDefinitionProvider).updateAcDefinition(acmDefinition);
+ verify(participantUpdatePublisher).sendPriming(any(), any(), any());
+ }
+
+ @Test
+ void testDepriming() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acmDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMED);
+ var compositionId = acmDefinition.getCompositionId();
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
+
+ var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
+ var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
+ new AcTypeStateResolver(), participantUpdatePublisher);
+
+ var acTypeStateUpdate = new AcTypeStateUpdate();
+ acTypeStateUpdate.setPrimeOrder(PrimeOrder.DEPRIME);
+ provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate);
+ verify(participantUpdatePublisher).sendDepriming(compositionId);
+ }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index 53fa945b2..73f3a687e 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -40,7 +40,9 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
+import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
@@ -207,6 +209,16 @@ class CommissioningControllerTest extends CommonRestController {
assertThat(templatesInDB).isEmpty();
}
+ @Test
+ void testPrimeBadRequest() {
+ var compositionId = createEntryInDB("Prime");
+ var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
+ var body = new AcTypeStateUpdate();
+ body.setPrimeOrder(PrimeOrder.PRIME);
+ var resp = invocationBuilder.put(Entity.json(body));
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ }
+
private UUID createEntryInDB(String name) {
var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate);
serviceTemplateCreate.setName(name);
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 cd6e021c5..0a46bc6b8 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,6 +37,7 @@ import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
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.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
@@ -90,8 +91,9 @@ class AutomationCompositionInstantiationProviderTest {
when(participantProvider.getParticipants()).thenReturn(participants);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var compositionId = UUID.randomUUID();
- when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(serviceTemplate));
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var supervisionHandler = mock(SupervisionHandler.class);
var acProvider = mock(AutomationCompositionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
@@ -203,8 +205,9 @@ class AutomationCompositionInstantiationProviderTest {
@Test
void testCreateAutomationCompositions_NoDuplicates() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var compositionId = UUID.randomUUID();
- when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(serviceTemplate));
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var automationCompositionCreate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates");
@@ -236,8 +239,9 @@ class AutomationCompositionInstantiationProviderTest {
@Test
void testCreateAutomationCompositions_CommissionedAcElementNotFound() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var compositionId = UUID.randomUUID();
- when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(serviceTemplate));
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(
AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "AcElementNotFound");
automationComposition.setCompositionId(compositionId);
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 aa8905917..c6535702b 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,7 +20,6 @@
package org.onap.policy.clamp.acm.runtime.supervision;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -39,9 +38,9 @@ import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionUpdatePublisher;
-import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantUpdatePublisher;
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.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;
@@ -52,7 +51,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-import org.onap.policy.models.base.PfModelException;
+
class SupervisionHandlerTest {
private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
@@ -102,8 +101,7 @@ class SupervisionHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
- mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
- mock(ParticipantUpdatePublisher.class));
+ mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher);
handler.triggerAutomationCompositionSupervision(automationComposition);
@@ -152,8 +150,7 @@ class SupervisionHandlerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
@@ -197,8 +194,7 @@ class SupervisionHandlerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
@@ -215,8 +211,7 @@ class SupervisionHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = createSupervisionHandler(automationCompositionProvider,
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
var automationCompositionAckMessage =
new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of());
@@ -237,8 +232,7 @@ class SupervisionHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = createSupervisionHandler(automationCompositionProvider,
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
@@ -246,48 +240,68 @@ class SupervisionHandlerTest {
}
@Test
- void testParticipantUpdateAck() {
+ void testParticipantUpdateAckNotFound() {
var participantUpdateAckMessage = new ParticipantUpdateAck();
participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId());
participantUpdateAckMessage.setState(ParticipantState.ON_LINE);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
+ mock(AutomationCompositionUpdatePublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
- assertThatCode(() -> handler.handleParticipantMessage(participantUpdateAckMessage)).doesNotThrowAnyException();
+ handler.handleParticipantMessage(participantUpdateAckMessage);
+ verify(acDefinitionProvider).findAcDefinition(any());
}
@Test
- void testHandleSendCommissionMessage() {
- var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
- var acmDefinition = new AutomationCompositionDefinition();
- handler.handleSendCommissionMessage(acmDefinition);
+ void testParticipantUpdateAckPrimed() {
+ var participantUpdateAckMessage = new ParticipantUpdateAck();
+ participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantUpdateAckMessage.setState(ParticipantState.ON_LINE);
+
+ var acDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMED);
+ participantUpdateAckMessage.setCompositionId(acDefinition.getCompositionId());
+
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
+ .thenReturn(Optional.of(acDefinition));
- verify(participantUpdatePublisher).sendComissioningBroadcast(acmDefinition);
+ var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
+ mock(AutomationCompositionUpdatePublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
+
+ handler.handleParticipantMessage(participantUpdateAckMessage);
+ verify(acDefinitionProvider).findAcDefinition(any());
}
@Test
- void testHandleSendDeCommissionMessage() throws PfModelException {
- var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
- handler.handleSendDeCommissionMessage(IDENTIFIER);
+ void testParticipantUpdateAck() {
+ var participantUpdateAckMessage = new ParticipantUpdateAck();
+ participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantUpdateAckMessage.setState(ParticipantState.ON_LINE);
+
+ var acDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING);
+ participantUpdateAckMessage.setCompositionId(acDefinition.getCompositionId());
+
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
+ .thenReturn(Optional.of(acDefinition));
- verify(participantUpdatePublisher).sendDecomisioning(IDENTIFIER);
+ var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
+ mock(AutomationCompositionUpdatePublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
+
+ handler.handleParticipantMessage(participantUpdateAckMessage);
+ verify(acDefinitionProvider).findAcDefinition(any());
+ verify(acDefinitionProvider).updateAcDefinition(any());
}
private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider,
AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher,
AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
- ParticipantUpdatePublisher participantUpdatePublisher, AutomationCompositionOrderedState orderedState,
- AutomationCompositionState state) {
+ AutomationCompositionOrderedState orderedState, AutomationCompositionState state) {
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
@@ -306,21 +320,19 @@ class SupervisionHandlerTest {
when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
return new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
- automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
- participantUpdatePublisher);
+ automationCompositionUpdatePublisher, automationCompositionStateChangePublisher);
}
private SupervisionHandler createSupervisionHandlerForTrigger() {
return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(AutomationCompositionUpdatePublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
}
private SupervisionHandler createSupervisionHandlerForTrigger(
AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher) {
return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
- automationCompositionUpdatePublisher, mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ automationCompositionUpdatePublisher, 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 5ea3bea2c..d558deae3 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
@@ -25,16 +25,20 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.anyString;
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.Collections;
+import java.util.HashMap;
import java.util.List;
+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.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
+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.AutomationCompositionState;
@@ -46,9 +50,11 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
-import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionMessagesTest {
@@ -133,16 +139,28 @@ class SupervisionMessagesTest {
@Test
void testParticipantUpdatePublisherDecomisioning() {
- var publisher = new ParticipantUpdatePublisher(mock(AcDefinitionProvider.class));
+ var publisher = new ParticipantUpdatePublisher(mock(ParticipantProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
- publisher.sendDecomisioning(UUID.randomUUID());
+ publisher.sendDepriming(UUID.randomUUID());
verify(topicSink).send(anyString());
}
@Test
- void testParticipantUpdatePublisherComissioning() {
- var publisher = new ParticipantUpdatePublisher(mock(AcDefinitionProvider.class));
+ void testParticipantUpdatePublisherPriming() {
+ var participantId = UUID.randomUUID();
+ Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>();
+ supportedElementMap.put(
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"),
+ participantId);
+ supportedElementMap.put(new ToscaConceptIdentifier(
+ "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.1"), participantId);
+ supportedElementMap.put(
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"),
+ participantId);
+ var participantProvider = mock(ParticipantProvider.class);
+ when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap);
+ var publisher = new ParticipantUpdatePublisher(participantProvider);
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
@@ -151,7 +169,10 @@ class SupervisionMessagesTest {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
acmDefinition.setServiceTemplate(serviceTemplate);
- publisher.sendComissioningBroadcast(acmDefinition);
+ var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate);
+ acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
+ var preparation = publisher.prepareParticipantPriming(acmDefinition);
+ publisher.sendPriming(preparation, acmDefinition.getCompositionId(), null);
verify(topicSink).send(anyString());
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
index b99140914..702a93678 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
@@ -25,11 +25,15 @@ import java.util.UUID;
import javax.ws.rs.core.Response.Status;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Class to hold/create all parameters for test cases.
@@ -37,8 +41,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
*/
public class CommonTestData {
private static final Coder CODER = new StandardCoder();
- public static final String TOSCA_SERVICE_TEMPLATE_YAML =
- "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
+ public static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
/**
* Gets the standard automation composition parameters.
@@ -53,7 +56,7 @@ public class CommonTestData {
} catch (CoderException e) {
throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE,
- "cannot read automation composition parameters", e);
+ "cannot read automation composition parameters", e);
}
}
@@ -65,7 +68,7 @@ public class CommonTestData {
*/
public static String getParameterGroupAsString(final String dbName) {
return ResourceUtils.getResourceAsString("src/test/resources/parameters/TestParameters.json")
- .replace("${dbName}", "jdbc:h2:mem:" + dbName);
+ .replace("${dbName}", "jdbc:h2:mem:" + dbName);
}
/**
@@ -95,4 +98,23 @@ public class CommonTestData {
public static UUID getParticipantId() {
return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03");
}
+
+ /**
+ * Create a new AutomationCompositionDefinition.
+ *
+ * @param serviceTemplate the serviceTemplate
+ * @param state the AcTypeState
+ * @return a new AutomationCompositionDefinition
+ */
+ public static AutomationCompositionDefinition createAcDefinition(ToscaServiceTemplate serviceTemplate,
+ AcTypeState state) {
+ var acDefinition = new AutomationCompositionDefinition();
+ acDefinition.setCompositionId(UUID.randomUUID());
+ acDefinition.setState(state);
+ acDefinition.setServiceTemplate(serviceTemplate);
+ var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate);
+ acDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, state));
+ return acDefinition;
+ }
+
}