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.ArgumentMatchers.isA;
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.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 SDNCActivateTaskTest extends BaseTaskTest {
58 private SDNCActivateTasks sdncActivateTasks = new SDNCActivateTasks();
60 private L3Network network;
61 private ServiceInstance serviceInstance;
62 private RequestContext requestContext;
63 private CloudRegion cloudRegion;
64 private GenericVnf genericVnf;
65 private VfModule vfModule;
66 private Customer customer;
69 public void before() throws BBObjectNotFoundException {
70 serviceInstance = setServiceInstance();
71 network = setL3Network();
72 genericVnf = setGenericVnf();
73 vfModule = setVfModule();
74 cloudRegion = setCloudRegion();
75 requestContext = setRequestContext();
76 customer = setCustomer();
78 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
79 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
80 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
81 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
82 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
83 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
84 .thenReturn(genericVnf);
85 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
86 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
87 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
88 .thenReturn(serviceInstance);
89 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
90 .thenReturn(serviceInstance);
92 when(env.getRequiredProperty("mso.workflow.message.endpoint")).thenReturn("http://localhost:9090");
96 public void activateVnfTest() throws Exception {
97 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).activateVnf(genericVnf,
98 serviceInstance, customer, cloudRegion, requestContext);
99 sdncActivateTasks.activateVnf(execution);
100 verify(sdncVnfResources, times(1)).activateVnf(genericVnf, serviceInstance, customer, cloudRegion,
102 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
103 assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
107 public void activateVnfTestException() throws Exception {
108 expectedException.expect(BpmnError.class);
109 doThrow(RuntimeException.class).when(sdncVnfResources).activateVnf(genericVnf, serviceInstance, customer,
110 cloudRegion, requestContext);
111 sdncActivateTasks.activateVnf(execution);
115 public void activateNetworkTest() throws Exception {
116 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources).activateNetwork(
117 isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class),
118 isA(CloudRegion.class));
119 sdncActivateTasks.activateNetwork(execution);
120 verify(sdncNetworkResources, times(1)).activateNetwork(network, serviceInstance, customer, requestContext,
122 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
123 assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());
127 public void activateNetworkExceptionTest() throws Exception {
128 expectedException.expect(BpmnError.class);
129 doThrow(RuntimeException.class).when(sdncNetworkResources).activateNetwork(isA(L3Network.class),
130 isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class));
131 sdncActivateTasks.activateNetwork(execution);
135 public void activateVfModuleTest() throws Exception {
136 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).activateVfModule(
137 eq(vfModule), eq(genericVnf), eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext),
139 sdncActivateTasks.activateVfModule(execution);
140 verify(sdncVfModuleResources, times(1)).activateVfModule(eq(vfModule), eq(genericVnf), eq(serviceInstance),
141 eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class));
142 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
143 assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
147 public void activateVfModuleTestException() throws Exception {
148 expectedException.expect(BpmnError.class);
149 doThrow(RuntimeException.class).when(sdncVfModuleResources).activateVfModule(eq(vfModule), eq(genericVnf),
150 eq(serviceInstance), eq(customer), eq(cloudRegion), eq(requestContext), any(URI.class));
151 sdncActivateTasks.activateVfModule(execution);