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;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.List;
31 import org.camunda.bpm.engine.RuntimeService;
32 import org.camunda.bpm.engine.impl.ExecutionQueryImpl;
33 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
34 import org.camunda.bpm.engine.runtime.Execution;
35 import org.camunda.bpm.engine.runtime.ExecutionQuery;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackError;
39 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult;
40 import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackSuccess;
41 import org.onap.so.bpmn.core.UrnPropertiesReader;
42 import org.springframework.core.env.Environment;
44 public class CallbackHandlerServiceTest {
46 private static final String METHOD_NAME = "testMethod";
47 private static final String MESSAGE = "testMessage";
48 private static final String EVENT_NAME = "eventNameTest";
49 private static final String MESSAGE_VARIABLE = "messageVarTest";
50 private static final String CORRELATION_VARIABLE = "corrVarTest";
51 private static final String CORRELATION_VALUE = "corrValueTest";
52 private static final String LOG_MARKER = "markerTest";
54 private RuntimeService runtimeServiceMock;
55 private CallbackHandlerService testedObject;
59 runtimeServiceMock = mock(RuntimeService.class);
60 testedObject = new CallbackHandlerService(runtimeServiceMock);
65 public void callbackSuccessful() {
67 mockRuntimeService(new ArrayList<>(Arrays.asList(new ExecutionEntity())));
69 CallbackResult callbackResult = testedObject.handleCallback(METHOD_NAME, MESSAGE, EVENT_NAME, MESSAGE_VARIABLE,
70 CORRELATION_VARIABLE, CORRELATION_VALUE, LOG_MARKER, new HashMap<>());
72 assertThat(callbackResult).isExactlyInstanceOf(CallbackSuccess.class);
76 public void callbackNotSuccessful_noWaitingProcesses() {
78 mockRuntimeService(Collections.emptyList());
80 CallbackResult callbackResult = testedObject.handleCallback(METHOD_NAME, MESSAGE, EVENT_NAME, MESSAGE_VARIABLE,
81 CORRELATION_VARIABLE, CORRELATION_VALUE, LOG_MARKER, new HashMap<>());
83 assertThat(callbackResult).isExactlyInstanceOf(CallbackError.class);
86 private void mockRuntimeService(List<Execution> waitingProcesses) {
87 ExecutionQuery executionQueryMock = mock(ExecutionQueryImpl.class);
88 when(runtimeServiceMock.createExecutionQuery()).thenReturn(executionQueryMock);
89 when(executionQueryMock.messageEventSubscriptionName("eventNameTest")).thenReturn(executionQueryMock);
90 when(executionQueryMock.processVariableValueEquals("corrVarTest", "corrValueTest"))
91 .thenReturn(executionQueryMock);
92 when(executionQueryMock.list()).thenReturn(waitingProcesses);
95 private Environment mockEnvironment() {
96 Environment mockEnvironment = mock(Environment.class);
97 UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader();
98 urnPropertiesReader.setEnvironment(mockEnvironment);
99 when(mockEnvironment.getProperty("mso.correlation.timeout")).thenReturn("1");
100 return mockEnvironment;