Replaced all tabs with spaces in java and pom.xml
[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 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.mockito.ArgumentMatchers;
38 import org.mockito.InjectMocks;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.common.BuildingBlockExecution;
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.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 ServiceInstance serviceInstance;
55     private GenericVnf genericVnf;
56     private VfModule vfModule;
57
58     @Before
59     public void before() throws BBObjectNotFoundException {
60         serviceInstance = setServiceInstance();
61         genericVnf = setGenericVnf();
62         vfModule = setVfModule();
63
64         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
65                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
66         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
67                 .thenReturn(serviceInstance);
68
69         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
70                 .thenReturn(genericVnf);
71
72         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
73
74     }
75
76     @Test
77     public void queryVfModuleTest() throws Exception {
78         String sdncQueryResponse = "response";
79         vfModule.setSelflink("vfModuleSelfLink");
80
81         doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
82
83         assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
84         sdncQueryTasks.queryVfModule(execution);
85         assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
86
87         verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
88     }
89
90     @Test
91     public void queryVnfTest() throws Exception {
92         String sdncQueryResponse = "response";
93
94         doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
95
96         assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
97         sdncQueryTasks.queryVnf(execution);
98         assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
99
100         verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
101     }
102
103     @Test
104     public void queryVfModuleForVolumeGroupTest() throws Exception {
105         String sdncQueryResponse = "response";
106         vfModule.setSelflink("vfModuleSelfLink");
107
108         doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
109
110         assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
111         sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
112         assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
113
114         verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
115     }
116
117     @Test
118     public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
119         expectedException.expect(BpmnError.class);
120
121         vfModule.setSelflink("");
122
123         sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
124     }
125
126     @Test
127     public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
128         expectedException.expect(BpmnError.class);
129         doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),
130                 ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID));
131         sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
132
133         verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
134     }
135
136     @Test
137     public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
138         expectedException.expect(BpmnError.class);
139
140         sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
141     }
142 }