diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-04-11 10:37:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-04-11 10:37:13 +0000 |
commit | 991d65c35ee2f8aa9857059a0336ab05c39ae118 (patch) | |
tree | 02933fa05d4500e58ebc2ab2e3af968784d2acd4 /bpmn/MSOInfrastructureBPMN/src/test | |
parent | e88ee9a2c2970735222eeeb155eaf4fdfb63698d (diff) | |
parent | 402e5e2cad8320dcfe7bd49cc9724d3071a4224d (diff) |
Merge "Added informing dmaap client in pnf-ready workflow"
Diffstat (limited to 'bpmn/MSOInfrastructureBPMN/src/test')
4 files changed, 150 insertions, 3 deletions
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 @@ <bean id="createAaiEntryWithPnfIdDelegate" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.CreateAaiEntryWithPnfIdDelegate"> <property name="aaiConnection" ref="aaiConnection"/> </bean> + + <bean id="informDmaapClient" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.InformDmaapClient"> + <property name="dmaapClient" ref="dmaapClient"/> + </bean> + + <bean id="dmaapClient" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.DmaapClientTestImpl"/> </beans> |