2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.doThrow;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
31 import static org.mockito.Mockito.when;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.ArgumentMatchers;
37 import org.mockito.InjectMocks;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.common.BuildingBlockExecution;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
48 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
49 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
50 import org.onap.so.client.exception.BBObjectNotFoundException;
51 import org.onap.so.client.sdnc.beans.SDNCRequest;
52 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
55 public class SDNCAssignTasksTest extends BaseTaskTest{
57 private SDNCAssignTasks sdncAssignTasks = new SDNCAssignTasks();
59 private L3Network network;
60 private ServiceInstance serviceInstance;
61 private RequestContext requestContext;
62 private CloudRegion cloudRegion;
63 private GenericVnf genericVnf;
64 private VfModule vfModule;
65 private VolumeGroup volumeGroup;
66 private Customer customer;
69 public void before() throws BBObjectNotFoundException {
70 customer = setCustomer();
71 serviceInstance = setServiceInstance();
72 network = setL3Network();
73 cloudRegion = setCloudRegion();
74 requestContext = setRequestContext();
75 genericVnf = setGenericVnf();
76 vfModule = setVfModule();
77 volumeGroup = setVolumeGroup();
79 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
80 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
81 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
82 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
83 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
84 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
85 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup);
89 public void assignServiceInstanceTest() throws Exception {
90 doReturn("response").when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
92 sdncAssignTasks.assignServiceInstance(execution);
94 verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext);
95 assertTrue(execution.getVariable("SDNCResponse").equals("response"));
99 public void assignServiceInstanceExceptionTest() throws Exception {
100 expectedException.expect(BpmnError.class);
102 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
104 sdncAssignTasks.assignServiceInstance(execution);
108 public void assignVnfTest() throws Exception {
109 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
111 execution.setVariable("generalBuildingBlock", gBBInput);
112 sdncAssignTasks.assignVnf(execution);
114 verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance,customer, cloudRegion, requestContext, false);
115 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
116 assertEquals(SDNCTopology.VNF,sdncRequest.getTopology());
120 public void assignVnfExceptionTest() throws Exception {
121 expectedException.expect(BpmnError.class);
123 doThrow(RuntimeException.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
125 sdncAssignTasks.assignVnf(execution);
129 public void assignVfModuleTest() throws Exception {
130 doReturn("response").when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
132 sdncAssignTasks.assignVfModule(execution);
134 verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
135 assertTrue(execution.getVariable("SDNCAssignResponse_" + vfModule.getVfModuleId()).equals("response"));
139 public void assignVfModuleExceptionTest() throws Exception {
140 expectedException.expect(BpmnError.class);
142 doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
144 sdncAssignTasks.assignVfModule(execution);
148 public void assignNetworkTest() throws Exception {
149 doReturn("response").when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
151 sdncAssignTasks.assignNetwork(execution);
153 verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
157 public void assignNetworkExceptionTest() throws Exception {
158 expectedException.expect(BpmnError.class);
160 doThrow(RuntimeException.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
162 sdncAssignTasks.assignNetwork(execution);