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;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.ArgumentMatchers;
35 import org.mockito.InjectMocks;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
40 import org.onap.so.bpmn.BaseTaskTest;
41 import org.onap.so.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
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;
54 public class SDNCDeactivateTaskTest extends BaseTaskTest {
56 private SDNCDeactivateTasks sdncDeactivateTasks = new SDNCDeactivateTasks();
58 private ServiceInstance serviceInstance;
59 private CloudRegion cloudRegion;
60 private RequestContext requestContext;
61 private GenericVnf genericVnf;
62 private VfModule vfModule;
63 private L3Network network;
64 private Customer customer;
67 public void before() throws BBObjectNotFoundException {
68 customer = setCustomer();
69 serviceInstance = setServiceInstance();
70 cloudRegion = setCloudRegion();
71 requestContext = setRequestContext();
72 genericVnf = setGenericVnf();
73 vfModule = setVfModule();
74 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);
88 public void deactivateVfModuleTest() throws Exception {
89 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources)
90 .deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
91 sdncDeactivateTasks.deactivateVfModule(execution);
92 verify(sdncVfModuleResources, times(1)).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer,
93 cloudRegion, requestContext);
94 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
95 assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
99 public void deactivateVfModuleExceptionTest() throws Exception {
100 expectedException.expect(BpmnError.class);
101 doThrow(RuntimeException.class).when(sdncVfModuleResources).deactivateVfModule(vfModule, genericVnf,
102 serviceInstance, customer, cloudRegion, requestContext);
103 sdncDeactivateTasks.deactivateVfModule(execution);
107 public void deactivateVnfTest() throws Exception {
108 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).deactivateVnf(genericVnf,
109 serviceInstance, customer, cloudRegion, requestContext);
110 sdncDeactivateTasks.deactivateVnf(execution);
111 verify(sdncVnfResources, times(1)).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion,
113 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
114 assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
118 public void deactivateVnfExceptionTest() throws Exception {
119 doThrow(RuntimeException.class).when(sdncVnfResources).deactivateVnf(genericVnf, serviceInstance, customer,
120 cloudRegion, requestContext);
121 expectedException.expect(BpmnError.class);
122 sdncDeactivateTasks.deactivateVnf(execution);
126 public void deactivateServiceInstanceTest() throws Exception {
127 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources)
128 .deactivateServiceInstance(serviceInstance, customer, requestContext);
129 sdncDeactivateTasks.deactivateServiceInstance(execution);
130 verify(sdncServiceInstanceResources, times(1)).deactivateServiceInstance(serviceInstance, customer,
132 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
133 assertEquals(SDNCTopology.SERVICE, sdncRequest.getTopology());
137 public void deactivateServiceInstanceExceptionTest() throws Exception {
138 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).deactivateServiceInstance(serviceInstance,
139 customer, requestContext);
140 expectedException.expect(BpmnError.class);
141 sdncDeactivateTasks.deactivateServiceInstance(execution);
145 public void test_deactivateNetwork() throws Exception {
146 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources)
147 .deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
148 sdncDeactivateTasks.deactivateNetwork(execution);
149 verify(sdncNetworkResources, times(1)).deactivateNetwork(network, serviceInstance, customer, requestContext,
151 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
152 assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());
156 public void test_deactivateNetwork_exception() throws Exception {
157 expectedException.expect(BpmnError.class);
158 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),
159 ArgumentMatchers.eq(ResourceKey.NETWORK_ID));
160 sdncDeactivateTasks.deactivateNetwork(execution);
161 verify(sdncNetworkResources, times(0)).deactivateNetwork(network, serviceInstance, customer, requestContext,