diff options
Diffstat (limited to 'runtime-acm/src/test')
9 files changed, 139 insertions, 258 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 0a46bc6b8..019d53c0b 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 @@ -33,17 +33,13 @@ import java.util.Optional; import java.util.UUID; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -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; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; 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.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; @@ -56,13 +52,13 @@ class AutomationCompositionInstantiationProviderTest { private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json"; private static final String AC_INSTANTIATION_UPDATE_JSON = "src/test/resources/rest/acm/AutomationCompositionUpdate.json"; - private static final String AC_INSTANTIATION_CHANGE_STATE_JSON = "src/test/resources/rest/acm/PassiveCommand.json"; + private static final String AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON = "src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json"; private static final String AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON = "src/test/resources/rest/acm/AutomationCompositionNotFound.json"; private static final String DELETE_BAD_REQUEST = "Automation composition state is still %s"; - 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" @@ -86,18 +82,13 @@ class AutomationCompositionInstantiationProviderTest { @Test void testInstantiationCrud() throws AutomationCompositionException { - var participantProvider = Mockito.mock(ParticipantProvider.class); - var participants = CommonTestData.createParticipants(); - when(participantProvider.getParticipants()).thenReturn(participants); - var acDefinitionProvider = mock(AcDefinitionProvider.class); 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, - participantProvider, acDefinitionProvider); + var instantiationProvider = + new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null); var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); automationCompositionCreate.setCompositionId(compositionId); @@ -132,15 +123,6 @@ class AutomationCompositionInstantiationProviderTest { verify(acProvider).updateAutomationComposition(automationCompositionUpdate); - var instantiationCommand = - InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON); - instantiationProvider.issueAutomationCompositionCommand(automationCompositionUpdate, - instantiationCommand); - verify(supervisionHandler).triggerAutomationCompositionSupervision(automationCompositionUpdate); - - // in order to delete a automationComposition the state must be UNINITIALISED - automationCompositionCreate.setState(AutomationCompositionState.UNINITIALISED); - when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getInstanceId())) .thenReturn(automationCompositionUpdate); instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getCompositionId(), @@ -154,13 +136,11 @@ class AutomationCompositionInstantiationProviderTest { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete"); - var participantProvider = Mockito.mock(ParticipantProvider.class); var acProvider = mock(AutomationCompositionProvider.class); - var supervisionHandler = mock(SupervisionHandler.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, - participantProvider, acDefinitionProvider); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, + acDefinitionProvider, null); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -185,13 +165,11 @@ class AutomationCompositionInstantiationProviderTest { private void assertThatDeleteThrownBy(AutomationComposition automationComposition, AutomationCompositionState state) { automationComposition.setState(state); - var participantProvider = Mockito.mock(ParticipantProvider.class); var acProvider = mock(AutomationCompositionProvider.class); - var supervisionHandler = mock(SupervisionHandler.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, - participantProvider, acDefinitionProvider); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, + acDefinitionProvider, null); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -218,11 +196,8 @@ class AutomationCompositionInstantiationProviderTest { when(acProvider.createAutomationComposition(automationCompositionCreate)) .thenReturn(automationCompositionCreate); - var participantProvider = Mockito.mock(ParticipantProvider.class); - var supervisionHandler = mock(SupervisionHandler.class); - - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, - participantProvider, acDefinitionProvider); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, + acDefinitionProvider, null); var instantiationResponse = instantiationProvider.createAutomationComposition( automationCompositionCreate.getCompositionId(), automationCompositionCreate); @@ -247,10 +222,8 @@ class AutomationCompositionInstantiationProviderTest { automationComposition.setCompositionId(compositionId); var acProvider = mock(AutomationCompositionProvider.class); - var participantProvider = mock(ParticipantProvider.class); - var supervisionHandler = mock(SupervisionHandler.class); - var provider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, - participantProvider, acDefinitionProvider); + var provider = new AutomationCompositionInstantiationProvider(acProvider, + acDefinitionProvider, null); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND); @@ -267,14 +240,12 @@ class AutomationCompositionInstantiationProviderTest { var automationComposition = InstantiationUtils .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); - var participantProvider = Mockito.mock(ParticipantProvider.class); var acProvider = mock(AutomationCompositionProvider.class); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); - var supervisionHandler = mock(SupervisionHandler.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); - var provider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, - participantProvider, acDefinitionProvider); + var provider = new AutomationCompositionInstantiationProvider(acProvider, + acDefinitionProvider, null); var compositionId = automationComposition.getCompositionId(); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) @@ -290,21 +261,4 @@ class AutomationCompositionInstantiationProviderTest { assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, automationComposition)) .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId); } - - @Test - void testIssueAutomationCompositionCommand_OrderedStateInvalid() { - var participantProvider = Mockito.mock(ParticipantProvider.class); - var acProvider = mock(AutomationCompositionProvider.class); - var supervisionHandler = mock(SupervisionHandler.class); - var acDefinitionProvider = mock(AcDefinitionProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, - participantProvider, acDefinitionProvider); - var automationComposition = InstantiationUtils - .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound"); - when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) - .thenReturn(automationComposition); - - assertThatThrownBy(() -> instantiationProvider.issueAutomationCompositionCommand(automationComposition, - new InstantiationCommand())).hasMessageMatching(ORDERED_STATE_INVALID); - } } 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 38db863c3..fe0a477f9 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 @@ -30,10 +30,8 @@ import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVIC import java.util.UUID; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Response; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.runtime.instantiation.AutomationCompositionInstantiationProvider; @@ -41,14 +39,13 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.main.rest.InstantiationController; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; +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.AutomationCompositions; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; 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.persistence.repository.AutomationCompositionRepository; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -74,10 +71,6 @@ class InstantiationControllerTest extends CommonRestController { private static final String INSTANTIATION_ENDPOINT = "compositions/%s/instances"; private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - private UUID compositionId = UUID.randomUUID(); - - @Autowired - private AutomationCompositionRepository automationCompositionRepository; @Autowired private AcDefinitionProvider acDefinitionProvider; @@ -85,9 +78,6 @@ class InstantiationControllerTest extends CommonRestController { @Autowired private AutomationCompositionInstantiationProvider instantiationProvider; - @Autowired - private ParticipantProvider participantProvider; - @LocalServerPort private int randomServerPort; @@ -97,25 +87,15 @@ class InstantiationControllerTest extends CommonRestController { } @BeforeEach - public void populateDb() { - createEntryInDB(); - } - - @BeforeEach public void setUpPort() { super.setHttpPrefix(randomServerPort); } - @AfterEach - public void cleanDatabase() { - deleteEntryInDB(); - } - - private String getInstanceEndPoint() { + private String getInstanceEndPoint(UUID compositionId) { return String.format(INSTANTIATION_ENDPOINT, compositionId.toString()); } - private String getInstanceEndPoint(UUID instanceId) { + private String getInstanceEndPoint(UUID compositionId, UUID instanceId) { return String.format(INSTANTIATION_ENDPOINT, compositionId.toString()) + "/" + instanceId; } @@ -129,12 +109,12 @@ class InstantiationControllerTest extends CommonRestController { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Unauthorized"); - assertUnauthorizedPost(getInstanceEndPoint(), Entity.json(automationComposition)); + assertUnauthorizedPost(getInstanceEndPoint(UUID.randomUUID()), Entity.json(automationComposition)); } @Test void testQuery_Unauthorized() { - assertUnauthorizedGet(getInstanceEndPoint()); + assertUnauthorizedGet(getInstanceEndPoint(UUID.randomUUID())); } @Test @@ -142,42 +122,45 @@ class InstantiationControllerTest extends CommonRestController { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Unauthorized"); - assertUnauthorizedPut(getInstanceEndPoint(), Entity.json(automationComposition)); + assertUnauthorizedPut(getInstanceEndPoint(UUID.randomUUID()), Entity.json(automationComposition)); } @Test void testDelete_Unauthorized() { - assertUnauthorizedDelete(getInstanceEndPoint()); + assertUnauthorizedDelete(getInstanceEndPoint(UUID.randomUUID())); } @Test void testCreate() { + var compositionId = createAcDefinitionInDB("Create"); var automationCompositionFromRsc = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Create"); automationCompositionFromRsc.setCompositionId(compositionId); - var invocationBuilder = super.sendRequest(getInstanceEndPoint()); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId)); var resp = invocationBuilder.post(Entity.json(automationCompositionFromRsc)); assertEquals(Response.Status.CREATED.getStatusCode(), resp.getStatus()); var instResponse = resp.readEntity(InstantiationResponse.class); InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc); automationCompositionFromRsc.setInstanceId(instResponse.getInstanceId()); + automationCompositionFromRsc.getElements().values() + .forEach(element -> element.setParticipantId(CommonTestData.getParticipantId())); var automationCompositionFromDb = instantiationProvider.getAutomationComposition(compositionId, instResponse.getInstanceId()); assertNotNull(automationCompositionFromDb); assertEquals(automationCompositionFromRsc, automationCompositionFromDb); - } @Test void testCreateBadRequest() { + var compositionId = createAcDefinitionInDB("CreateBadRequest"); var automationCompositionFromRsc = InstantiationUtils .getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "CreateBadRequest"); automationCompositionFromRsc.setCompositionId(compositionId); - var invocationBuilder = super.sendRequest(getInstanceEndPoint()); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId)); var resp = invocationBuilder.post(Entity.json(automationCompositionFromRsc)); assertEquals(Response.Status.CREATED.getStatusCode(), resp.getStatus()); @@ -191,7 +174,8 @@ class InstantiationControllerTest extends CommonRestController { @Test void testQuery_NoResultWithThisName() { - var invocationBuilder = super.sendRequest(getInstanceEndPoint() + "?name=noResultWithThisName"); + var invocationBuilder = + super.sendRequest(getInstanceEndPoint(UUID.randomUUID()) + "?name=noResultWithThisName"); var rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); var resp = rawresp.readEntity(AutomationCompositions.class); @@ -200,14 +184,15 @@ class InstantiationControllerTest extends CommonRestController { @Test void testQuery() { + var compositionId = createAcDefinitionInDB("Query"); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Query"); automationComposition.setCompositionId(compositionId); instantiationProvider.createAutomationComposition(compositionId, automationComposition); - var invocationBuilder = - super.sendRequest(getInstanceEndPoint() + "?name=" + automationComposition.getKey().getName()); + var invocationBuilder = super.sendRequest( + getInstanceEndPoint(compositionId) + "?name=" + automationComposition.getKey().getName()); var rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); var automationCompositionsQuery = rawresp.readEntity(AutomationCompositions.class); @@ -217,7 +202,26 @@ class InstantiationControllerTest extends CommonRestController { } @Test + void testGet() { + var compositionId = createAcDefinitionInDB("Get"); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Get"); + automationComposition.setCompositionId(compositionId); + + instantiationProvider.createAutomationComposition(compositionId, automationComposition); + + var invocationBuilder = super.sendRequest( + getInstanceEndPoint(compositionId, automationComposition.getInstanceId())); + var rawresp = invocationBuilder.buildGet().invoke(); + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + var automationCompositionGet = rawresp.readEntity(AutomationComposition.class); + assertNotNull(automationCompositionGet); + assertEquals(automationComposition, automationCompositionGet); + } + + @Test void testUpdate() { + var compositionId = createAcDefinitionInDB("Update"); var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Update"); automationCompositionCreate.setCompositionId(compositionId); @@ -228,7 +232,10 @@ class InstantiationControllerTest extends CommonRestController { InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update"); automationComposition.setCompositionId(compositionId); automationComposition.setInstanceId(response.getInstanceId()); - var invocationBuilder = super.sendRequest(getInstanceEndPoint()); + automationComposition.getElements().values() + .forEach(element -> element.setParticipantId(CommonTestData.getParticipantId())); + + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId)); var resp = invocationBuilder.post(Entity.json(automationComposition)); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); @@ -245,6 +252,7 @@ class InstantiationControllerTest extends CommonRestController { @Test void testDelete() { + var compositionId = createAcDefinitionInDB("Delete"); var automationCompositionFromRsc = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete"); automationCompositionFromRsc.setCompositionId(compositionId); @@ -252,7 +260,7 @@ class InstantiationControllerTest extends CommonRestController { var instResponse = instantiationProvider.createAutomationComposition(compositionId, automationCompositionFromRsc); - var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId())); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId, instResponse.getInstanceId())); var resp = invocationBuilder.delete(); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); instResponse = resp.readEntity(InstantiationResponse.class); @@ -265,30 +273,31 @@ class InstantiationControllerTest extends CommonRestController { @Test void testDeleteNotFound() { + var compositionId = createAcDefinitionInDB("DeleteNotFound"); var automationCompositionFromRsc = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "DelNotFound"); automationCompositionFromRsc.setCompositionId(compositionId); instantiationProvider.createAutomationComposition(compositionId, automationCompositionFromRsc); - var invocationBuilder = super.sendRequest(getInstanceEndPoint(UUID.randomUUID())); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId, UUID.randomUUID())); var resp = invocationBuilder.delete(); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus()); } - @Disabled @Test - void testCommand_NotFound1() { - var invocationBuilder = super.sendRequest(getInstanceEndPoint(UUID.randomUUID())); - var resp = invocationBuilder.post(Entity.json(new AutomationComposition())); + void testDeploy_NotFound() { + var compositionId = createAcDefinitionInDB("Deploy_NotFound"); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId, UUID.randomUUID())); + var resp = invocationBuilder.put(Entity.json(new AcInstanceStateUpdate())); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus()); } - @Disabled @Test - void testCommand_NotFound2() { + void testDeploy_BadRequest() { + var compositionId = createAcDefinitionInDB("Deploy_BadRequest"); var acFromRsc = - InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "DelNotFound"); + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "BadRequest"); acFromRsc.setCompositionId(compositionId); var instResponse = instantiationProvider.createAutomationComposition(compositionId, acFromRsc); @@ -297,50 +306,33 @@ class InstantiationControllerTest extends CommonRestController { command.setDeployOrder(null); command.setLockOrder(null); - var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId())); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId, instResponse.getInstanceId())); var resp = invocationBuilder.put(Entity.json(command)); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); } - @Disabled @Test - void testCommand() throws PfModelException { + void testDeploy() { + var compositionId = createAcDefinitionInDB("Deploy"); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Command"); automationComposition.setCompositionId(compositionId); var instResponse = instantiationProvider.createAutomationComposition(compositionId, automationComposition); - var participants = CommonTestData.createParticipants(); - for (var participant : participants) { - participantProvider.saveParticipant(participant); - } - var instantiationUpdate = new AcInstanceStateUpdate(); + instantiationUpdate.setDeployOrder(DeployOrder.DEPLOY); + instantiationUpdate.setLockOrder(null); - var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId())); + var invocationBuilder = super.sendRequest(getInstanceEndPoint(compositionId, instResponse.getInstanceId())); var resp = invocationBuilder.put(Entity.json(instantiationUpdate)); - assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); - instResponse = resp.readEntity(InstantiationResponse.class); - InstantiationUtils.assertInstantiationResponse(instResponse, automationComposition); - - // check passive state on DB - var toscaConceptIdentifier = instResponse.getAffectedAutomationComposition(); - var automationCompositionsGet = instantiationProvider.getAutomationCompositions(compositionId, - toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion()); - assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1); - } - - private synchronized void deleteEntryInDB() { - automationCompositionRepository.deleteAll(); - var list = acDefinitionProvider.findAcDefinition(compositionId); - if (!list.isEmpty()) { - acDefinitionProvider.deleteAcDefintion(compositionId); - } + assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus()); } - private synchronized void createEntryInDB() { - deleteEntryInDB(); - var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate); - compositionId = acmDefinition.getCompositionId(); + private UUID createAcDefinitionInDB(String name) { + var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate); + serviceTemplateCreate.setName(name); + var acmDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + acDefinitionProvider.updateAcDefinition(acmDefinition); + return acmDefinition.getCompositionId(); } } 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 e54cfafa2..0fa15b62d 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 @@ -40,11 +40,13 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionD 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; @@ -214,7 +216,10 @@ class SupervisionHandlerTest { AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); var automationCompositionAckMessage = new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); - automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of()); + 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); @@ -227,7 +232,10 @@ class SupervisionHandlerTest { var automationCompositionAckMessage = new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK); automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId()); - automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of()); + 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, 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 702a93678..69c1302bc 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 @@ -114,6 +114,11 @@ public class CommonTestData { acDefinition.setServiceTemplate(serviceTemplate); var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate); acDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, state)); + if (AcTypeState.PRIMED.equals(state)) { + for (var element : acDefinition.getElementStateMap().values()) { + element.setParticipantId(getParticipantId()); + } + } return acDefinition; } diff --git a/runtime-acm/src/test/resources/rest/acm/AutomationComposition.json b/runtime-acm/src/test/resources/rest/acm/AutomationComposition.json index 77078e6eb..0e6988d9b 100644 --- a/runtime-acm/src/test/resources/rest/acm/AutomationComposition.json +++ b/runtime-acm/src/test/resources/rest/acm/AutomationComposition.json @@ -2,8 +2,8 @@ "name": "PMSHInstance0", "version": "1.0.1", "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40", - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "PMSH automation composition instance 0", "elements": { "709c62b3-8918-41b9-a747-d21eb79c6c20": { @@ -12,13 +12,8 @@ "name": "org.onap.domain.database.PMSH_K8SMicroserviceAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c02", - "participantType": { - "name": "org.onap.policy.clamp.acm.KubernetesParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Automation composition element for the K8S microservice for PMSH" }, "709c62b3-8918-41b9-a747-d21eb79c6c21": { @@ -27,13 +22,8 @@ "name": "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c01", - "participantType": { - "name": "org.onap.policy.clamp.acm.HttpParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Automation composition element for the http requests of PMSH microservice" }, "709c62b3-8918-41b9-a747-d21eb79c6c22": { @@ -42,13 +32,8 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03", - "participantType": { - "name": "org.onap.policy.clamp.acm.PolicyParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Automation composition element for the operational policy for Performance Management Subscription Handling" } } diff --git a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json index 80facb29c..34ee3f69d 100644 --- a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json +++ b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json @@ -2,8 +2,8 @@ "name": "PMSHInstance0", "version": "1.0.1", "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40", - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "PMSH automation composition instance 0", "elements": { "709c62b3-8918-41b9-a747-d21eb79c6c20": { @@ -12,12 +12,8 @@ "name": "org.onap.domain.pmsh.DCAEMicroservice", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "DCAE Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c21": { @@ -26,12 +22,8 @@ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Monitoring Policy Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c22": { @@ -40,12 +32,8 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Operational Policy Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c23": { @@ -54,13 +42,8 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03", - "participantType": { - "name": "org.onap.policy.clamp.acm.PolicyParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "CDS Automation Composition Element for the PMSH instance 0 automation composition" } } diff --git a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionNotFound.json b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionNotFound.json index a17ba399a..9b3664294 100644 --- a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionNotFound.json +++ b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionNotFound.json @@ -2,8 +2,8 @@ "name": "PMSHInstance0", "version": "1.0.1", "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40", - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "PMSH automation composition instance 0", "elements": { "709c62b3-8918-41b9-a747-d21eb79c6c20": { @@ -12,12 +12,8 @@ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "DCAE Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c21": { @@ -26,12 +22,8 @@ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Monitoring Policy Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c22": { @@ -40,12 +32,8 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Operational Policy Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c23": { @@ -54,12 +42,8 @@ "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement", "version": "1.2.3" }, - "participantType": { - "name": "org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant", - "version": "2.2.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "CDS Automation Composition Element for the PMSH instance 0 automation composition" } } diff --git a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionSmoke.json b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionSmoke.json index e66f3f68d..7a226ac92 100644 --- a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionSmoke.json +++ b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionSmoke.json @@ -2,8 +2,8 @@ "name": "PMSHInstance0", "version": "1.0.1", "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40", - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "PMSH automation composition instance 0", "elements": { "709c62b3-8918-41b9-a747-d21eb79c6c20": { @@ -12,13 +12,8 @@ "name": "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c01", - "participantType": { - "name": "org.onap.policy.clamp.acm.HttpParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Http Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c22": { @@ -27,13 +22,8 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03", - "participantType": { - "name": "org.onap.policy.clamp.acm.PolicyParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Operational Policy Automation Composition Element for the PMSH instance 0 automation composition" }, "709c62b3-8918-41b9-a747-d21eb79c6c23": { @@ -42,13 +32,8 @@ "name": "org.onap.domain.database.PMSH_K8SMicroserviceAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c02", - "participantType": { - "name": "org.onap.policy.clamp.acm.KubernetesParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "K8s Automation Composition Element for the PMSH instance 0 automation composition" } } diff --git a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionUpdate.json b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionUpdate.json index d0372a342..37568fb19 100644 --- a/runtime-acm/src/test/resources/rest/acm/AutomationCompositionUpdate.json +++ b/runtime-acm/src/test/resources/rest/acm/AutomationCompositionUpdate.json @@ -2,8 +2,8 @@ "name": "PMSHInstance0", "version": "1.0.1", "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40", - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "PMSH automation composition instance 0", "elements": { "709c62b3-8918-41b9-a747-d21eb79c6c21": { @@ -12,13 +12,8 @@ "name": "org.onap.domain.database.PMSH_K8SMicroserviceAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c02", - "participantType": { - "name": "org.onap.policy.clamp.acm.KubernetesParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Automation composition element for the K8S microservice for PMSH" }, "709c62b3-8918-41b9-a747-d21eb79c6c22": { @@ -27,13 +22,8 @@ "name": "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c01", - "participantType": { - "name": "org.onap.policy.clamp.acm.HttpParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Automation composition element for the operational policy for Performance Management Subscription Handling" }, "709c62b3-8918-41b9-a747-d21eb79c6c23": { @@ -42,13 +32,8 @@ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", "version": "1.2.3" }, - "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03", - "participantType": { - "name": "org.onap.policy.clamp.acm.PolicyParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", + "deployState": "UNDEPLOYED", + "lockState": "NONE", "description": "Operational Policy Automation Composition Element for the PMSH instance 0 automation composition" } } |