0f106ad91339d5b75edc98d575b2cb39ccc8e52a
[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
30 import java.util.ArrayList;
31 import java.util.List;
32
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;
45
46 public class WorkflowActionBBTasksUpdateReqDbTest extends BaseTaskTest{
47
48         protected WorkflowAction workflowAction = new WorkflowAction();
49         
50         @Spy
51         @InjectMocks
52         protected WorkflowActionBBTasks workflowActionBBTasks;
53         
54         private DelegateExecution execution;
55         
56         @Rule
57         public ExpectedException thrown = ExpectedException.none();
58         
59         @Before
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);
67         }
68         
69         @Test
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());
93         }
94 }