b98ab71d1d2bd0a7088a9e399fb5e5a6ed4a7f1e
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / sdnc / tasks / SDNCQueryTasksTest.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.junit.Assert.assertNotEquals;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29
30 import org.camunda.bpm.engine.delegate.BpmnError;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.so.bpmn.BaseTaskTest;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.springframework.beans.factory.annotation.Autowired;
39
40 public class SDNCQueryTasksTest extends BaseTaskTest{
41         @Autowired
42         private SDNCQueryTasks sdncQueryTasks;
43         
44         @Rule
45         public ExpectedException expectedException = ExpectedException.none();
46                 
47         private GenericVnf genericVnf;
48         private VfModule vfModule;
49         
50         @Before
51         public void before() {
52                 genericVnf = setGenericVnf();
53                 vfModule = setVfModule();
54         }
55         
56         @Test
57         public void queryVfModuleTest() throws Exception {
58                 String sdncQueryResponse = "response";
59                 vfModule.setSelflink("vfModuleSelfLink");
60                 
61                 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
62                 
63                 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
64                 sdncQueryTasks.queryVfModule(execution);
65                 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
66
67                 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
68         }
69
70         @Test
71         public void queryVnfTest() throws Exception {
72                 String sdncQueryResponse = "response";
73                 
74                 doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
75
76                 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
77                 sdncQueryTasks.queryVnf(execution);
78                 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
79
80                 verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
81         }       
82         
83         @Test
84         public void queryVfModuleForVolumeGroupTest() throws Exception {
85                 String sdncQueryResponse = "response";
86                 vfModule.setSelflink("vfModuleSelfLink");
87                 
88                 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
89                 
90                 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
91                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
92                 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
93
94                 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
95         }
96         
97         @Test
98         public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
99                 expectedException.expect(BpmnError.class);
100                 
101                 vfModule.setSelflink("");
102                 
103                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
104         }
105         
106         @Test
107         public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
108                 gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs().get(0).getVfModules().clear();
109                 
110                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
111                 
112                 verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
113         }
114         
115         @Test
116         public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
117                 expectedException.expect(BpmnError.class);
118                 
119                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
120         }
121 }