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