2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 - 2018 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.workflow.tasks;
 
  23 import static org.junit.Assert.assertEquals;
 
  24 import static org.mockito.ArgumentMatchers.any;
 
  25 import static org.mockito.ArgumentMatchers.anyString;
 
  26 import static org.mockito.ArgumentMatchers.isA;
 
  27 import static org.mockito.Mockito.doReturn;
 
  28 import static org.mockito.Mockito.when;
 
  29 import java.util.ArrayList;
 
  30 import java.util.List;
 
  31 import org.camunda.bpm.engine.delegate.DelegateExecution;
 
  32 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
 
  33 import org.junit.Before;
 
  34 import org.junit.Rule;
 
  35 import org.junit.Test;
 
  36 import org.junit.rules.ExpectedException;
 
  37 import org.mockito.InjectMocks;
 
  38 import org.mockito.Spy;
 
  39 import org.onap.so.bpmn.BaseTaskTest;
 
  40 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
 
  41 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 
  42 import org.onap.so.db.request.beans.InfraActiveRequests;
 
  44 public class WorkflowActionBBTasksUpdateReqDbTest extends BaseTaskTest {
 
  46     protected WorkflowAction workflowAction = new WorkflowAction();
 
  50     protected WorkflowActionBBTasks workflowActionBBTasks;
 
  52     private DelegateExecution execution;
 
  55     public ExpectedException thrown = ExpectedException.none();
 
  58     public void before() throws Exception {
 
  59         execution = new DelegateExecutionFake();
 
  60         org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
 
  61         servInstance.setServiceInstanceId("TEST");
 
  62         when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), any())).thenReturn(servInstance);
 
  63         workflowAction.setBbInputSetupUtils(bbSetupUtils);
 
  64         workflowAction.setBbInputSetup(bbInputSetup);
 
  68     public void getUpdatedRequestTest() throws Exception {
 
  69         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
 
  70         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
 
  71         BuildingBlock bb1 = new BuildingBlock();
 
  72         bb1.setBpmnFlowName("CreateNetworkBB");
 
  73         flowsToExecute.add(ebb1);
 
  74         ebb1.setBuildingBlock(bb1);
 
  75         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
 
  76         BuildingBlock bb2 = new BuildingBlock();
 
  77         bb2.setBpmnFlowName("ActivateNetworkBB");
 
  78         flowsToExecute.add(ebb2);
 
  79         ebb2.setBuildingBlock(bb2);
 
  80         String requestId = "requestId";
 
  81         execution.setVariable("mso-request-id", requestId);
 
  82         execution.setVariable("flowsToExecute", flowsToExecute);
 
  83         int currentSequence = 2;
 
  84         String expectedStatusMessage =
 
  85                 "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1).";
 
  86         Long expectedLong = new Long(52);
 
  87         InfraActiveRequests mockedRequest = new InfraActiveRequests();
 
  88         doReturn(mockedRequest).when(requestsDbClient).getInfraActiveRequestbyRequestId(isA(String.class));
 
  89         InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence);
 
  90         assertEquals(expectedStatusMessage, actual.getFlowStatus());
 
  91         assertEquals(expectedLong, actual.getProgress());