a9bfde9babc08277aeed56adff0643d1ca0502d9
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / ebb / loader / VnfEBBLoaderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2021 Nokia
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Modifications Copyright (c) 2021 Nokia
10  * ================================================================================
11  * Modifications Copyright (c) 2020 Tech Mahindra
12  * ================================================================================
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  *      http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  * ============LICENSE_END=========================================================
25  */
26
27 package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader;
28
29
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
32 import org.javatuples.Pair;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
36 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
37 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
38 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
39 import org.onap.so.client.exception.ExceptionBuilder;
40 import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
41 import java.util.ArrayList;
42 import java.util.List;
43 import static org.junit.Assert.assertEquals;
44 import static org.mockito.Mockito.doReturn;
45 import static org.mockito.Mockito.mock;
46
47
48 public class VnfEBBLoaderTest {
49
50     private String serviceId;
51     private String vnfId;
52     private BBInputSetupUtils bbInputSetupUtils;
53     private BBInputSetup bbInputSetup;
54     private WorkflowActionExtractResourcesAAI workflowActionUtils;
55     private ExceptionBuilder exceptionBuilder;
56     private DelegateExecution delegateExecution;
57     private VnfEBBLoader cut;
58
59     private org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI;
60     private ServiceInstance serviceInstanceMSO;
61
62     @Before
63     public void setup() {
64         serviceId = "service123";
65         vnfId = "vnf123";
66         serviceInstanceAAI = mock(org.onap.aai.domain.yang.ServiceInstance.class);
67         serviceInstanceMSO = mock(ServiceInstance.class);
68         bbInputSetupUtils = mock(BBInputSetupUtils.class);
69         bbInputSetup = mock(BBInputSetup.class);
70         workflowActionUtils = mock(WorkflowActionExtractResourcesAAI.class);
71         exceptionBuilder = mock(ExceptionBuilder.class);
72         delegateExecution = new DelegateExecutionFake();
73     }
74
75     @Test
76     public void traverseAAIVnf_shouldAddServiceToResourceList() throws Exception {
77         List<Resource> resourceList = new ArrayList<>();
78         List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
79         doReturn(serviceInstanceAAI).when(bbInputSetupUtils).getAAIServiceInstanceById(serviceId);
80         doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
81         cut = new VnfEBBLoader(bbInputSetupUtils, bbInputSetup, workflowActionUtils, exceptionBuilder);
82         cut.traverseAAIVnf(delegateExecution, resourceList, serviceId, vnfId, aaiResourceIds);
83         assertEquals(WorkflowType.SERVICE, resourceList.get(0).getResourceType());
84     }
85 }