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.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.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;
30 import org.camunda.bpm.engine.ProcessEngineServices;
31 import org.camunda.bpm.engine.RuntimeService;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.InOrder;
38 public class InformDmaapClientTest {
41 informDmaapClient = new InformDmaapClient();
42 dmaapClientTest = new DmaapClientTestImpl();
43 informDmaapClient.setDmaapClient(dmaapClientTest);
44 delegateExecution = mockDelegateExecution();
47 private InformDmaapClient informDmaapClient;
49 private DmaapClientTestImpl dmaapClientTest;
51 private DelegateExecution delegateExecution;
53 private MessageCorrelationBuilder messageCorrelationBuilder;
56 public void shouldSendListenerToDmaapClient() {
58 informDmaapClient.execute(delegateExecution);
60 assertThat(dmaapClientTest.getPnfCorrelationId()).isEqualTo("testPnfCorrelationId");
61 assertThat(dmaapClientTest.getInformConsumer()).isNotNull();
62 verifyZeroInteractions(messageCorrelationBuilder);
66 public void shouldSendListenerToDmaapClientAndSendMessageToCamunda() {
68 informDmaapClient.execute(delegateExecution);
69 dmaapClientTest.getInformConsumer().run();
71 assertThat(dmaapClientTest.getPnfCorrelationId()).isEqualTo("testPnfCorrelationId");
72 InOrder inOrder = inOrder(messageCorrelationBuilder);
73 inOrder.verify(messageCorrelationBuilder).processInstanceBusinessKey("testBusinessKey");
74 inOrder.verify(messageCorrelationBuilder).correlateWithResult();
77 private DelegateExecution mockDelegateExecution() {
78 DelegateExecution delegateExecution = mock(DelegateExecution.class);
79 when(delegateExecution.getVariable(eq(ExecutionVariableNames.PNF_CORRELATION_ID)))
80 .thenReturn("testPnfCorrelationId");
81 when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey");
82 ProcessEngineServices processEngineServices = mock(ProcessEngineServices.class);
83 when(delegateExecution.getProcessEngineServices()).thenReturn(processEngineServices);
84 RuntimeService runtimeService = mock(RuntimeService.class);
85 when(processEngineServices.getRuntimeService()).thenReturn(runtimeService);
86 messageCorrelationBuilder = mock(MessageCorrelationBuilder.class);
87 when(runtimeService.createMessageCorrelation(any())).thenReturn(messageCorrelationBuilder);
88 when(messageCorrelationBuilder.processInstanceBusinessKey(any())).thenReturn(messageCorrelationBuilder);
89 return delegateExecution;