2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.sdnc.vnfapi;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.mockito.internal.util.reflection.Whitebox;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.data.PreloadDataBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.data.ServiceDataBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.preload.data.VfModulePreloadDataBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.service.data.VfModuleServiceDataBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.preload.data.VnfInstancePreloadDataBuilder;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.service.data.VnfInstanceServiceDataBuilder;
37 import org.slf4j.Logger;
39 import java.util.Properties;
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.*;
44 public class VNFSDNSvcLogicServiceClientTest {
45 private static final String MODE = "mode";
46 private static final String MODULE = "module";
47 private static final String RPC = "rpc";
48 private static final String VERSION = "version";
50 private Logger mockLog = mock(Logger.class);
51 private SvcLogicService mockSvcLogic = mock(SvcLogicService.class);
53 private VNFSDNSvcLogicServiceClient svcClient;
56 public void setUp() throws Exception {
57 svcClient = spy(new VNFSDNSvcLogicServiceClient(mockSvcLogic));
59 Whitebox.setInternalState(svcClient, "logger", mockLog);
60 Whitebox.setInternalState(svcClient, "svcLogic", mockSvcLogic);
64 public void testConstructorWithoutSvcLogicBundle() throws Exception {
65 VNFSDNSvcLogicServiceClient client = new VNFSDNSvcLogicServiceClient(mockSvcLogic);
66 Assert.assertEquals("Should have set mockSvcLogic",
67 mockSvcLogic, Whitebox.getInternalState(client, "svcLogic"));
70 @Test (expected = SvcLogicException.class)
71 public void testHasGraphWithException() throws Exception {
72 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).hasGraph(MODULE, RPC, VERSION, MODE);
73 svcClient.hasGraph(MODULE, RPC, VERSION, MODE);
77 public void testHasGraph() throws Exception {
78 Mockito.doReturn(true).when(mockSvcLogic).hasGraph(MODULE, RPC, VERSION, MODE);
79 Assert.assertTrue("Should return true", svcClient.hasGraph(MODULE, RPC, VERSION, MODE));
82 // --------- Test cases for ServiceDataBuilder serviceData-----------------
83 @Test (expected = SvcLogicException.class)
84 public void testExecuteWithServiceDataBuilderWithException() throws Exception {
85 ServiceDataBuilder mockBuilder = mock(ServiceDataBuilder.class);
86 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
87 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
89 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
93 public void testExecuteWithServiceDataBuilder() throws Exception {
94 ServiceDataBuilder mockBuilder = mock(ServiceDataBuilder.class);
95 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
96 Mockito.verify(svcClient, times(1)).execute(
97 any(String.class), any(String.class), any(String.class), any(String.class),
98 any(ServiceDataBuilder.class), any(Properties.class));
101 @Test (expected = SvcLogicException.class)
102 public void testParamExecuteWithServiceDataBuilderWithException() throws Exception {
103 ServiceDataBuilder mockBuilder = mock(ServiceDataBuilder.class);
104 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
105 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
107 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
111 public void testParamExecuteWithServiceDataBuilderWithExecutorReturnNull() throws Exception {
112 ServiceDataBuilder mockBuilder = mock(ServiceDataBuilder.class);
113 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
114 Assert.assertTrue("Should return null", properties == null);
115 Mockito.verify(mockSvcLogic, times(1)).execute(
116 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
120 public void testParamExecuteWithServiceDataBuilderWithExecutorReturnFailure() throws Exception {
121 ServiceDataBuilder mockBuilder = mock(ServiceDataBuilder.class);
122 Properties resultProps = new Properties();
123 resultProps.setProperty(VNFSDNSvcLogicServiceClient.SVC_LOGIC_STATUS_KEY,
124 VNFSDNSvcLogicServiceClient.FAILURE_RESULT);
125 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
126 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
127 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
128 Assert.assertEquals("Should return resultProps", resultProps, properties);
132 public void testParamExecuteWithServiceDataBuilder() throws Exception {
133 Mockito.doReturn(true).when(mockLog).isDebugEnabled();
134 ServiceDataBuilder mockBuilder = mock(ServiceDataBuilder.class);
135 Properties resultProps = new Properties();
136 resultProps.setProperty("my", "testing");
137 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
138 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
139 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
140 Assert.assertEquals("Should still return resultProps", resultProps, properties);
143 // --------- Test cases for PreloadDataBuilder serviceData-----------------
144 @Test (expected = SvcLogicException.class)
145 public void testExecuteWithPreloadDataBuilderWithException() throws Exception {
146 PreloadDataBuilder mockBuilder = mock(PreloadDataBuilder.class);
147 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
148 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
150 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
154 public void testExecuteWithPreloadDataBuilder() throws Exception {
155 PreloadDataBuilder mockBuilder = mock(PreloadDataBuilder.class);
156 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
157 Mockito.verify(svcClient, times(1)).execute(
158 any(String.class), any(String.class), any(String.class), any(String.class),
159 any(PreloadDataBuilder .class), any(Properties.class));
162 @Test (expected = SvcLogicException.class)
163 public void testParamExecuteWithPreloadDataBuilderWithException() throws Exception {
164 PreloadDataBuilder mockBuilder = mock(PreloadDataBuilder.class);
165 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
166 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
168 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
172 public void testParamExecuteWithPreloadDataBuilderWithExecutorReturnNull() throws Exception {
173 PreloadDataBuilder mockBuilder = mock(PreloadDataBuilder.class);
174 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
175 Assert.assertTrue("Should return null", properties == null);
176 Mockito.verify(mockSvcLogic, times(1)).execute(
177 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
181 public void testParamExecuteWithPreloadDataBuilderWithExecutorReturnFailure() throws Exception {
182 PreloadDataBuilder mockBuilder = mock(PreloadDataBuilder.class);
183 Properties resultProps = new Properties();
184 resultProps.setProperty(VNFSDNSvcLogicServiceClient.SVC_LOGIC_STATUS_KEY,
185 VNFSDNSvcLogicServiceClient.FAILURE_RESULT);
186 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
187 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
188 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
189 Assert.assertEquals("Should return resultProps", resultProps, properties);
193 public void testParamExecuteWithPreloadDataBuilder() throws Exception {
194 Mockito.doReturn(true).when(mockLog).isDebugEnabled();
195 PreloadDataBuilder mockBuilder = mock(PreloadDataBuilder.class);
196 Properties resultProps = new Properties();
197 resultProps.setProperty("my", "testing");
198 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
199 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
200 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
201 Assert.assertEquals("Should still return resultProps", resultProps, properties);
205 // --------- Test cases for VfModulePreloadDataBuilder serviceData-----------------
206 @Test (expected = SvcLogicException.class)
207 public void testExecuteWithVfModulePreloadDataBuilderWithException() throws Exception {
208 VfModulePreloadDataBuilder mockBuilder = mock(VfModulePreloadDataBuilder.class);
209 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
210 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
212 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
216 public void testExecuteWithVfModulePreloadDataBuilder() throws Exception {
217 VfModulePreloadDataBuilder mockBuilder = mock(VfModulePreloadDataBuilder.class);
218 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
219 Mockito.verify(svcClient, times(1)).execute(
220 any(String.class), any(String.class), any(String.class), any(String.class),
221 any(VfModulePreloadDataBuilder .class), any(Properties.class));
224 @Test (expected = SvcLogicException.class)
225 public void testParamExecuteWithVfModulePreloadDataBuilderWithException() throws Exception {
226 VfModulePreloadDataBuilder mockBuilder = mock(VfModulePreloadDataBuilder.class);
227 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
228 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
230 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
234 public void testParamExecuteWithVfModulePreloadDataBuilderWithExecutorReturnNull() throws Exception {
235 VfModulePreloadDataBuilder mockBuilder = mock(VfModulePreloadDataBuilder.class);
236 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
237 Assert.assertTrue("Should return null", properties == null);
238 Mockito.verify(mockSvcLogic, times(1)).execute(
239 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
243 public void testParamExecuteWithVfModulePreloadDataBuilderWithExecutorReturnFailure() throws Exception {
244 VfModulePreloadDataBuilder mockBuilder = mock(VfModulePreloadDataBuilder.class);
245 Properties resultProps = new Properties();
246 resultProps.setProperty(VNFSDNSvcLogicServiceClient.SVC_LOGIC_STATUS_KEY,
247 VNFSDNSvcLogicServiceClient.FAILURE_RESULT);
248 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
249 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
250 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
251 Assert.assertEquals("Should return resultProps", resultProps, properties);
255 public void testParamExecuteWithVfModulePreloadDataBuilder() throws Exception {
256 Mockito.doReturn(true).when(mockLog).isDebugEnabled();
257 VfModulePreloadDataBuilder mockBuilder = mock(VfModulePreloadDataBuilder.class);
258 Properties resultProps = new Properties();
259 resultProps.setProperty("my", "testing");
260 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
261 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
262 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
263 Assert.assertEquals("Should still return resultProps", resultProps, properties);
266 // --------- Test cases for VfModuleServiceDataBuilder serviceData-----------------
267 @Test (expected = SvcLogicException.class)
268 public void testExecuteWithVfModuleServiceDataBuilderWithException() throws Exception {
269 VfModuleServiceDataBuilder mockBuilder = mock(VfModuleServiceDataBuilder.class);
270 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
271 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
273 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
277 public void testExecuteWithVfModuleServiceDataBuilder() throws Exception {
278 VfModuleServiceDataBuilder mockBuilder = mock(VfModuleServiceDataBuilder.class);
279 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
280 Mockito.verify(svcClient, times(1)).execute(
281 any(String.class), any(String.class), any(String.class), any(String.class),
282 any(VfModuleServiceDataBuilder .class), any(Properties.class));
285 @Test (expected = SvcLogicException.class)
286 public void testParamExecuteWithVfModuleServiceDataBuilderWithException() throws Exception {
287 VfModuleServiceDataBuilder mockBuilder = mock(VfModuleServiceDataBuilder.class);
288 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
289 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
291 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
295 public void testParamExecuteWithVfModuleServiceDataBuilderWithExecutorReturnNull() throws Exception {
296 VfModuleServiceDataBuilder mockBuilder = mock(VfModuleServiceDataBuilder.class);
297 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
298 Assert.assertTrue("Should return null", properties == null);
299 Mockito.verify(mockSvcLogic, times(1)).execute(
300 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
304 public void testParamExecuteWithVfModuleServiceDataBuilderWithExecutorReturnFailure() throws Exception {
305 VfModuleServiceDataBuilder mockBuilder = mock(VfModuleServiceDataBuilder.class);
306 Properties resultProps = new Properties();
307 resultProps.setProperty(VNFSDNSvcLogicServiceClient.SVC_LOGIC_STATUS_KEY,
308 VNFSDNSvcLogicServiceClient.FAILURE_RESULT);
309 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
310 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
311 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
312 Assert.assertEquals("Should return resultProps", resultProps, properties);
316 public void testParamExecuteWithVfModuleServiceDataBuilder() throws Exception {
317 Mockito.doReturn(true).when(mockLog).isDebugEnabled();
318 VfModuleServiceDataBuilder mockBuilder = mock(VfModuleServiceDataBuilder.class);
319 Properties resultProps = new Properties();
320 resultProps.setProperty("my", "testing");
321 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
322 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
323 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
324 Assert.assertEquals("Should still return resultProps", resultProps, properties);
327 // --------- Test cases for VnfInstancePreloadDataBuilder serviceData-----------------
328 @Test (expected = SvcLogicException.class)
329 public void testExecuteWithVnfInstancePreloadDataBuilderWithException() throws Exception {
330 VnfInstancePreloadDataBuilder mockBuilder = mock(VnfInstancePreloadDataBuilder.class);
331 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
332 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
334 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
338 public void testExecuteWithVnfInstancePreloadDataBuilder() throws Exception {
339 VnfInstancePreloadDataBuilder mockBuilder = mock(VnfInstancePreloadDataBuilder.class);
340 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
341 Mockito.verify(svcClient, times(1)).execute(
342 any(String.class), any(String.class), any(String.class), any(String.class),
343 any(VnfInstancePreloadDataBuilder .class), any(Properties.class));
346 @Test (expected = SvcLogicException.class)
347 public void testParamExecuteWithVnfInstancePreloadDataBuilderWithException() throws Exception {
348 VnfInstancePreloadDataBuilder mockBuilder = mock(VnfInstancePreloadDataBuilder.class);
349 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
350 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
352 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
356 public void testParamExecuteWithVnfInstancePreloadDataBuilderWithExecutorReturnNull() throws Exception {
357 VnfInstancePreloadDataBuilder mockBuilder = mock(VnfInstancePreloadDataBuilder.class);
358 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
359 Assert.assertTrue("Should return null", properties == null);
360 Mockito.verify(mockSvcLogic, times(1)).execute(
361 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
365 public void testParamExecuteWithVnfInstancePreloadDataBuilderWithExecutorReturnFailure() throws Exception {
366 VnfInstancePreloadDataBuilder mockBuilder = mock(VnfInstancePreloadDataBuilder.class);
367 Properties resultProps = new Properties();
368 resultProps.setProperty(VNFSDNSvcLogicServiceClient.SVC_LOGIC_STATUS_KEY,
369 VNFSDNSvcLogicServiceClient.FAILURE_RESULT);
370 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
371 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
372 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
373 Assert.assertEquals("Should return resultProps", resultProps, properties);
377 public void testParamExecuteWithVnfInstancePreloadDataBuilder() throws Exception {
378 Mockito.doReturn(true).when(mockLog).isDebugEnabled();
379 VnfInstancePreloadDataBuilder mockBuilder = mock(VnfInstancePreloadDataBuilder.class);
380 Properties resultProps = new Properties();
381 resultProps.setProperty("my", "testing");
382 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
383 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
384 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
385 Assert.assertEquals("Should still return resultProps", resultProps, properties);
388 // --------- Test cases for VnfInstanceServiceDataBuilder serviceData-----------------
389 @Test (expected = SvcLogicException.class)
390 public void testExecuteWithVnfInstanceServiceDataBuilderWithException() throws Exception {
391 VnfInstanceServiceDataBuilder mockBuilder = mock(VnfInstanceServiceDataBuilder.class);
392 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
393 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
395 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
399 public void testExecuteWithVnfInstanceServiceDataBuilder() throws Exception {
400 VnfInstanceServiceDataBuilder mockBuilder = mock(VnfInstanceServiceDataBuilder.class);
401 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder);
402 Mockito.verify(svcClient, times(1)).execute(
403 any(String.class), any(String.class), any(String.class), any(String.class),
404 any(VnfInstanceServiceDataBuilder .class), any(Properties.class));
407 @Test (expected = SvcLogicException.class)
408 public void testParamExecuteWithVnfInstanceServiceDataBuilderWithException() throws Exception {
409 VnfInstanceServiceDataBuilder mockBuilder = mock(VnfInstanceServiceDataBuilder.class);
410 Mockito.doThrow(new SvcLogicException()).when(mockSvcLogic).execute(
411 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
413 svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
417 public void testParamExecuteWithVnfInstanceServiceDataBuilderWithExecutorReturnNull() throws Exception {
418 VnfInstanceServiceDataBuilder mockBuilder = mock(VnfInstanceServiceDataBuilder.class);
419 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
420 Assert.assertTrue("Should return null", properties == null);
421 Mockito.verify(mockSvcLogic, times(1)).execute(
422 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
426 public void testParamExecuteWithVnfInstanceServiceDataBuilderWithExecutorReturnFailure() throws Exception {
427 VnfInstanceServiceDataBuilder mockBuilder = mock(VnfInstanceServiceDataBuilder.class);
428 Properties resultProps = new Properties();
429 resultProps.setProperty(VNFSDNSvcLogicServiceClient.SVC_LOGIC_STATUS_KEY,
430 VNFSDNSvcLogicServiceClient.FAILURE_RESULT);
431 Mockito.doReturn(resultProps).when(mockSvcLogic).execute(
432 any(String.class), any(String.class), any(String.class), any(String.class), any(Properties.class));
433 Properties properties = svcClient.execute(MODULE, RPC, VERSION, MODE, mockBuilder, new Properties());
434 Assert.assertEquals("Should return resultProps", resultProps, properties);