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 BuildingBlock bb1 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
71 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(bb1);
72 flowsToExecute.add(ebb1);
73 BuildingBlock bb2 = new BuildingBlock().setBpmnFlowName("ActivateNetworkBB");
74 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(bb2);
75 flowsToExecute.add(ebb2);
76 String requestId = "requestId";
77 execution.setVariable("mso-request-id", requestId);
78 execution.setVariable("flowsToExecute", flowsToExecute);
79 int currentSequence = 2;
80 String expectedStatusMessage =
81 "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1).";
82 Long expectedLong = new Long(52);
83 InfraActiveRequests mockedRequest = new InfraActiveRequests();
84 doReturn(mockedRequest).when(requestsDbClient).getInfraActiveRequestbyRequestId(isA(String.class));
85 InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence);
86 assertEquals(expectedStatusMessage, actual.getFlowStatus());
87 assertEquals(expectedLong, actual.getProgress());