diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-12-07 16:22:45 +0000 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2022-12-08 10:08:43 +0000 |
commit | a50038a6ed673819b45e9af35eb203e6e24dec99 (patch) | |
tree | 7cd5cf908e5367f03d938bef91fe0778bf0ec436 /runtime-acm/src/test | |
parent | a0ccd552fa1c6ddbef3a1e8d455ce256395ee97a (diff) |
Add instanceId support in AutomationCompositionProvider
As part of the endpoint refactoring of InstantiationController,
AutomationCompositionProvider have to support instanceId
in CRUD operations. InstanceId will be temporary add as normal field
and it will became primary key in next Jira task.
Issue-ID: POLICY-4478
Change-Id: I0f7a1ab7683671403831cffdfe6db37eea569c74
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test')
4 files changed, 34 insertions, 30 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 864179844..115adcb50 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 @@ -45,6 +45,7 @@ import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvide import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; @@ -66,14 +67,13 @@ class AutomationCompositionInstantiationProviderTest { private static final String ORDERED_STATE_INVALID = "ordered state invalid or not specified on command"; private static final String AC_ELEMENT_NAME_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n" - + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n" - + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n" - + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\"" - + " INVALID, Not found\n"; - private static final String AC_DEFINITION_NOT_FOUND = - "\"AutomationComposition\" INVALID, item has status INVALID\n" - + " item \"ServiceTemplate\" value \"\" INVALID," - + " Commissioned automation composition definition not found\n"; + + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n" + + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n" + + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\"" + + " INVALID, Not found\n"; + private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n" + + " item \"ServiceTemplate\" value \"\" INVALID," + + " Commissioned automation composition definition not found\n"; private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); @@ -101,12 +101,13 @@ class AutomationCompositionInstantiationProviderTest { var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); automationCompositionCreate.setCompositionId(compositionId); - when(acProvider.saveAutomationComposition(automationCompositionCreate)).thenReturn(automationCompositionCreate); + when(acProvider.createAutomationComposition(automationCompositionCreate)) + .thenReturn(automationCompositionCreate); var instantiationResponse = instantiationProvider.createAutomationComposition(automationCompositionCreate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionCreate); - verify(acProvider).saveAutomationComposition(automationCompositionCreate); + verify(acProvider).createAutomationComposition(automationCompositionCreate); when(acProvider.getAutomationCompositions(automationCompositionCreate.getName(), automationCompositionCreate.getVersion())).thenReturn(List.of(automationCompositionCreate)); @@ -123,14 +124,12 @@ class AutomationCompositionInstantiationProviderTest { instantiationResponse = instantiationProvider.updateAutomationComposition(automationCompositionUpdate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate); - verify(acProvider).saveAutomationComposition(automationCompositionUpdate); + verify(acProvider).updateAutomationComposition(automationCompositionUpdate); when(acProvider.findAutomationComposition(automationCompositionUpdate.getKey().asIdentifier())) .thenReturn(Optional.of(automationCompositionUpdate)); - when(acProvider.findAutomationComposition(automationCompositionUpdate.getName(), - automationCompositionUpdate.getVersion())).thenReturn(Optional.of(automationCompositionUpdate)); - when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getName(), - automationCompositionUpdate.getVersion())).thenReturn(automationCompositionUpdate); + when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getInstanceId())) + .thenReturn(automationCompositionUpdate); var instantiationCommand = InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud"); @@ -146,8 +145,7 @@ class AutomationCompositionInstantiationProviderTest { instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getName(), automationCompositionCreate.getVersion()); - verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getName(), - automationCompositionCreate.getVersion()); + verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getInstanceId()); } @Test @@ -172,11 +170,13 @@ class AutomationCompositionInstantiationProviderTest { } } automationComposition.setState(AutomationCompositionState.UNINITIALISED); + automationComposition.setInstanceId(UUID.randomUUID()); - when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion())) - .thenReturn(Optional.of(automationComposition)); - when(acProvider.deleteAutomationComposition(automationComposition.getName(), - automationComposition.getVersion())).thenReturn(automationComposition); + when(acProvider.findAutomationComposition( + new ToscaConceptIdentifier(automationComposition.getName(), automationComposition.getVersion()))) + .thenReturn(Optional.of(automationComposition)); + when(acProvider.deleteAutomationComposition(automationComposition.getInstanceId())) + .thenReturn(automationComposition); instantiationProvider.deleteAutomationComposition(automationComposition.getName(), automationComposition.getVersion()); @@ -193,8 +193,8 @@ class AutomationCompositionInstantiationProviderTest { var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, participantProvider, acDefinitionProvider); - when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion())) - .thenReturn(Optional.of(automationComposition)); + var key = new ToscaConceptIdentifier(automationComposition.getName(), automationComposition.getVersion()); + when(acProvider.findAutomationComposition(key)).thenReturn(Optional.of(automationComposition)); assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition.getName(), automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state)); @@ -209,9 +209,11 @@ class AutomationCompositionInstantiationProviderTest { var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates"); automationCompositionCreate.setCompositionId(compositionId); + automationCompositionCreate.setInstanceId(UUID.randomUUID()); var acProvider = mock(AutomationCompositionProvider.class); - when(acProvider.saveAutomationComposition(automationCompositionCreate)).thenReturn(automationCompositionCreate); + when(acProvider.createAutomationComposition(automationCompositionCreate)) + .thenReturn(automationCompositionCreate); var participantProvider = Mockito.mock(ParticipantProvider.class); var supervisionHandler = mock(SupervisionHandler.class); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java index dd6e8f3fc..9c364b2db 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java @@ -166,6 +166,7 @@ class InstantiationControllerTest extends CommonRestController { assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); var instResponse = resp.readEntity(InstantiationResponse.class); InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc); + automationCompositionFromRsc.setInstanceId(instResponse.getInstanceId()); var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions( automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion()); @@ -227,12 +228,13 @@ class InstantiationControllerTest extends CommonRestController { InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Update"); automationCompositionCreate.setCompositionId(compositionId); - instantiationProvider.createAutomationComposition(automationCompositionCreate); + var response = instantiationProvider.createAutomationComposition(automationCompositionCreate); var invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update"); automationComposition.setCompositionId(compositionId); + automationComposition.setInstanceId(response.getInstanceId()); var resp = invocationBuilder.put(Entity.json(automationComposition)); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); 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 cc915003d..3a707cd52 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 @@ -235,7 +235,7 @@ class SupervisionHandlerTest { handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage); - verify(automationCompositionProvider).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -255,7 +255,7 @@ class SupervisionHandlerTest { handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); - verify(automationCompositionProvider).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } @Test diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index 03a0ec59e..1455e9246 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -96,7 +96,7 @@ class SupervisionScannerTest { participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionProvider, times(0)).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -120,7 +120,7 @@ class SupervisionScannerTest { participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionProvider, times(1)).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -148,7 +148,7 @@ class SupervisionScannerTest { supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier()); supervisionScanner.run(true); - verify(automationCompositionProvider, times(0)).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); verify(participantStatusReqPublisher, times(0)).send(any(ToscaConceptIdentifier.class)); } |