Springboot 2.0 upgrade
[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.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
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
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.mockito.ArgumentMatchers;
39 import org.mockito.InjectMocks;
40 import org.onap.so.bpmn.BaseTaskTest;
41 import org.onap.so.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
46
47 public class SDNCQueryTasksTest extends BaseTaskTest{
48         @InjectMocks
49         private SDNCQueryTasks sdncQueryTasks = new SDNCQueryTasks();
50         
51         @Rule
52         public ExpectedException expectedException = ExpectedException.none();
53                 
54         private GenericVnf genericVnf;
55         private VfModule vfModule;
56         
57         @Before
58         public void before() throws BBObjectNotFoundException {
59                 genericVnf = setGenericVnf();
60                 vfModule = setVfModule();
61                 
62                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
63                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
64
65                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
66
67         }
68         
69         @Test
70         public void queryVfModuleTest() throws Exception {
71                 String sdncQueryResponse = "response";
72                 vfModule.setSelflink("vfModuleSelfLink");
73                 
74                 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
75                 
76                 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
77                 sdncQueryTasks.queryVfModule(execution);
78                 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
79
80                 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
81         }
82
83         @Test
84         public void queryVnfTest() throws Exception {
85                 String sdncQueryResponse = "response";
86                 
87                 doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
88
89                 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
90                 sdncQueryTasks.queryVnf(execution);
91                 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
92
93                 verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
94         }       
95         
96         @Test
97         public void queryVfModuleForVolumeGroupTest() throws Exception {
98                 String sdncQueryResponse = "response";
99                 vfModule.setSelflink("vfModuleSelfLink");
100                 
101                 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
102                 
103                 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
104                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
105                 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
106
107                 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
108         }
109         
110         @Test
111         public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
112                 expectedException.expect(BpmnError.class);
113                 
114                 vfModule.setSelflink("");
115                 
116                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
117         }
118         
119         @Test
120         public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
121                 expectedException.expect(BpmnError.class);
122                 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any());       
123                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
124                 
125                 verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
126         }
127         
128         @Test
129         public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
130                 expectedException.expect(BpmnError.class);
131                 
132                 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
133         }
134 }