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)
82 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
83 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
84 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
85 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
86 .thenReturn(genericVnf);
87 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
88 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
89 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
90 .thenReturn(serviceInstance);
91 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
92 .thenReturn(volumeGroup);
93 when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090");
97 public void assignServiceInstanceTest() throws Exception {
98 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources)
99 .assignServiceInstance(serviceInstance, customer, requestContext);
100 sdncAssignTasks.assignServiceInstance(execution);
101 verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext);
102 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
103 assertEquals(SDNCTopology.SERVICE, sdncRequest.getTopology());
107 public void assignServiceInstanceExceptionTest() throws Exception {
108 expectedException.expect(BpmnError.class);
109 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance,
110 customer, requestContext);
111 sdncAssignTasks.assignServiceInstance(execution);
115 public void assignVnfTest() throws Exception {
116 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).assignVnf(genericVnf,
117 serviceInstance, customer, cloudRegion, requestContext, false);
118 execution.setVariable("generalBuildingBlock", gBBInput);
119 sdncAssignTasks.assignVnf(execution);
120 verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext,
122 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
123 assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
127 public void assignVnfExceptionTest() throws Exception {
128 expectedException.expect(BpmnError.class);
129 doThrow(RuntimeException.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer,
130 cloudRegion, requestContext, false);
131 sdncAssignTasks.assignVnf(execution);
135 public void assignVfModuleTest() throws Exception {
136 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).assignVfModule(
137 eq(vfModule), eq(volumeGroup), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion),
138 eq(requestContext), any(URI.class));
139 sdncAssignTasks.assignVfModule(execution);
140 verify(sdncVfModuleResources, times(1)).assignVfModule(eq(vfModule), eq(volumeGroup), eq(genericVnf),
141 eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class));
142 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
143 assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
147 public void assignVfModuleExceptionTest() throws Exception {
148 expectedException.expect(BpmnError.class);
149 doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(eq(vfModule), eq(volumeGroup),
150 eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class));
151 sdncAssignTasks.assignVfModule(execution);
155 public void assignNetworkTest() throws Exception {
156 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources).assignNetwork(network,
157 serviceInstance, customer, requestContext, cloudRegion);
158 sdncAssignTasks.assignNetwork(execution);
159 verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext,
161 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
162 assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());
166 public void assignNetworkExceptionTest() throws Exception {
167 expectedException.expect(BpmnError.class);
168 doThrow(RuntimeException.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer,
169 requestContext, cloudRegion);
170 sdncAssignTasks.assignNetwork(execution);