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.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
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;
31 import static org.mockito.Mockito.when;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.ArgumentMatchers;
37 import org.mockito.InjectMocks;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
42 import org.onap.so.bpmn.BaseTaskTest;
43 import org.onap.so.bpmn.common.BuildingBlockExecution;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
50 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
51 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
52 import org.onap.so.client.exception.BBObjectNotFoundException;
53 import org.onap.so.client.sdnc.beans.SDNCRequest;
54 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
56 public class SDNCUnassignTasksTest extends BaseTaskTest {
58 private SDNCUnassignTasks sdncUnassignTasks = new SDNCUnassignTasks();
60 private ServiceInstance serviceInstance;
61 private RequestContext requestContext;
62 private GenericVnf genericVnf;
63 private VfModule vfModule;
64 private CloudRegion cloudRegion;
65 private L3Network network;
66 private Customer customer;
69 public void before() throws BBObjectNotFoundException {
70 customer = setCustomer();
71 serviceInstance = setServiceInstance();
72 requestContext = setRequestContext();
73 genericVnf = setGenericVnf();
74 vfModule = setVfModule();
75 cloudRegion = setCloudRegion();
76 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 unassignServiceInstanceTest() throws Exception {
90 doReturn(new GenericResourceApiServiceOperationInformation()).when(sdncServiceInstanceResources)
91 .unassignServiceInstance(serviceInstance, customer, requestContext);
92 sdncUnassignTasks.unassignServiceInstance(execution);
93 verify(sdncServiceInstanceResources, times(1)).unassignServiceInstance(serviceInstance, customer,
95 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
96 assertEquals(SDNCTopology.SERVICE, sdncRequest.getTopology());
100 public void unassignServiceInstanceExceptionTest() throws Exception {
101 expectedException.expect(BpmnError.class);
102 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance,
103 customer, requestContext);
104 sdncUnassignTasks.unassignServiceInstance(execution);
108 public void unassignVfModuleTest() throws Exception {
109 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).unassignVfModule(
110 eq(vfModule), eq(genericVnf), eq(serviceInstance), eq(requestContext), any(URI.class));
111 sdncUnassignTasks.unassignVfModule(execution);
112 verify(sdncVfModuleResources, times(1)).unassignVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance),
113 eq(requestContext), any(URI.class));
114 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
115 assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
119 public void unassignVfModuleExceptionTest() throws Exception {
120 expectedException.expect(BpmnError.class);
121 doThrow(RuntimeException.class).when(sdncVfModuleResources).unassignVfModule(eq(vfModule), eq(genericVnf),
122 eq(serviceInstance), eq(requestContext), any(URI.class));
123 sdncUnassignTasks.unassignVfModule(execution);
127 public void unassignVnfTest() throws Exception {
128 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).unassignVnf(genericVnf,
129 serviceInstance, customer, cloudRegion, requestContext);
130 sdncUnassignTasks.unassignVnf(execution);
131 verify(sdncVnfResources, times(1)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion,
133 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
134 assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
138 public void unassignVnfExceptionTest() throws Exception {
139 expectedException.expect(BpmnError.class);
140 doThrow(RuntimeException.class).when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer,
141 cloudRegion, requestContext);
142 sdncUnassignTasks.unassignVnf(execution);
146 public void unassignNetworkTest() throws Exception {
147 String cloudRegionSdnc = "AAIAIC25";
148 cloudRegion.setCloudRegionVersion("2.5");
149 execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
150 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources)
151 .unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
152 assertNotEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
153 sdncUnassignTasks.unassignNetwork(execution);
154 verify(sdncNetworkResources, times(1)).unassignNetwork(network, serviceInstance, customer, requestContext,
156 assertEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId());
157 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
158 assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());