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.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.doReturn;
30 import static org.mockito.Mockito.doThrow;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
33 import static org.mockito.Mockito.when;
35 import org.camunda.bpm.engine.delegate.BpmnError;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.ArgumentMatchers;
39 import org.mockito.InjectMocks;
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.db.catalog.beans.OrchestrationStatus;
52 import org.springframework.beans.factory.annotation.Autowired;
54 public class SDNCUnassignTasksTest extends BaseTaskTest{
56 private SDNCUnassignTasks sdncUnassignTasks = new SDNCUnassignTasks();
58 private ServiceInstance serviceInstance;
59 private RequestContext requestContext;
60 private GenericVnf genericVnf;
61 private VfModule vfModule;
62 private CloudRegion cloudRegion;
63 private L3Network network;
64 private Customer customer;
67 public void before() throws BBObjectNotFoundException {
68 customer = setCustomer();
69 serviceInstance = setServiceInstance();
70 requestContext = setRequestContext();
71 genericVnf = setGenericVnf();
72 vfModule = setVfModule();
73 cloudRegion = setCloudRegion();
74 network = setL3Network();
75 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
76 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
77 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
78 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
79 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
83 public void unassignServiceInstanceTest() throws Exception {
84 doReturn("test").when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext);
86 sdncUnassignTasks.unassignServiceInstance(execution);
88 verify(sdncServiceInstanceResources, times(1)).unassignServiceInstance(serviceInstance, customer, requestContext);
94 public void unassignServiceInstanceExceptionTest() throws Exception {
95 expectedException.expect(BpmnError.class);
97 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext);
99 sdncUnassignTasks.unassignServiceInstance(execution);
103 public void unassignVfModuleTest() throws Exception {
104 doReturn("response").when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, serviceInstance);
106 sdncUnassignTasks.unassignVfModule(execution);
108 verify(sdncVfModuleResources, times(1)).unassignVfModule(vfModule, genericVnf, serviceInstance);
109 assertEquals("response", execution.getVariable("SDNCResponse"));
116 public void unassignVfModuleExceptionTest() throws Exception {
117 expectedException.expect(BpmnError.class);
119 doThrow(RuntimeException.class).when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, serviceInstance);
121 sdncUnassignTasks.unassignVfModule(execution);
125 public void unassignVnfTest() throws Exception {
126 doReturn("response").when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
128 sdncUnassignTasks.unassignVnf(execution);
130 verify(sdncVnfResources, times(1)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
131 assertTrue(execution.getVariable("sdncUnassignVnfResponse").equals("response"));
136 public void unassignVnfExceptionTest() throws Exception {
137 expectedException.expect(BpmnError.class);
138 doThrow(RuntimeException.class).when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
139 sdncUnassignTasks.unassignVnf(execution);
143 public void unassignNetworkTest() throws Exception {
144 String cloudRegionSdnc = "AAIAIC25";
146 cloudRegion.setCloudRegionVersion("2.5");
148 execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
150 doReturn("response").when(sdncNetworkResources).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
152 assertNotEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
153 sdncUnassignTasks.unassignNetwork(execution);
155 verify(sdncNetworkResources, times(1)).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
156 assertEquals("response", execution.getVariable("SDNCUnAssignNetworkResponse"));
157 assertEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());