fc2d182b52f0d8a105edfa2a4bb470e8d432cafd
[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.Mockito.doReturn;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.so.bpmn.BaseTaskTest;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
39 import org.springframework.beans.factory.annotation.Autowired;
40
41 public class SDNCChangeAssignTasksTest extends BaseTaskTest{
42         @Autowired
43         private SDNCChangeAssignTasks sdncChangeAssignTasks;
44         
45         private ServiceInstance serviceInstance;
46         private RequestContext requestContext;
47         private CloudRegion cloudRegion;
48         private VfModule vfModule;
49         private GenericVnf genericVnf;
50         private Customer customer;
51         
52         @Before
53         public void before() {
54                 customer = setCustomer();
55                 serviceInstance = setServiceInstance();
56                 genericVnf = setGenericVnf();
57                 vfModule = setVfModule();
58                 cloudRegion = setCloudRegion();
59                 requestContext = setRequestContext();
60
61         }
62         
63         @Test
64         public void changeModelVnfTest() throws Exception {
65                 String response = "sdncChangeModelServiceInstance";
66                 
67                 doReturn(response).when(sdncServiceInstanceResources).changeModelServiceInstance(serviceInstance, customer, requestContext);
68                 
69                 sdncChangeAssignTasks.changeModelServiceInstance(execution);
70                 
71                 verify(sdncServiceInstanceResources, times(1)).changeModelServiceInstance(serviceInstance, customer, requestContext);
72                 
73                 assertEquals(response, execution.getVariable("SDNCChangeAssignTasks.changeModelServiceInstance.response"));
74         }
75         
76         @Test
77         public void changeModelVnfExceptionTest() throws Exception {
78                 expectedException.expect(BpmnError.class);
79                 doThrow(Exception.class).when(sdncVnfResources).changeModelVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext);
80                 sdncChangeAssignTasks.changeModelVnf(execution);
81         }
82         
83         @Test
84         public void changeAssignModelVfModuleTest() throws Exception {
85                 String response = "response";
86                 doReturn(response).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
87                 
88                 sdncChangeAssignTasks.changeAssignModelVfModule(execution);
89                 
90                 verify(sdncVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
91                 assertTrue(execution.getVariable("SDNCChangeAssignVfModuleResponse").equals(response));
92         }
93         
94         @Test
95         public void changeAssignModelVfModuleExceptionTest() throws Exception {
96                 expectedException.expect(BpmnError.class);
97                 doThrow(Exception.class).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext);
98                 sdncChangeAssignTasks.changeAssignModelVfModule(execution);
99         }
100 }