e064fb0b64ca413fda3dd0c3bb2627e27dc7bc39
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.workflow.tasks;
22
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;
43
44 public class WorkflowActionBBTasksUpdateReqDbTest extends BaseTaskTest {
45
46     protected WorkflowAction workflowAction = new WorkflowAction();
47
48     @Spy
49     @InjectMocks
50     protected WorkflowActionBBTasks workflowActionBBTasks;
51
52     private DelegateExecution execution;
53
54     @Rule
55     public ExpectedException thrown = ExpectedException.none();
56
57     @Before
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);
65     }
66
67     @Test
68     public void getUpdatedRequestTest() throws Exception {
69         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
70         BuildingBlock bb1 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
71         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
72         ebb1.setBuildingBlock(bb1);
73         flowsToExecute.add(ebb1);
74         BuildingBlock bb2 = new BuildingBlock().setBpmnFlowName("ActivateNetworkBB");
75         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
76         ebb2.setBuildingBlock(bb2);
77         flowsToExecute.add(ebb2);
78         String requestId = "requestId";
79         execution.setVariable("mso-request-id", requestId);
80         execution.setVariable("flowsToExecute", flowsToExecute);
81         int currentSequence = 2;
82         String expectedStatusMessage =
83                 "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1).";
84         Long expectedLong = new Long(52);
85         InfraActiveRequests mockedRequest = new InfraActiveRequests();
86         doReturn(mockedRequest).when(requestsDbClient).getInfraActiveRequestbyRequestId(isA(String.class));
87         InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence);
88         assertEquals(expectedStatusMessage, actual.getFlowStatus());
89         assertEquals(expectedLong, actual.getProgress());
90     }
91 }