From 402e5e2cad8320dcfe7bd49cc9724d3071a4224d Mon Sep 17 00:00:00 2001 From: biniek Date: Tue, 10 Apr 2018 10:48:54 +0200 Subject: Added informing dmaap client in pnf-ready workflow Change-Id: I0d7b610e24da56aad32a9b02b987f98f932456f6 Issue-ID: SO-506 Signed-off-by: biniek --- .../pnf/delegate/InformDmaapClient.java | 45 +++++++ .../pnf/implementation/DmaapClient.java | 26 ++++ .../process/CreateAndActivatePnfResource.bpmn | 139 ++++++++++++--------- .../src/main/webapp/WEB-INF/applicationContext.xml | 5 + .../pnf/delegate/DmaapClientTestImpl.java | 42 +++++++ .../pnf/delegate/InformDmaapClientTest.java | 94 ++++++++++++++ .../bpmn/CreateAndActivatePnfResourceTest.java | 11 +- .../resources/applicationContext_forPnfTesting.xml | 6 + 8 files changed, 307 insertions(+), 61 deletions(-) create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/DmaapClient.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java (limited to 'bpmn') diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java new file mode 100644 index 0000000000..5a8d741a05 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.DmaapClient; +import org.springframework.beans.factory.annotation.Autowired; + +public class InformDmaapClient implements JavaDelegate { + + private DmaapClient dmaapClient; + + @Override + public void execute(DelegateExecution execution) throws Exception { + String correlationId = (String) execution.getVariable(ExecutionVariableNames.CORRELATION_ID); + dmaapClient.registerForUpdate(correlationId, () -> execution.getProcessEngineServices().getRuntimeService() + .createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey(execution.getProcessBusinessKey()) + .correlateWithResult()); + } + + @Autowired + public void setDmaapClient(DmaapClient dmaapClient) { + this.dmaapClient = dmaapClient; + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/DmaapClient.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/DmaapClient.java new file mode 100644 index 0000000000..07e8ada21e --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/DmaapClient.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.implementation; + +public interface DmaapClient { + + void registerForUpdate(String correlationId, Runnable informConsumer); +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn index 262e08689d..7d8863892d 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn @@ -8,6 +8,7 @@ + @@ -34,9 +35,10 @@ SequenceFlow_0j5ksz1 - + + SequenceFlow_0j5ksz1 SequenceFlow_1j4r3zt @@ -61,7 +63,7 @@ SequenceFlow_17s9025 - SequenceFlow_17s9025 + SequenceFlow_1o8od8e SequenceFlow_0p09qgm @@ -74,6 +76,10 @@ SequenceFlow_1kc34bc + + SequenceFlow_17s9025 + SequenceFlow_1o8od8e + - + - + - + - + @@ -114,92 +120,92 @@ - + - + - - + + - + - - - + + + - + - - + + - + - + - + - - + + - + - - + + - + - + - + - + - - + + - + - - + + - + - - + + - + - + - + - + @@ -209,9 +215,9 @@ - + - + @@ -222,43 +228,60 @@ - - + + - + - - + + - + - + - + - - - + + + - + - + - + - + + + + + + + + + + + + + + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml index f46cd065ed..ed1556b05d 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml @@ -14,6 +14,11 @@ + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java new file mode 100644 index 0000000000..1103597157 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.DmaapClient; + +public class DmaapClientTestImpl implements DmaapClient { + private String correlationId; + private Runnable informConsumer; + + @Override + public void registerForUpdate(String correlationId, Runnable informConsumer) { + this.correlationId = correlationId; + this.informConsumer = informConsumer; + } + + public String getCorrelationId() { + return correlationId; + } + + public Runnable getInformConsumer() { + return informConsumer; + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java new file mode 100644 index 0000000000..2bfae461be --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/InformDmaapClientTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.engine.ProcessEngineServices; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InOrder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {InformDmaapClient.class, DmaapClientTestImpl.class}) +public class InformDmaapClientTest { + + @Autowired + private InformDmaapClient informDmaapClient; + + @Autowired + private DmaapClientTestImpl dmaapClientTest; + + private DelegateExecution delegateExecution; + + private MessageCorrelationBuilder messageCorrelationBuilder; + + @Test + public void shouldSendListenerToDmaapClient() throws Exception { + // given + mockDelegateExecution(); + // when + informDmaapClient.execute(delegateExecution); + // then + assertThat(dmaapClientTest.getCorrelationId()).isEqualTo("testCorrelationId"); + assertThat(dmaapClientTest.getInformConsumer()).isNotNull(); + verifyZeroInteractions(messageCorrelationBuilder); + } + + @Test + public void shouldSendListenerToDmaapClientAndSendMessageToCamunda() throws Exception { + // given + mockDelegateExecution(); + // when + informDmaapClient.execute(delegateExecution); + dmaapClientTest.getInformConsumer().run(); + // then + assertThat(dmaapClientTest.getCorrelationId()).isEqualTo("testCorrelationId"); + InOrder inOrder = inOrder(messageCorrelationBuilder); + inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey"); + inOrder.verify(messageCorrelationBuilder).correlateWithResult(); + } + + private void mockDelegateExecution() { + delegateExecution = mock(DelegateExecution.class); + when(delegateExecution.getVariable(eq(ExecutionVariableNames.CORRELATION_ID))).thenReturn("testCorrelationId"); + when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey"); + ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class); + when(delegateExecution.getProcessEngineServices()).thenReturn(processEngineServices); + RuntimeService runtimeService = mock(RuntimeService.class); + when(processEngineServices.getRuntimeService()).thenReturn(runtimeService); + messageCorrelationBuilder = mock(MessageCorrelationBuilder.class); + when(runtimeService.createMessageCorrelation(any())).thenReturn(messageCorrelationBuilder); + when(messageCorrelationBuilder.processInstanceBusinessKey(any())).thenReturn(messageCorrelationBuilder); + } +} \ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java index 88e7d2f4b3..cceb271778 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java @@ -75,7 +75,8 @@ public class CreateAndActivatePnfResourceTest { "CreateAndActivatePnf_StartEvent", "CheckAiiForCorrelationId", "DoesAaiContainInfoAboutPnf", - "DoesAaiContainInfoAboutIp" + "DoesAaiContainInfoAboutIp", + "AaiEntryAlreadyUpToDate" ); } @@ -102,7 +103,9 @@ public class CreateAndActivatePnfResourceTest { "DoesAaiContainInfoAboutPnf", "DoesAaiContainInfoAboutIp", "AaiEntryExists", - "WaitForDmaapPnfReadyNotification" + "InformDmaapClient", + "WaitForDmaapPnfReadyNotification", + "AaiEntryUpdated" ); } @@ -129,7 +132,9 @@ public class CreateAndActivatePnfResourceTest { "DoesAaiContainInfoAboutPnf", "CreateAndActivatePnf_CreateAaiEntry", "AaiEntryExists", - "WaitForDmaapPnfReadyNotification" + "InformDmaapClient", + "WaitForDmaapPnfReadyNotification", + "AaiEntryUpdated" ); assertThat(aaiConnection.getCreated()).containsExactly(ID_WITHOUT_ENTRY); } diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml index b222383c82..6dc3bbf880 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml @@ -56,4 +56,10 @@ + + + + + + -- cgit 1.2.3-korg