f9ad473e5aeac5c8702cf745d970d4fbed5eed7c
[so.git] /
1 package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.mockito.ArgumentMatchers.any;
5 import static org.mockito.Mockito.doNothing;
6 import static org.mockito.Mockito.times;
7 import static org.mockito.Mockito.verify;
8 import static org.mockito.Mockito.when;
9 import java.util.HashMap;
10 import java.util.Map;
11 import org.camunda.bpm.engine.ProcessEngineServices;
12 import org.camunda.bpm.engine.TaskService;
13 import org.camunda.bpm.engine.delegate.DelegateExecution;
14 import org.camunda.bpm.engine.delegate.DelegateTask;
15 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.onap.so.bpmn.BaseTaskTest;
21 import org.onap.so.db.request.beans.InfraActiveRequests;
22
23 public class ManualHandlingTasksTest extends BaseTaskTest {
24     @InjectMocks
25     protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
26
27     @Mock
28     TaskService taskService;
29
30     @Mock
31     private DelegateExecution mockExecution;
32
33     @Mock
34     ProcessEngineServices processEngineServices;
35
36     @Mock
37     private DelegateTask task;
38
39     private DelegateExecution delegateExecution;
40
41     @Before
42     public void before() throws Exception {
43         delegateExecution = new DelegateExecutionFake();
44     }
45
46     @Test
47     public void setFalloutTaskVariables_Test() {
48         when(task.getId()).thenReturn("taskId");
49         when(task.getExecution()).thenReturn(mockExecution);
50         when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
51         when(processEngineServices.getTaskService()).thenReturn(taskService);
52         manualHandlingTasks.setFalloutTaskVariables(task);
53         verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
54     }
55
56     @Test
57     public void setPauseTaskVariables_Test() {
58         when(task.getId()).thenReturn("taskId");
59         when(task.getExecution()).thenReturn(mockExecution);
60         when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
61         when(processEngineServices.getTaskService()).thenReturn(taskService);
62         manualHandlingTasks.setPauseTaskVariables(task);
63         verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
64     }
65
66     @Test
67     public void completeTask_Test() throws Exception {
68         when(task.getId()).thenReturn("taskId");
69         when(task.getExecution()).thenReturn(mockExecution);
70         Map<String, Object> taskVariables = new HashMap<String, Object>();
71         taskVariables.put("responseValue", "resume");
72         when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
73         when(processEngineServices.getTaskService()).thenReturn(taskService);
74         when(taskService.getVariables(any(String.class))).thenReturn(taskVariables);
75         manualHandlingTasks.completeTask(task);
76         verify(mockExecution, times(1)).setVariable("responseValueTask", "Resume");
77     }
78
79     @Test
80     public void updateRequestDbStatus_Test() throws Exception {
81         InfraActiveRequests mockedRequest = new InfraActiveRequests();
82         delegateExecution.setVariable("msoRequestId", "testMsoRequestId");
83         when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
84         doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
85         manualHandlingTasks.updateRequestDbStatus(delegateExecution, "IN_PROGRESS");
86         verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
87         assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS");
88     }
89
90     @Test
91     public void createExternalTicket_Test() throws Exception {
92         delegateExecution.setVariable("msoRequestId", ("testMsoRequestId"));
93         delegateExecution.setVariable("vnfType", "testVnfType");
94         manualHandlingTasks.createExternalTicket(delegateExecution);
95     }
96 }