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)
78 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
79 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
80 .thenReturn(genericVnf);
81 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
82 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
83 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
84 .thenReturn(serviceInstance);
85 when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090");
89 public void deactivateVfModuleTest() throws Exception {
90 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).deactivateVfModule(
91 eq(vfModule), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext),
93 sdncDeactivateTasks.deactivateVfModule(execution);
94 verify(sdncVfModuleResources, times(1)).deactivateVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance),
95 eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class));
96 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
97 assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
101 public void deactivateVfModuleExceptionTest() throws Exception {
102 expectedException.expect(BpmnError.class);
103 doThrow(RuntimeException.class).when(sdncVfModuleResources).deactivateVfModule(eq(vfModule), eq(genericVnf),
104 eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class));
105 sdncDeactivateTasks.deactivateVfModule(execution);
109 public void deactivateVnfTest() throws Exception {
110 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).deactivateVnf(genericVnf,
111 serviceInstance, customer, cloudRegion, requestContext);
112 sdncDeactivateTasks.deactivateVnf(execution);
113 verify(sdncVnfResources, times(1)).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion,
115 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
116 assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
120 public void deactivateVnfExceptionTest() throws Exception {
121 doThrow(RuntimeException.class).when(sdncVnfResources).deactivateVnf(genericVnf, serviceInstance, customer,
122 cloudRegion, requestContext);
123 expectedException.expect(BpmnError.class);
124 sdncDeactivateTasks.deactivateVnf(execution);
128 public void deactivateServiceInstanceTest() throws Exception {
129 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources)
130 .deactivateServiceInstance(serviceInstance, customer, requestContext);
131 sdncDeactivateTasks.deactivateServiceInstance(execution);
132 verify(sdncServiceInstanceResources, times(1)).deactivateServiceInstance(serviceInstance, customer,
134 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
135 assertEquals(SDNCTopology.SERVICE, sdncRequest.getTopology());
139 public void deactivateServiceInstanceExceptionTest() throws Exception {
140 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).deactivateServiceInstance(serviceInstance,
141 customer, requestContext);
142 expectedException.expect(BpmnError.class);
143 sdncDeactivateTasks.deactivateServiceInstance(execution);
147 public void test_deactivateNetwork() throws Exception {
148 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources)
149 .deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
150 sdncDeactivateTasks.deactivateNetwork(execution);
151 verify(sdncNetworkResources, times(1)).deactivateNetwork(network, serviceInstance, customer, requestContext,
153 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
154 assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());
158 public void test_deactivateNetwork_exception() throws Exception {
159 expectedException.expect(BpmnError.class);
160 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),
161 ArgumentMatchers.eq(ResourceKey.NETWORK_ID));
162 sdncDeactivateTasks.deactivateNetwork(execution);
163 verify(sdncNetworkResources, times(0)).deactivateNetwork(network, serviceInstance, customer, requestContext,