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.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;
 
  45 public class ManualHandlingTasksTest extends BaseTaskTest {
 
  47     protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks();
 
  50     TaskService taskService;
 
  53     private DelegateExecution mockExecution;
 
  56     ProcessEngineServices processEngineServices;
 
  59     private DelegateTask task;
 
  62     private BuildingBlockExecution buildingBlockExecution;
 
  65     public void before() throws Exception {
 
  66         delegateExecution = new DelegateExecutionFake();
 
  67         buildingBlockExecution = new DelegateExecutionImpl(delegateExecution);
 
  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));
 
  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));
 
  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");
 
 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");
 
 115     public void createExternalTicket_Test() throws Exception {
 
 116         buildingBlockExecution.setVariable("mso-request-id", ("testMsoRequestId"));
 
 117         buildingBlockExecution.setVariable("vnfType", "testVnfType");
 
 118         manualHandlingTasks.createExternalTicket(buildingBlockExecution);