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.mockito.MockitoAnnotations;
41 import org.onap.so.bpmn.BaseTaskTest;
42 import org.onap.so.bpmn.common.BuildingBlockExecution;
43 import org.onap.so.bpmn.common.DelegateExecutionImpl;
44 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
45 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
46 import org.onap.so.client.ticket.ExternalTicket;
47 import org.onap.so.db.request.beans.InfraActiveRequests;
49 public class ManualHandlingTasksTest extends BaseTaskTest {
51 protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
54 TaskService taskService;
57 private DelegateExecution mockExecution;
60 ProcessEngineServices processEngineServices;
63 private DelegateTask task;
66 private BuildingBlockExecution buildingBlockExecution;
69 private GeneralBuildingBlock generalBuildingBlock;
72 private RequestContext requestContext;
75 private ExternalTicket MOCK_externalTicket;
78 public void before() throws Exception {
79 MockitoAnnotations.initMocks(this);
80 delegateExecution = new DelegateExecutionFake();
81 buildingBlockExecution = new DelegateExecutionImpl(delegateExecution);
82 generalBuildingBlock = new GeneralBuildingBlock();
83 requestContext = new RequestContext();
84 requestContext.setRequestorId("someRequestorId");
85 generalBuildingBlock.setRequestContext(requestContext);
86 buildingBlockExecution.setVariable("mso-request-id", ("testMsoRequestId"));
87 buildingBlockExecution.setVariable("vnfType", "testVnfType");
88 buildingBlockExecution.setVariable("gBBInput", generalBuildingBlock);
89 buildingBlockExecution.setVariable("rainyDayVnfName", "someVnfName");
90 buildingBlockExecution.setVariable("workStep", "someWorkstep");
91 buildingBlockExecution.setVariable("taskTimeout", "PT5M");
95 public void setFalloutTaskVariables_Test() {
96 when(mockExecution.getVariable("gBuildingBlockExecution")).thenReturn(buildingBlockExecution);
97 buildingBlockExecution.setVariable("gBBInput", generalBuildingBlock);
98 when(task.getId()).thenReturn("taskId");
99 when(task.getExecution()).thenReturn(mockExecution);
100 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
101 when(processEngineServices.getTaskService()).thenReturn(taskService);
102 manualHandlingTasks.setFalloutTaskVariables(task);
103 verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
107 public void setPauseTaskVariables_Test() {
108 when(task.getId()).thenReturn("taskId");
109 when(task.getExecution()).thenReturn(mockExecution);
110 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
111 when(processEngineServices.getTaskService()).thenReturn(taskService);
112 manualHandlingTasks.setPauseTaskVariables(task);
113 verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
117 public void completeTask_Test() throws Exception {
118 when(task.getId()).thenReturn("taskId");
119 when(task.getExecution()).thenReturn(mockExecution);
120 Map<String, Object> taskVariables = new HashMap<String, Object>();
121 taskVariables.put("responseValue", "resume");
122 when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
123 when(processEngineServices.getTaskService()).thenReturn(taskService);
124 when(taskService.getVariables(any(String.class))).thenReturn(taskVariables);
125 manualHandlingTasks.completeTask(task);
126 verify(mockExecution, times(1)).setVariable("responseValueTask", "Resume");
130 public void updateRequestDbStatus_Test() throws Exception {
131 InfraActiveRequests mockedRequest = new InfraActiveRequests();
132 when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
133 doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
134 manualHandlingTasks.updateRequestDbStatus(buildingBlockExecution, "IN_PROGRESS");
135 verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
136 assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS");