Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCChangeAssignTasksTest.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 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
21
22 import static org.junit.Assert.assertEquals;
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.ServiceInstance;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
46 import org.onap.so.client.exception.BBObjectNotFoundException;
47 import org.springframework.beans.factory.annotation.Autowired;
48
49 public class SDNCChangeAssignTasksTest extends BaseTaskTest{
50         @InjectMocks
51         private SDNCChangeAssignTasks sdncChangeAssignTasks = new SDNCChangeAssignTasks();
52         
53         private ServiceInstance serviceInstance;
54         private RequestContext requestContext;
55         private CloudRegion cloudRegion;
56         private VfModule vfModule;
57         private GenericVnf genericVnf;
58         private Customer customer;
59         
60         @Before
61         public void before() throws BBObjectNotFoundException {
62                 customer = setCustomer();
63                 serviceInstance = setServiceInstance();
64                 genericVnf = setGenericVnf();
65                 vfModule = setVfModule();
66                 cloudRegion = setCloudRegion();
67                 requestContext = setRequestContext();
68
69                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
70                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
71                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
72                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
73         }
74         
75         @Test
76         public void changeModelVnfTest() throws Exception {
77                 String response = "sdncChangeModelServiceInstance";
78                 
79                 doReturn(response).when(sdncServiceInstanceResources).changeModelServiceInstance(serviceInstance, customer, requestContext);
80                 
81                 sdncChangeAssignTasks.changeModelServiceInstance(execution);
82                 
83                 verify(sdncServiceInstanceResources, times(1)).changeModelServiceInstance(serviceInstance, customer, requestContext);
84                 
85                 assertEquals(response, execution.getVariable("SDNCChangeAssignTasks.changeModelServiceInstance.response"));
86         }
87         
88         @Test
89         public void changeModelVnfExceptionTest() throws Exception {
90                 expectedException.expect(BpmnError.class);
91                 doThrow(RuntimeException.class).when(sdncVnfResources).changeModelVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
92                 sdncChangeAssignTasks.changeModelVnf(execution);
93         }
94         
95         @Test
96         public void changeAssignModelVfModuleTest() throws Exception {
97                 String response = "response";
98                 doReturn(response).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
99                 
100                 sdncChangeAssignTasks.changeAssignModelVfModule(execution);
101                 
102                 verify(sdncVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
103                 assertTrue(execution.getVariable("SDNCChangeAssignVfModuleResponse").equals(response));
104         }
105         
106         @Test
107         public void changeAssignModelVfModuleExceptionTest() throws Exception {
108                 expectedException.expect(BpmnError.class);
109                 doThrow(RuntimeException.class).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
110                 sdncChangeAssignTasks.changeAssignModelVfModule(execution);
111         }
112 }