b40195c07b5e8767f8146eedb523324bad34b5bc
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.manualhandling.tasks;
22
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;
30 import java.util.Map;
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.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.common.DelegateExecutionImpl;
43 import org.onap.so.db.request.beans.InfraActiveRequests;
44
45 public class ManualHandlingTasksTest extends BaseTaskTest {
46     @InjectMocks
47     protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
48
49     @Mock
50     TaskService taskService;
51
52     @Mock
53     private DelegateExecution mockExecution;
54
55     @Mock
56     ProcessEngineServices processEngineServices;
57
58     @Mock
59     private DelegateTask task;
60
61     @Mock
62     private BuildingBlockExecution buildingBlockExecution;
63
64     @Before
65     public void before() throws Exception {
66         delegateExecution = new DelegateExecutionFake();
67         buildingBlockExecution = new DelegateExecutionImpl(delegateExecution);
68     }
69
70     @Test
71     public void setFalloutTaskVariables_Test() {
72         when(task.getId()).thenReturn("taskId");
73         when(task.getExecution()).thenReturn(mockExecution);
74         when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
75         when(processEngineServices.getTaskService()).thenReturn(taskService);
76         manualHandlingTasks.setFalloutTaskVariables(task);
77         verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
78     }
79
80     @Test
81     public void setPauseTaskVariables_Test() {
82         when(task.getId()).thenReturn("taskId");
83         when(task.getExecution()).thenReturn(mockExecution);
84         when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
85         when(processEngineServices.getTaskService()).thenReturn(taskService);
86         manualHandlingTasks.setPauseTaskVariables(task);
87         verify(taskService, times(1)).setVariables(any(String.class), any(Map.class));
88     }
89
90     @Test
91     public void completeTask_Test() throws Exception {
92         when(task.getId()).thenReturn("taskId");
93         when(task.getExecution()).thenReturn(mockExecution);
94         Map<String, Object> taskVariables = new HashMap<String, Object>();
95         taskVariables.put("responseValue", "resume");
96         when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices);
97         when(processEngineServices.getTaskService()).thenReturn(taskService);
98         when(taskService.getVariables(any(String.class))).thenReturn(taskVariables);
99         manualHandlingTasks.completeTask(task);
100         verify(mockExecution, times(1)).setVariable("responseValueTask", "Resume");
101     }
102
103     @Test
104     public void updateRequestDbStatus_Test() throws Exception {
105         InfraActiveRequests mockedRequest = new InfraActiveRequests();
106         buildingBlockExecution.setVariable("mso-request-id", "msoRequestId");
107         when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
108         doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
109         manualHandlingTasks.updateRequestDbStatus(buildingBlockExecution, "IN_PROGRESS");
110         verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
111         assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS");
112     }
113
114     @Test
115     public void createExternalTicket_Test() throws Exception {
116         buildingBlockExecution.setVariable("mso-request-id", ("testMsoRequestId"));
117         buildingBlockExecution.setVariable("vnfType", "testVnfType");
118         manualHandlingTasks.createExternalTicket(buildingBlockExecution);
119     }
120 }