b6dcd96534d46a8e52ec1540e5bf06e59f66502c
[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.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;
48
49 public class ManualHandlingTasksTest extends BaseTaskTest {
50     @InjectMocks
51     protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
52
53     @Mock
54     TaskService taskService;
55
56     @Mock
57     private DelegateExecution mockExecution;
58
59     @Mock
60     ProcessEngineServices processEngineServices;
61
62     @Mock
63     private DelegateTask task;
64
65     @Mock
66     private BuildingBlockExecution buildingBlockExecution;
67
68     @Mock
69     private GeneralBuildingBlock generalBuildingBlock;
70
71     @Mock
72     private RequestContext requestContext;
73
74     @Mock
75     private ExternalTicket MOCK_externalTicket;
76
77     @Before
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");
92     }
93
94     @Test
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));
104     }
105
106     @Test
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));
114     }
115
116     @Test
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");
127     }
128
129     @Test
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");
137     }
138
139 }