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