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.assertTrue;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.doThrow;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.ArgumentMatchers;
36 import org.mockito.InjectMocks;
37 import org.onap.so.bpmn.BaseTaskTest;
38 import org.onap.so.bpmn.common.BuildingBlockExecution;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
46 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
47 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
48 import org.onap.so.client.exception.BBObjectNotFoundException;
51 public class SDNCAssignTasksTest extends BaseTaskTest{
53 private SDNCAssignTasks sdncAssignTasks = new SDNCAssignTasks();
55 private L3Network network;
56 private ServiceInstance serviceInstance;
57 private RequestContext requestContext;
58 private CloudRegion cloudRegion;
59 private GenericVnf genericVnf;
60 private VfModule vfModule;
61 private VolumeGroup volumeGroup;
62 private Customer customer;
65 public void before() throws BBObjectNotFoundException {
66 customer = setCustomer();
67 serviceInstance = setServiceInstance();
68 network = setL3Network();
69 cloudRegion = setCloudRegion();
70 requestContext = setRequestContext();
71 genericVnf = setGenericVnf();
72 vfModule = setVfModule();
73 volumeGroup = setVolumeGroup();
75 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
76 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
77 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
78 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
79 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
80 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
81 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup);
85 public void assignServiceInstanceTest() throws Exception {
86 doReturn("response").when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
88 sdncAssignTasks.assignServiceInstance(execution);
90 verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext);
91 assertTrue(execution.getVariable("SDNCResponse").equals("response"));
95 public void assignServiceInstanceExceptionTest() throws Exception {
96 expectedException.expect(BpmnError.class);
98 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
100 sdncAssignTasks.assignServiceInstance(execution);
104 public void assignVnfTest() throws Exception {
105 doReturn("response").when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
107 execution.setVariable("generalBuildingBlock", gBBInput);
108 sdncAssignTasks.assignVnf(execution);
110 verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance,customer, cloudRegion, requestContext, false);
111 assertTrue(execution.getVariable("SDNCResponse").equals("response"));
115 public void assignVnfExceptionTest() throws Exception {
116 expectedException.expect(BpmnError.class);
118 doThrow(RuntimeException.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
120 sdncAssignTasks.assignVnf(execution);
124 public void assignVfModuleTest() throws Exception {
125 doReturn("response").when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
127 sdncAssignTasks.assignVfModule(execution);
129 verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
130 assertTrue(execution.getVariable("SDNCAssignResponse_" + vfModule.getVfModuleId()).equals("response"));
134 public void assignVfModuleExceptionTest() throws Exception {
135 expectedException.expect(BpmnError.class);
137 doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
139 sdncAssignTasks.assignVfModule(execution);
143 public void assignNetworkTest() throws Exception {
144 doReturn("response").when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
146 sdncAssignTasks.assignNetwork(execution);
148 verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
152 public void assignNetworkExceptionTest() throws Exception {
153 expectedException.expect(BpmnError.class);
155 doThrow(RuntimeException.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
157 sdncAssignTasks.assignNetwork(execution);