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).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
80 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
81 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
82 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
83 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
84 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
89 public void activateVnfTest() throws Exception {
90 doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).activateVnf(genericVnf,serviceInstance, customer, cloudRegion,requestContext);
91 sdncActivateTasks.activateVnf(execution);
92 verify(sdncVnfResources, times(1)).activateVnf(genericVnf,serviceInstance, customer,cloudRegion,requestContext);
93 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
94 assertEquals(SDNCTopology.VNF,sdncRequest.getTopology());
98 public void activateVnfTestException() throws Exception {
99 expectedException.expect(BpmnError.class);
100 doThrow(RuntimeException.class).when(sdncVnfResources).activateVnf(genericVnf,serviceInstance, customer,cloudRegion,requestContext);
101 sdncActivateTasks.activateVnf(execution);
105 public void activateNetworkTest() throws Exception {
106 doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources).activateNetwork(isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class));
107 sdncActivateTasks.activateNetwork(execution);
108 verify(sdncNetworkResources, times(1)).activateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
109 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
110 assertEquals(SDNCTopology.NETWORK,sdncRequest.getTopology());
114 public void activateNetworkExceptionTest() throws Exception {
115 expectedException.expect(BpmnError.class);
116 doThrow(RuntimeException.class).when(sdncNetworkResources).activateNetwork(isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class));
117 sdncActivateTasks.activateNetwork(execution);
121 public void activateVfModuleTest() throws Exception {
122 doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources).activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
123 sdncActivateTasks.activateVfModule(execution);
124 verify(sdncVfModuleResources, times(1)).activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
125 SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
126 assertEquals(SDNCTopology.VFMODULE,sdncRequest.getTopology());
130 public void activateVfModuleTestException() throws Exception {
131 expectedException.expect(BpmnError.class);
132 doThrow(RuntimeException.class).when(sdncVfModuleResources).activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
133 sdncActivateTasks.activateVfModule(execution);