2 * ============LICENSE_START=======================================================
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
17 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
27 package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader;
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.GenericVnf;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
39 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
40 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
41 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
42 import org.onap.so.client.exception.ExceptionBuilder;
43 import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
44 import java.util.ArrayList;
45 import java.util.List;
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertTrue;
48 import static org.mockito.Mockito.doReturn;
49 import static org.mockito.Mockito.mock;
50 import static org.mockito.Mockito.only;
53 public class VnfEBBLoaderTest {
55 private String serviceId;
57 private String vfModuleId;
58 private BBInputSetupUtils bbInputSetupUtils;
59 private BBInputSetup bbInputSetup;
60 private WorkflowActionExtractResourcesAAI workflowActionUtils;
61 private ExceptionBuilder exceptionBuilder;
62 private DelegateExecution delegateExecution;
63 private VnfEBBLoader cut;
65 private org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI;
66 private ServiceInstance serviceInstanceMSO;
70 serviceId = "service123";
72 vfModuleId = "vfModule123";
73 serviceInstanceAAI = mock(org.onap.aai.domain.yang.ServiceInstance.class);
74 serviceInstanceMSO = mock(ServiceInstance.class);
75 bbInputSetupUtils = mock(BBInputSetupUtils.class);
76 bbInputSetup = mock(BBInputSetup.class);
77 workflowActionUtils = mock(WorkflowActionExtractResourcesAAI.class);
78 exceptionBuilder = mock(ExceptionBuilder.class);
79 delegateExecution = new DelegateExecutionFake();
83 public void traverseAAIVnf_shouldAddServiceToResourceList() throws Exception {
84 List<Resource> resourceList = new ArrayList<>();
85 List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
86 doReturn(serviceInstanceAAI).when(bbInputSetupUtils).getAAIServiceInstanceById(serviceId);
87 doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
88 cut = new VnfEBBLoader(bbInputSetupUtils, bbInputSetup, workflowActionUtils, exceptionBuilder);
89 cut.traverseAAIVnf(delegateExecution, resourceList, serviceId, vnfId, aaiResourceIds);
90 assertEquals(WorkflowType.SERVICE, resourceList.get(0).getResourceType());
94 public void traverseAAIVnf_should_add_vnfs_and_vfmodules() throws Exception {
95 List<Resource> resourceList = new ArrayList<>();
96 List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
98 GenericVnf genericVnf = mock(GenericVnf.class);
99 doReturn(vnfId).when(genericVnf).getVnfId();
101 org.onap.aai.domain.yang.GenericVnf aaiVnf = mock(org.onap.aai.domain.yang.GenericVnf.class);
102 doReturn(aaiVnf).when(bbInputSetupUtils).getAAIGenericVnf(vnfId);
104 VfModule vfModule = mock(VfModule.class);
105 doReturn(vfModuleId).when(vfModule).getVfModuleId();
106 ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
107 modelInfoVfModule.setIsBaseBoolean(true);
108 doReturn(modelInfoVfModule).when(vfModule).getModelInfoVfModule();
110 org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule();
111 aaiVfModule.setIsBaseVfModule(true);
112 doReturn(aaiVfModule).when(bbInputSetupUtils).getAAIVfModule(vnfId, vfModuleId);
114 doReturn(serviceInstanceAAI).when(bbInputSetupUtils).getAAIServiceInstanceById(serviceId);
115 doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
116 doReturn(List.of(genericVnf)).when(serviceInstanceMSO).getVnfs();
117 doReturn(List.of(vfModule)).when(genericVnf).getVfModules();
118 cut = new VnfEBBLoader(bbInputSetupUtils, bbInputSetup, workflowActionUtils, exceptionBuilder);
120 cut.traverseAAIVnf(delegateExecution, resourceList, serviceId, vnfId, aaiResourceIds);
122 assertEquals(3, resourceList.size());
123 assertEquals(WorkflowType.VNF, resourceList.get(1).getResourceType());
124 assertEquals(WorkflowType.VFMODULE, resourceList.get(2).getResourceType());
125 assertTrue(resourceList.get(2).isBaseVfModule());