2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia.
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.common.workflow.service;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.List;
32 import org.camunda.bpm.engine.RuntimeService;
33 import org.camunda.bpm.engine.impl.ExecutionQueryImpl;
34 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
35 import org.camunda.bpm.engine.runtime.Execution;
36 import org.camunda.bpm.engine.runtime.ExecutionQuery;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
40 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
41 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackSuccess;
42 import org.onap.so.bpmn.core.UrnPropertiesReader;
43 import org.springframework.core.env.Environment;
45 public class CallbackHandlerServiceTest {
47 private static final String METHOD_NAME = "testMethod";
48 private static final String MESSAGE = "testMessage";
49 private static final String EVENT_NAME = "eventNameTest";
50 private static final String MESSAGE_VARIABLE = "messageVarTest";
51 private static final String CORRELATION_VARIABLE = "corrVarTest";
52 private static final String CORRELATION_VALUE = "corrValueTest";
53 private static final String LOG_MARKER = "markerTest";
55 private RuntimeService runtimeServiceMock;
56 private CallbackHandlerService testedObject;
60 runtimeServiceMock = mock(RuntimeService.class);
61 testedObject = new CallbackHandlerService(runtimeServiceMock);
66 public void callbackSuccessful() {
68 mockRuntimeService(new ArrayList<>(Arrays.asList(new ExecutionEntity())));
70 CallbackResult callbackResult = testedObject.handleCallback(METHOD_NAME, MESSAGE, EVENT_NAME, MESSAGE_VARIABLE,
71 CORRELATION_VARIABLE, CORRELATION_VALUE, LOG_MARKER, new HashMap<>());
73 assertThat(callbackResult).isExactlyInstanceOf(CallbackSuccess.class);
77 public void callbackNotSuccessful_noWaitingProcesses() {
79 mockRuntimeService(Collections.emptyList());
81 CallbackResult callbackResult = testedObject.handleCallback(METHOD_NAME, MESSAGE, EVENT_NAME, MESSAGE_VARIABLE,
82 CORRELATION_VARIABLE, CORRELATION_VALUE, LOG_MARKER, new HashMap<>());
84 assertThat(callbackResult).isExactlyInstanceOf(CallbackError.class);
87 private void mockRuntimeService(List<Execution> waitingProcesses) {
88 ExecutionQuery executionQueryMock = mock(ExecutionQueryImpl.class);
89 when(runtimeServiceMock.createExecutionQuery()).thenReturn(executionQueryMock);
90 when(executionQueryMock.messageEventSubscriptionName("eventNameTest")).thenReturn(executionQueryMock);
91 when(executionQueryMock.processVariableValueEquals("corrVarTest", "corrValueTest"))
92 .thenReturn(executionQueryMock);
93 when(executionQueryMock.list()).thenReturn(waitingProcesses);
96 private Environment mockEnvironment() {
97 Environment mockEnvironment = mock(Environment.class);
98 UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader();
99 urnPropertiesReader.setEnvironment(mockEnvironment);
100 when(mockEnvironment.getProperty("mso.correlation.timeout")).thenReturn("1");
101 return mockEnvironment;