Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCActivateTaskTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
22
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;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.ArgumentMatchers;
36 import org.mockito.InjectMocks;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
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.client.sdnc.beans.SDNCRequest;
52 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
53
54 public class SDNCActivateTaskTest extends BaseTaskTest {
55
56     @InjectMocks
57     private SDNCActivateTasks sdncActivateTasks = new SDNCActivateTasks();
58
59     private L3Network network;
60     private ServiceInstance serviceInstance;
61     private RequestContext requestContext;
62     private CloudRegion cloudRegion;
63     private GenericVnf genericVnf;
64     private VfModule vfModule;
65     private Customer customer;
66
67     @Before
68     public void before() throws BBObjectNotFoundException {
69         serviceInstance = setServiceInstance();
70         network = setL3Network();
71         genericVnf = setGenericVnf();
72         vfModule = setVfModule();
73         cloudRegion = setCloudRegion();
74         requestContext = setRequestContext();
75         customer = setCustomer();
76
77         customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
78         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
79                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
80         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
81                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
82         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
83                 .thenReturn(genericVnf);
84         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
85         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
86         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
87                 .thenReturn(serviceInstance);
88
89     }
90
91     @Test
92     public void activateVnfTest() throws Exception {
93         doReturn(new GenericResourceApiVnfOperationInformation()).when(sdncVnfResources).activateVnf(genericVnf,
94                 serviceInstance, customer, cloudRegion, requestContext);
95         sdncActivateTasks.activateVnf(execution);
96         verify(sdncVnfResources, times(1)).activateVnf(genericVnf, serviceInstance, customer, cloudRegion,
97                 requestContext);
98         SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
99         assertEquals(SDNCTopology.VNF, sdncRequest.getTopology());
100     }
101
102     @Test
103     public void activateVnfTestException() throws Exception {
104         expectedException.expect(BpmnError.class);
105         doThrow(RuntimeException.class).when(sdncVnfResources).activateVnf(genericVnf, serviceInstance, customer,
106                 cloudRegion, requestContext);
107         sdncActivateTasks.activateVnf(execution);
108     }
109
110     @Test
111     public void activateNetworkTest() throws Exception {
112         doReturn(new GenericResourceApiNetworkOperationInformation()).when(sdncNetworkResources).activateNetwork(
113                 isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class),
114                 isA(CloudRegion.class));
115         sdncActivateTasks.activateNetwork(execution);
116         verify(sdncNetworkResources, times(1)).activateNetwork(network, serviceInstance, customer, requestContext,
117                 cloudRegion);
118         SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
119         assertEquals(SDNCTopology.NETWORK, sdncRequest.getTopology());
120     }
121
122     @Test
123     public void activateNetworkExceptionTest() throws Exception {
124         expectedException.expect(BpmnError.class);
125         doThrow(RuntimeException.class).when(sdncNetworkResources).activateNetwork(isA(L3Network.class),
126                 isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class));
127         sdncActivateTasks.activateNetwork(execution);
128     }
129
130     @Test
131     public void activateVfModuleTest() throws Exception {
132         doReturn(new GenericResourceApiVfModuleOperationInformation()).when(sdncVfModuleResources)
133                 .activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
134         sdncActivateTasks.activateVfModule(execution);
135         verify(sdncVfModuleResources, times(1)).activateVfModule(vfModule, genericVnf, serviceInstance, customer,
136                 cloudRegion, requestContext);
137         SDNCRequest sdncRequest = execution.getVariable("SDNCRequest");
138         assertEquals(SDNCTopology.VFMODULE, sdncRequest.getTopology());
139     }
140
141     @Test
142     public void activateVfModuleTestException() throws Exception {
143         expectedException.expect(BpmnError.class);
144         doThrow(RuntimeException.class).when(sdncVfModuleResources).activateVfModule(vfModule, genericVnf,
145                 serviceInstance, customer, cloudRegion, requestContext);
146         sdncActivateTasks.activateVfModule(execution);
147     }
148 }