Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / pnf / delegate / InformDmaapClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
22
23 import org.camunda.bpm.engine.ProcessEngineServices;
24 import org.camunda.bpm.engine.RuntimeService;
25 import org.camunda.bpm.engine.delegate.DelegateExecution;
26 import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.InOrder;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.mockito.ArgumentMatchers.any;
32 import static org.mockito.ArgumentMatchers.eq;
33 import static org.mockito.Mockito.*;
34
35 public class InformDmaapClientTest {
36     @Before
37     public void setUp() throws Exception {
38         informDmaapClient = new InformDmaapClient();
39         dmaapClientTest = new DmaapClientTestImpl();
40         informDmaapClient.setDmaapClient(dmaapClientTest);
41         delegateExecution = mockDelegateExecution();
42     }
43
44     private InformDmaapClient informDmaapClient;
45
46     private DmaapClientTestImpl dmaapClientTest;
47
48     private DelegateExecution delegateExecution;
49
50     private MessageCorrelationBuilder messageCorrelationBuilder;
51
52     @Test
53     public void shouldSendListenerToDmaapClient() throws Exception {
54         // when
55         informDmaapClient.execute(delegateExecution);
56         // then
57         assertThat(dmaapClientTest.getPnfCorrelationId()).isEqualTo("testPnfCorrelationId");
58         assertThat(dmaapClientTest.getInformConsumer()).isNotNull();
59         verifyZeroInteractions(messageCorrelationBuilder);
60     }
61
62     @Test
63     public void shouldSendListenerToDmaapClientAndSendMessageToCamunda() throws Exception {
64         // when
65         informDmaapClient.execute(delegateExecution);
66         dmaapClientTest.getInformConsumer().run();
67         // then
68         assertThat(dmaapClientTest.getPnfCorrelationId()).isEqualTo("testPnfCorrelationId");
69         InOrder inOrder = inOrder(messageCorrelationBuilder);
70         inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey");
71         inOrder.verify(messageCorrelationBuilder).correlateWithResult();
72     }
73
74     private DelegateExecution mockDelegateExecution() {
75         DelegateExecution delegateExecution = mock(DelegateExecution.class);
76         when(delegateExecution.getVariable(eq(ExecutionVariableNames.PNF_CORRELATION_ID)))
77                 .thenReturn("testPnfCorrelationId");
78         when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey");
79         ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class);
80         when(delegateExecution.getProcessEngineServices()).thenReturn(processEngineServices);
81         RuntimeService runtimeService = mock(RuntimeService.class);
82         when(processEngineServices.getRuntimeService()).thenReturn(runtimeService);
83         messageCorrelationBuilder = mock(MessageCorrelationBuilder.class);
84         when(runtimeService.createMessageCorrelation(any())).thenReturn(messageCorrelationBuilder);
85         when(messageCorrelationBuilder.processInstanceBusinessKey(any())).thenReturn(messageCorrelationBuilder);
86         return delegateExecution;
87     }
88 }