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.Mockito.doReturn;
28 import static org.mockito.Mockito.doThrow;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.so.bpmn.BaseTaskTest;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
42 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
43 import org.onap.so.db.catalog.beans.OrchestrationStatus;
44 import org.springframework.beans.factory.annotation.Autowired;
46 public class SDNCUnassignTasksTest extends BaseTaskTest{
48 private SDNCUnassignTasks sdncUnassignTasks;
50 private ServiceInstance serviceInstance;
51 private RequestContext requestContext;
52 private GenericVnf genericVnf;
53 private VfModule vfModule;
54 private CloudRegion cloudRegion;
55 private L3Network network;
56 private Customer customer;
59 public void before() {
60 customer = setCustomer();
61 serviceInstance = setServiceInstance();
62 requestContext = setRequestContext();
63 genericVnf = setGenericVnf();
64 vfModule = setVfModule();
65 cloudRegion = setCloudRegion();
66 network = setL3Network();
71 public void unassignServiceInstanceTest() throws Exception {
72 doReturn("test").when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext);
74 sdncUnassignTasks.unassignServiceInstance(execution);
76 verify(sdncServiceInstanceResources, times(1)).unassignServiceInstance(serviceInstance, customer, requestContext);
80 public void unassignServiceInstanceTest_inventoried() throws Exception {
81 doReturn("test").when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext);
83 serviceInstance.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
85 sdncUnassignTasks.unassignServiceInstance(execution);
87 verify(sdncServiceInstanceResources, times(0)).unassignServiceInstance(serviceInstance, customer, requestContext);
91 public void unassignServiceInstanceExceptionTest() throws Exception {
92 expectedException.expect(BpmnError.class);
94 doThrow(Exception.class).when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext);
96 sdncUnassignTasks.unassignServiceInstance(execution);
100 public void unassignVfModuleTest() throws Exception {
101 doReturn("response").when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, serviceInstance);
103 sdncUnassignTasks.unassignVfModule(execution);
105 verify(sdncVfModuleResources, times(1)).unassignVfModule(vfModule, genericVnf, serviceInstance);
106 assertEquals("response", execution.getVariable("SDNCResponse"));
110 public void unassignVfModuleTest_inventoried() throws Exception {
111 vfModule.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
113 sdncUnassignTasks.unassignVfModule(execution);
115 verify(sdncVfModuleResources, times(0)).unassignVfModule(vfModule, genericVnf, serviceInstance);
116 assertNull(execution.getVariable("SDNCResponse"));
120 public void unassignVfModuleTest_pendingCreate() throws Exception {
121 vfModule.setOrchestrationStatus(OrchestrationStatus.PENDING_CREATE);
123 sdncUnassignTasks.unassignVfModule(execution);
125 verify(sdncVfModuleResources, times(0)).unassignVfModule(vfModule, genericVnf, serviceInstance);
126 assertNull(execution.getVariable("SDNCResponse"));
130 public void unassignVfModuleExceptionTest() throws Exception {
131 expectedException.expect(BpmnError.class);
133 doThrow(Exception.class).when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, serviceInstance);
135 sdncUnassignTasks.unassignVfModule(execution);
139 public void unassignVnfTest() throws Exception {
140 doReturn("response").when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
142 sdncUnassignTasks.unassignVnf(execution);
144 verify(sdncVnfResources, times(1)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
145 assertTrue(execution.getVariable("sdncUnassignVnfResponse").equals("response"));
149 public void unassignVnfTest_inventoried() throws Exception {
150 genericVnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
152 sdncUnassignTasks.unassignVnf(execution);
154 verify(sdncVnfResources, times(0)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
155 assertNull(execution.getVariable("sdncUnassignVnfResponse"));
159 public void unassignVnfTest_created() throws Exception {
160 genericVnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
162 sdncUnassignTasks.unassignVnf(execution);
164 verify(sdncVnfResources, times(0)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
165 assertNull(execution.getVariable("sdncUnassignVnfResponse"));
169 public void unassignVnfExceptionTest() throws Exception {
170 expectedException.expect(BpmnError.class);
171 doThrow(Exception.class).when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
172 sdncUnassignTasks.unassignVnf(execution);
176 public void unassignNetworkTest() throws Exception {
177 String cloudRegionSdnc = "AAIAIC25";
179 cloudRegion.setCloudRegionVersion("2.5");
181 execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
183 doReturn("response").when(sdncNetworkResources).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
185 assertNotEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
186 sdncUnassignTasks.unassignNetwork(execution);
188 verify(sdncNetworkResources, times(1)).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
189 assertEquals("response", execution.getVariable("SDNCUnAssignNetworkResponse"));
190 assertEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
194 public void unassignNetworkTest_inventoried() throws Exception {
195 network.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
197 sdncUnassignTasks.unassignNetwork(execution);
199 verify(sdncNetworkResources, times(0)).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
200 assertNull(execution.getVariable("SDNCUnAssignNetworkResponse"));