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.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 SDNCDeactivateTaskTest extends BaseTaskTest {
57 private SDNCDeactivateTasks sdncDeactivateTasks = new SDNCDeactivateTasks();
59 private ServiceInstance serviceInstance;
60 private CloudRegion cloudRegion;
61 private RequestContext requestContext;
62 private GenericVnf genericVnf;
63 private VfModule vfModule;
64 private L3Network network;
65 private Customer customer;
68 public void before() throws BBObjectNotFoundException {
69 customer = setCustomer();
70 serviceInstance = setServiceInstance();
71 cloudRegion = setCloudRegion();
72 requestContext = setRequestContext();
73 genericVnf = setGenericVnf();
74 vfModule = setVfModule();
75 network = setL3Network();
77 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
78 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
79 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
80 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
81 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
86 public void deactivateVfModuleTest() throws Exception {
87 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
88 sdncDeactivateTasks.deactivateVfModule(execution);
89 verify(sdncVfModuleResources, times(1)).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
90 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
91 assertEquals(SDNCTopology.VFMODULE,sdncRequest.getTopology());
95 public void deactivateVfModuleExceptionTest() throws Exception {
96 expectedException.expect(BpmnError.class);
97 doThrow(RuntimeException.class).when(sdncVfModuleResources).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
98 sdncDeactivateTasks.deactivateVfModule(execution);
102 public void deactivateVnfTest() throws Exception {
103 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
104 sdncDeactivateTasks.deactivateVnf(execution);
105 verify(sdncVnfResources, times(1)).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
106 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
107 assertEquals(SDNCTopology.VNF,sdncRequest.getTopology());
111 public void deactivateVnfExceptionTest() throws Exception {
112 doThrow(RuntimeException.class).when(sdncVnfResources).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
113 expectedException.expect(BpmnError.class);
114 sdncDeactivateTasks.deactivateVnf(execution);
118 public void deactivateServiceInstanceTest() throws Exception {
119 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources).deactivateServiceInstance(serviceInstance, customer, requestContext);
120 sdncDeactivateTasks.deactivateServiceInstance(execution);
121 verify(sdncServiceInstanceResources, times(1)).deactivateServiceInstance(serviceInstance, customer, requestContext);
122 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
123 assertEquals(SDNCTopology.SERVICE,sdncRequest.getTopology());
127 public void deactivateServiceInstanceExceptionTest() throws Exception {
128 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).deactivateServiceInstance(serviceInstance, customer, requestContext);
129 expectedException.expect(BpmnError.class);
130 sdncDeactivateTasks.deactivateServiceInstance(execution);
134 public void test_deactivateNetwork() throws Exception {
135 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources).deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
136 sdncDeactivateTasks.deactivateNetwork(execution);
137 verify(sdncNetworkResources, times(1)).deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
138 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
139 assertEquals(SDNCTopology.NETWORK,sdncRequest.getTopology());
143 public void test_deactivateNetwork_exception() throws Exception {
144 expectedException.expect(BpmnError.class);
145 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID));
146 sdncDeactivateTasks.deactivateNetwork(execution);
147 verify(sdncNetworkResources, times(0)).deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);