2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Matchers.eq;
26 import static org.mockito.Mockito.inOrder;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.verifyZeroInteractions;
29 import static org.mockito.Mockito.when;
31 import org.camunda.bpm.engine.ProcessEngineServices;
32 import org.camunda.bpm.engine.RuntimeService;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.InOrder;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.test.context.junit4.SpringRunner;
42 @RunWith(SpringRunner.class)
43 @SpringBootTest(classes = {InformDmaapClient.class, DmaapClientTestImpl.class})
44 public class InformDmaapClientTest {
47 private InformDmaapClient informDmaapClient;
50 private DmaapClientTestImpl dmaapClientTest;
52 private DelegateExecution delegateExecution;
54 private MessageCorrelationBuilder messageCorrelationBuilder;
57 public void shouldSendListenerToDmaapClient() throws Exception {
59 mockDelegateExecution();
61 informDmaapClient.execute(delegateExecution);
63 assertThat(dmaapClientTest.getCorrelationId()).isEqualTo("testCorrelationId");
64 assertThat(dmaapClientTest.getInformConsumer()).isNotNull();
65 verifyZeroInteractions(messageCorrelationBuilder);
69 public void shouldSendListenerToDmaapClientAndSendMessageToCamunda() throws Exception {
71 mockDelegateExecution();
73 informDmaapClient.execute(delegateExecution);
74 dmaapClientTest.getInformConsumer().run();
76 assertThat(dmaapClientTest.getCorrelationId()).isEqualTo("testCorrelationId");
77 InOrder inOrder = inOrder(messageCorrelationBuilder);
78 inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey");
79 inOrder.verify(messageCorrelationBuilder).correlateWithResult();
82 private void mockDelegateExecution() {
83 delegateExecution = mock(DelegateExecution.class);
84 when(delegateExecution.getVariable(eq(ExecutionVariableNames.CORRELATION_ID))).thenReturn("testCorrelationId");
85 when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey");
86 ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class);
87 when(delegateExecution.getProcessEngineServices()).thenReturn(processEngineServices);
88 RuntimeService runtimeService = mock(RuntimeService.class);
89 when(processEngineServices.getRuntimeService()).thenReturn(runtimeService);
90 messageCorrelationBuilder = mock(MessageCorrelationBuilder.class);
91 when(runtimeService.createMessageCorrelation(any())).thenReturn(messageCorrelationBuilder);
92 when(messageCorrelationBuilder.processInstanceBusinessKey(any())).thenReturn(messageCorrelationBuilder);