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.assertNotEquals;
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;
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.entities.ResourceKey;
50 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
51 import org.onap.so.client.exception.BBObjectNotFoundException;
52 import org.onap.so.client.sdnc.beans.SDNCRequest;
53 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
55 public class SDNCUnassignTasksTest extends BaseTaskTest {
57 private SDNCUnassignTasks sdncUnassignTasks = new SDNCUnassignTasks();
59 private ServiceInstance serviceInstance;
60 private RequestContext requestContext;
61 private GenericVnf genericVnf;
62 private VfModule vfModule;
63 private CloudRegion cloudRegion;
64 private L3Network network;
65 private Customer customer;
68 public void before() throws BBObjectNotFoundException {
69 customer = setCustomer();
70 serviceInstance = setServiceInstance();
71 requestContext = setRequestContext();
72 genericVnf = setGenericVnf();
73 vfModule = setVfModule();
74 cloudRegion = setCloudRegion();
75 network = setL3Network();
76 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
77 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
78 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
79 .thenReturn(genericVnf);
80 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
81 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
82 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
83 .thenReturn(serviceInstance);
87 public void unassignServiceInstanceTest() throws Exception {
88 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources)
89 .unassignServiceInstance(serviceInstance, customer, requestContext);
90 sdncUnassignTasks.unassignServiceInstance(execution);
91 verify(sdncServiceInstanceResources, times(1)).unassignServiceInstance(serviceInstance, customer,
93 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
94 assertEquals(SDNCTopology.SERVICE, sdncRequest.getTopology());
98 public void unassignServiceInstanceExceptionTest() throws Exception {
99 expectedException.expect(BpmnError.class);
100 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance,
101 customer, requestContext);
102 sdncUnassignTasks.unassignServiceInstance(execution);
106 public void unassignVfModuleTest() throws Exception {
107 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources)
108 .unassignVfModule(vfModule, genericVnf, serviceInstance);
109 sdncUnassignTasks.unassignVfModule(execution);
110 verify(sdncVfModuleResources, times(1)).unassignVfModule(vfModule, genericVnf, serviceInstance);
111 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
112 assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
116 public void unassignVfModuleExceptionTest() throws Exception {
117 expectedException.expect(BpmnError.class);
118 doThrow(RuntimeException.class).when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf,
120 sdncUnassignTasks.unassignVfModule(execution);
124 public void unassignVnfTest() throws Exception {
125 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).unassignVnf(genericVnf,
126 serviceInstance, customer, cloudRegion, requestContext);
127 sdncUnassignTasks.unassignVnf(execution);
128 verify(sdncVnfResources, times(1)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion,
130 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
131 assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
135 public void unassignVnfExceptionTest() throws Exception {
136 expectedException.expect(BpmnError.class);
137 doThrow(RuntimeException.class).when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer,
138 cloudRegion, requestContext);
139 sdncUnassignTasks.unassignVnf(execution);
143 public void unassignNetworkTest() throws Exception {
144 String cloudRegionSdnc = "AAIAIC25";
145 cloudRegion.setCloudRegionVersion("2.5");
146 execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
147 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources)
148 .unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
149 assertNotEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
150 sdncUnassignTasks.unassignNetwork(execution);
151 verify(sdncNetworkResources, times(1)).unassignNetwork(network, serviceInstance, customer, requestContext,
153 assertEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
154 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
155 assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());