2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.manualhandling.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
29 import java.util.HashMap;
31 import org.camunda.bpm.engine.ProcessEngineServices;
32 import org.camunda.bpm.engine.TaskService;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.camunda.bpm.engine.delegate.DelegateTask;
35 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.onap.so.bpmn.BaseTaskTest;
41 import org.onap.so.db.request.beans.InfraActiveRequests;
43 public class ManualHandlingTasksTest extends BaseTaskTest {
45 protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
48 TaskService taskService;
51 private DelegateExecution mockExecution;
54 ProcessEngineServices processEngineServices;
57 private DelegateTask task;
59 private DelegateExecution delegateExecution;
62 public void before() throws Exception {
63 delegateExecution = new DelegateExecutionFake();
67 public void setFalloutTaskVariables_Test() {
68 when(task.getId()).thenReturn("taskId");
69 when(task.getExecution()).thenReturn(mockExecution);
70 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
71 when(processEngineServices.getTaskService()).thenReturn(taskService);
72 manualHandlingTasks.setFalloutTaskVariables(task);
73 verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
77 public void setPauseTaskVariables_Test() {
78 when(task.getId()).thenReturn("taskId");
79 when(task.getExecution()).thenReturn(mockExecution);
80 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
81 when(processEngineServices.getTaskService()).thenReturn(taskService);
82 manualHandlingTasks.setPauseTaskVariables(task);
83 verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
87 public void completeTask_Test() throws Exception {
88 when(task.getId()).thenReturn("taskId");
89 when(task.getExecution()).thenReturn(mockExecution);
90 Map<String, Object> taskVariables = new HashMap<String, Object>();
91 taskVariables.put("responseValue", "resume");
92 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
93 when(processEngineServices.getTaskService()).thenReturn(taskService);
94 when(taskService.getVariables(any(String.class))).thenReturn(taskVariables);
95 manualHandlingTasks.completeTask(task);
96 verify(mockExecution, times(1)).setVariable("responseValueTask", "Resume");
100 public void updateRequestDbStatus_Test() throws Exception {
101 InfraActiveRequests mockedRequest = new InfraActiveRequests();
102 delegateExecution.setVariable("msoRequestId", "testMsoRequestId");
103 when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
104 doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
105 manualHandlingTasks.updateRequestDbStatus(delegateExecution, "IN_PROGRESS");
106 verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
107 assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS");
111 public void createExternalTicket_Test() throws Exception {
112 delegateExecution.setVariable("msoRequestId", ("testMsoRequestId"));
113 delegateExecution.setVariable("vnfType", "testVnfType");
114 manualHandlingTasks.createExternalTicket(delegateExecution);