Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCAssignTasksTest.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.assertTrue;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.doThrow;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31
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.so.bpmn.BaseTaskTest;
38 import org.onap.so.bpmn.common.BuildingBlockExecution;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
46 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
47 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
48 import org.onap.so.client.exception.BBObjectNotFoundException;
49
50
51 public class SDNCAssignTasksTest extends BaseTaskTest{
52         @InjectMocks
53         private SDNCAssignTasks sdncAssignTasks = new SDNCAssignTasks();
54
55         private L3Network network;
56         private ServiceInstance serviceInstance;
57         private RequestContext requestContext;
58         private CloudRegion cloudRegion;
59         private GenericVnf genericVnf;
60         private VfModule vfModule;
61         private VolumeGroup volumeGroup;
62         private Customer customer;
63
64         @Before
65         public void before() throws BBObjectNotFoundException {
66                 customer = setCustomer();
67                 serviceInstance = setServiceInstance();
68                 network = setL3Network();
69                 cloudRegion = setCloudRegion();
70                 requestContext = setRequestContext();
71                 genericVnf = setGenericVnf();
72                 vfModule = setVfModule();
73                 volumeGroup = setVolumeGroup();
74                 
75                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
76                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
77                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
78                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
79                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
80                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
81                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup);
82         }
83
84         @Test
85         public void assignServiceInstanceTest() throws Exception {
86                 doReturn("response").when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
87
88                 sdncAssignTasks.assignServiceInstance(execution);
89
90                 verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext);
91                 assertTrue(execution.getVariable("SDNCResponse").equals("response"));
92         }
93
94         @Test
95         public void assignServiceInstanceExceptionTest() throws Exception {
96                 expectedException.expect(BpmnError.class);
97
98                 doThrow(RuntimeException.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext);
99
100                 sdncAssignTasks.assignServiceInstance(execution);
101         }
102
103         @Test
104         public void assignVnfTest() throws Exception {
105                 doReturn("response").when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
106
107                 execution.setVariable("generalBuildingBlock", gBBInput);
108                 sdncAssignTasks.assignVnf(execution);
109
110                 verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance,customer, cloudRegion, requestContext, false);
111                 assertTrue(execution.getVariable("SDNCResponse").equals("response"));
112         }
113
114         @Test
115         public void assignVnfExceptionTest() throws Exception {
116                 expectedException.expect(BpmnError.class);
117
118                 doThrow(RuntimeException.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false);
119
120                 sdncAssignTasks.assignVnf(execution);
121         }
122
123         @Test
124         public void assignVfModuleTest() throws Exception {
125                 doReturn("response").when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
126
127                 sdncAssignTasks.assignVfModule(execution);
128
129                 verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
130                 assertTrue(execution.getVariable("SDNCAssignResponse_" + vfModule.getVfModuleId()).equals("response"));
131         }
132
133         @Test
134         public void assignVfModuleExceptionTest() throws Exception {
135                 expectedException.expect(BpmnError.class);
136
137                 doThrow(RuntimeException.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
138
139                 sdncAssignTasks.assignVfModule(execution);
140         }
141
142         @Test
143         public void assignNetworkTest() throws Exception {
144                 doReturn("response").when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
145
146                 sdncAssignTasks.assignNetwork(execution);
147
148                 verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
149         }
150
151         @Test
152         public void assignNetworkExceptionTest() throws Exception {
153                 expectedException.expect(BpmnError.class);
154
155                 doThrow(RuntimeException.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
156
157                 sdncAssignTasks.assignNetwork(execution);
158         }
159 }