summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-a1pms/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-impl/participant-impl-a1pms/src/test')
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java135
1 files changed, 110 insertions, 25 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
index a39076697..77f41cb60 100755
--- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
@@ -20,38 +20,35 @@
package org.onap.policy.clamp.acm.participant.a1pms.handler;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Spy;
import org.onap.policy.clamp.acm.participant.a1pms.exception.A1PolicyServiceException;
import org.onap.policy.clamp.acm.participant.a1pms.utils.CommonTestData;
import org.onap.policy.clamp.acm.participant.a1pms.utils.ToscaUtils;
import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+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.StateChangeResult;
+import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-@ExtendWith(SpringExtension.class)
class AcElementHandlerTest {
private final AcA1PmsClient acA1PmsClient = mock(AcA1PmsClient.class);
- @InjectMocks
- @Spy
- private AutomationCompositionElementHandler automationCompositionElementHandler =
- new AutomationCompositionElementHandler(acA1PmsClient);
-
private final CommonTestData commonTestData = new CommonTestData();
private static ToscaServiceTemplate serviceTemplate;
@@ -65,57 +62,145 @@ class AcElementHandlerTest {
@BeforeEach
void startMocks() throws A1PolicyServiceException {
- automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.TRUE);
doNothing().when(acA1PmsClient).createService(any());
}
@Test
void test_automationCompositionElementStateChange() throws A1PolicyServiceException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+
var automationCompositionId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
var automationCompositionElementId = element.getId();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.deploy(
- commonTestData.getAutomationCompositionId(), element,
+ automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(
- automationCompositionId, automationCompositionElementId));
+ automationCompositionElementHandler.undeploy(automationCompositionId, automationCompositionElementId);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
- assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.undeploy(
- automationCompositionId, automationCompositionElementId));
+ assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
+ .undeploy(automationCompositionId, automationCompositionElementId));
}
@Test
- void test_AutomationCompositionElementUpdate() {
+ void test_AutomationCompositionElementUpdate() throws A1PolicyServiceException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
var element = commonTestData.getAutomationCompositionElement();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(
+ commonTestData.getAutomationCompositionId(), element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Deployed");
}
@Test
void test_AutomationCompositionElementUpdateWithUnhealthyA1pms() {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
var element = commonTestData.getAutomationCompositionElement();
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.deploy(
- commonTestData.getAutomationCompositionId(), element,
+ () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
}
@Test
void test_AutomationCompositionElementUpdateWithInvalidConfiguration() {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
var element = commonTestData.getAutomationCompositionElement();
assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
.deploy(commonTestData.getAutomationCompositionId(), element, Map.of()));
}
+
+ @Test
+ void testLock() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ automationCompositionElementHandler.lock(automationCompositionId, elementId);
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
+ null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Test
+ void testUnlock() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ automationCompositionElementHandler.unlock(automationCompositionId, elementId);
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
+ null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Test
+ void testUpdate() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var element = commonTestData.getAutomationCompositionElement();
+ automationCompositionElementHandler.update(automationCompositionId, element, Map.of());
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
+ element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Test
+ void testDelete() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ automationCompositionElementHandler.delete(automationCompositionId, elementId);
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Test
+ void testPrime() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var compositionId = UUID.randomUUID();
+ automationCompositionElementHandler.prime(compositionId, List.of());
+
+ verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Test
+ void testDeprime() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var compositionId = UUID.randomUUID();
+ automationCompositionElementHandler.deprime(compositionId);
+
+ verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+ StateChangeResult.NO_ERROR, "Deprimed");
+ }
}