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;
52 public class VnfEBBLoaderTest {
54 private String serviceId;
56 private BBInputSetupUtils bbInputSetupUtils;
57 private BBInputSetup bbInputSetup;
58 private WorkflowActionExtractResourcesAAI workflowActionUtils;
59 private ExceptionBuilder exceptionBuilder;
60 private DelegateExecution delegateExecution;
61 private VnfEBBLoader cut;
63 private org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI;
64 private ServiceInstance serviceInstanceMSO;
68 serviceId = "service123";
70 serviceInstanceAAI = mock(org.onap.aai.domain.yang.ServiceInstance.class);
71 serviceInstanceMSO = mock(ServiceInstance.class);
72 bbInputSetupUtils = mock(BBInputSetupUtils.class);
73 bbInputSetup = mock(BBInputSetup.class);
74 workflowActionUtils = mock(WorkflowActionExtractResourcesAAI.class);
75 exceptionBuilder = mock(ExceptionBuilder.class);
76 delegateExecution = new DelegateExecutionFake();
80 public void traverseAAIVnf_shouldAddServiceToResourceList() throws Exception {
81 List<Resource> resourceList = new ArrayList<>();
82 List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
83 doReturn(serviceInstanceAAI).when(bbInputSetupUtils).getAAIServiceInstanceById(serviceId);
84 doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
85 cut = new VnfEBBLoader(bbInputSetupUtils, bbInputSetup, workflowActionUtils, exceptionBuilder);
86 cut.traverseAAIVnf(delegateExecution, resourceList, serviceId, vnfId, aaiResourceIds);
87 assertEquals(WorkflowType.SERVICE, resourceList.get(0).getResourceType());
91 public void traverseAAIVnf_should_add_vnfs_and_vfmodules() throws Exception {
92 List<Resource> resourceList = new ArrayList<>();
93 List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
95 GenericVnf genericVnf = mock(GenericVnf.class);
96 doReturn(vnfId).when(genericVnf).getVnfId();
98 VfModule vfModule = mock(VfModule.class);
99 ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
100 modelInfoVfModule.setIsBaseBoolean(true);
101 doReturn(modelInfoVfModule).when(vfModule).getModelInfoVfModule();
103 doReturn(serviceInstanceAAI).when(bbInputSetupUtils).getAAIServiceInstanceById(serviceId);
104 doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
105 doReturn(List.of(genericVnf)).when(serviceInstanceMSO).getVnfs();
106 doReturn(List.of(vfModule)).when(genericVnf).getVfModules();
107 cut = new VnfEBBLoader(bbInputSetupUtils, bbInputSetup, workflowActionUtils, exceptionBuilder);
109 cut.traverseAAIVnf(delegateExecution, resourceList, serviceId, vnfId, aaiResourceIds);
111 assertEquals(3, resourceList.size());
112 assertEquals(WorkflowType.VNF, resourceList.get(1).getResourceType());
113 assertEquals(WorkflowType.VFMODULE, resourceList.get(2).getResourceType());
114 assertTrue(resourceList.get(2).isBaseVfModule());