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.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.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
41 import org.onap.so.bpmn.BaseTaskTest;
42 import org.onap.so.bpmn.common.BuildingBlockExecution;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
50 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
51 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
52 import org.onap.so.client.exception.BBObjectNotFoundException;
53 import org.onap.so.client.sdnc.beans.SDNCRequest;
54 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
57 public class SDNCAssignTasksTest extends BaseTaskTest{
59 private SDNCAssignTasks sdncAssignTasks = new SDNCAssignTasks();
61 private L3Network network;
62 private ServiceInstance serviceInstance;
63 private RequestContext requestContext;
64 private CloudRegion cloudRegion;
65 private GenericVnf genericVnf;
66 private VfModule vfModule;
67 private VolumeGroup volumeGroup;
68 private Customer customer;
71 public void before() throws BBObjectNotFoundException {
72 customer = setCustomer();
73 serviceInstance = setServiceInstance();
74 network = setL3Network();
75 cloudRegion = setCloudRegion();
76 requestContext = setRequestContext();
77 genericVnf = setGenericVnf();
78 vfModule = setVfModule();
79 volumeGroup = setVolumeGroup();
81 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
82 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
83 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
84 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
85 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
86 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
87 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))).thenReturn(volumeGroup);
91 public void assignServiceInstanceTest() throws Exception {
92 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
93 sdncAssignTasks.assignServiceInstance(execution);
94 verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext);
95 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
96 assertEquals(SDNCTopology.SERVICE,sdncRequest.getTopology());
100 public void assignServiceInstanceExceptionTest() throws Exception {
101 expectedException.expect(BpmnError.class);
102 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
103 sdncAssignTasks.assignServiceInstance(execution);
107 public void assignVnfTest() throws Exception {
108 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
109 execution.setVariable("generalBuildingBlock", gBBInput);
110 sdncAssignTasks.assignVnf(execution);
111 verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance,customer, cloudRegion, requestContext, false);
112 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
113 assertEquals(SDNCTopology.VNF,sdncRequest.getTopology());
117 public void assignVnfExceptionTest() throws Exception {
118 expectedException.expect(BpmnError.class);
119 doThrow(RuntimeException.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
120 sdncAssignTasks.assignVnf(execution);
124 public void assignVfModuleTest() throws Exception {
125 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
126 sdncAssignTasks.assignVfModule(execution);
127 verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
128 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
129 assertEquals(SDNCTopology.VFMODULE,sdncRequest.getTopology());
133 public void assignVfModuleExceptionTest() throws Exception {
134 expectedException.expect(BpmnError.class);
135 doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
136 sdncAssignTasks.assignVfModule(execution);
140 public void assignNetworkTest() throws Exception {
141 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
142 sdncAssignTasks.assignNetwork(execution);
143 verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
144 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
145 assertEquals(SDNCTopology.NETWORK,sdncRequest.getTopology());
149 public void assignNetworkExceptionTest() throws Exception {
150 expectedException.expect(BpmnError.class);
151 doThrow(RuntimeException.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
152 sdncAssignTasks.assignNetwork(execution);