2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
43 import java.util.ArrayList;
44 import java.util.List;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.mockito.InjectMocks;
53 import org.mockito.Matchers;
54 import org.mockito.Mock;
55 import org.mockito.Mockito;
56 import org.mockito.MockitoAnnotations;
57 import org.onap.portalapp.portal.core.MockEPUser;
58 import org.onap.portalapp.portal.domain.EPUser;
59 import org.onap.portalapp.portal.domain.MicroserviceParameter;
60 import org.onap.portalapp.portal.domain.WidgetCatalog;
61 import org.onap.portalapp.portal.domain.WidgetCatalogParameter;
62 import org.onap.portalapp.portal.domain.WidgetParameterResult;
63 import org.onap.portalapp.portal.domain.WidgetServiceHeaders;
64 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
65 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
66 import org.onap.portalapp.portal.framework.MockitoTestSuite;
67 import org.onap.portalapp.portal.service.MicroserviceService;
68 import org.onap.portalapp.portal.service.MicroserviceServiceImpl;
69 import org.onap.portalapp.portal.service.WidgetMService;
70 import org.onap.portalapp.portal.service.WidgetMServiceImpl;
71 import org.onap.portalapp.portal.service.WidgetParameterService;
72 import org.onap.portalapp.portal.service.WidgetParameterServiceImpl;
73 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
74 import org.onap.portalapp.portal.utils.EcompPortalUtils;
75 import org.onap.portalapp.util.EPUserUtils;
76 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
77 import org.onap.portalsdk.core.util.SystemProperties;
78 import org.powermock.api.mockito.PowerMockito;
79 import org.powermock.core.classloader.annotations.PrepareForTest;
80 import org.powermock.modules.junit4.PowerMockRunner;
81 import org.springframework.http.HttpEntity;
82 import org.springframework.http.HttpMethod;
83 import org.springframework.http.HttpStatus;
84 import org.springframework.http.ResponseEntity;
85 import org.springframework.mock.web.MockHttpServletRequest;
86 import org.springframework.mock.web.MockHttpServletResponse;
87 import org.springframework.mock.web.MockMultipartFile;
88 import org.springframework.mock.web.MockMultipartHttpServletRequest;
89 import org.springframework.web.client.RestClientException;
90 import org.springframework.web.client.RestTemplate;
92 @SuppressWarnings("rawtypes")
93 @RunWith(PowerMockRunner.class)
94 @PrepareForTest({ EPUserUtils.class, CipherUtil.class, EcompPortalUtils.class, SystemProperties.class,
95 EPCommonSystemProperties.class, EPUserUtils.class })
96 public class WidgetsCatalogControllerTest {
99 WidgetMService widgetMService = new WidgetMServiceImpl();
102 MicroserviceService microserviceService = new MicroserviceServiceImpl();
105 WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl();
108 WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController();
111 public void setup() {
112 MockitoAnnotations.initMocks(this);
116 WidgetServiceHeaders widgetServiceHeaders;
119 RestTemplate template = new RestTemplate();
121 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
123 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
124 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
126 NullPointerException nullPointerException = new NullPointerException();
128 MockEPUser mockUser = new MockEPUser();
131 public void getUserWidgetCatalogTest() throws RestClientException, Exception {
132 PowerMockito.mockStatic(EcompPortalUtils.class);
133 PowerMockito.mockStatic(SystemProperties.class);
134 PowerMockito.mockStatic(EPCommonSystemProperties.class);
135 PowerMockito.mockStatic(CipherUtil.class);
136 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
137 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
138 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
139 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
141 Mockito.when(CipherUtil
142 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
144 List<WidgetCatalog> widgetsList = new ArrayList<>();
145 WidgetCatalog widgetCatalog = new WidgetCatalog();
146 widgetCatalog.setId(1l);
147 widgetCatalog.setName("test");
148 widgetsList.add(widgetCatalog);
149 ResponseEntity<List> ans = new ResponseEntity<>(widgetsList, HttpStatus.OK);
150 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
151 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
152 Matchers.eq(List.class))).thenReturn(ans);
153 List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT");
154 assertEquals(expectedWidgets, widgetsList);
158 public void getUserWidgetCatalogExceptionTest() throws RestClientException, Exception {
159 PowerMockito.mockStatic(EcompPortalUtils.class);
160 PowerMockito.mockStatic(SystemProperties.class);
161 PowerMockito.mockStatic(EPCommonSystemProperties.class);
162 PowerMockito.mockStatic(CipherUtil.class);
163 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
164 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
165 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
166 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
168 Mockito.when(CipherUtil
169 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
171 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
172 Mockito.doThrow(new NullPointerException()).when(template).exchange(Matchers.anyString(),
173 Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class));
174 List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT");
175 assertNull(expectedWidgets);
179 public void getWidgetCatalogTest() throws Exception {
180 PowerMockito.mockStatic(EcompPortalUtils.class);
181 PowerMockito.mockStatic(SystemProperties.class);
182 PowerMockito.mockStatic(EPCommonSystemProperties.class);
183 PowerMockito.mockStatic(CipherUtil.class);
184 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
185 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
186 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
187 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
189 Mockito.when(CipherUtil
190 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
192 List<WidgetCatalog> widgetsList = new ArrayList<>();
193 WidgetCatalog widgetCatalog = new WidgetCatalog();
194 widgetCatalog.setId(1l);
195 widgetCatalog.setName("test");
196 widgetsList.add(widgetCatalog);
197 ResponseEntity<List> ans = new ResponseEntity<>(widgetsList, HttpStatus.OK);
198 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
199 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
200 Matchers.eq(List.class))).thenReturn(ans);
201 List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getWidgetCatalog();
202 assertEquals(expectedWidgets, widgetsList);
206 public void getWidgetCatalogExceptionTest() throws Exception {
207 PowerMockito.mockStatic(EcompPortalUtils.class);
208 PowerMockito.mockStatic(SystemProperties.class);
209 PowerMockito.mockStatic(EPCommonSystemProperties.class);
210 PowerMockito.mockStatic(CipherUtil.class);
211 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
212 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
213 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
214 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
216 Mockito.when(CipherUtil
217 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
219 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
220 Mockito.doThrow(new NullPointerException()).when(template).exchange(Matchers.anyString(),
221 Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class));
222 List<WidgetCatalog> expectedWidgets = widgetsCatalogController.getUserWidgetCatalog("guestT");
223 assertNull(expectedWidgets);
227 public void updateWidgetCatalogTest() throws Exception {
228 PowerMockito.mockStatic(EcompPortalUtils.class);
229 PowerMockito.mockStatic(SystemProperties.class);
230 PowerMockito.mockStatic(EPCommonSystemProperties.class);
231 PowerMockito.mockStatic(CipherUtil.class);
232 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
233 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
234 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
235 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
237 Mockito.when(CipherUtil
238 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
240 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
241 ResponseEntity<List> ans = new ResponseEntity<>(HttpStatus.OK);
242 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
243 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT), Matchers.<HttpEntity<?>>any(),
244 Matchers.eq(List.class))).thenReturn(ans);
245 WidgetCatalog widget = new WidgetCatalog();
247 widgetsCatalogController.updateWidgetCatalog(widget, 1);
251 public void deleteOnboardingWidgetTest() throws Exception {
252 PowerMockito.mockStatic(EcompPortalUtils.class);
253 PowerMockito.mockStatic(SystemProperties.class);
254 PowerMockito.mockStatic(EPCommonSystemProperties.class);
255 PowerMockito.mockStatic(CipherUtil.class);
256 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
257 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
258 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
259 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
261 Mockito.when(CipherUtil
262 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
264 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
265 ResponseEntity<List> ans = new ResponseEntity<>(HttpStatus.OK);
266 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
267 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
268 Matchers.<HttpEntity<?>>any(), Matchers.eq(List.class))).thenReturn(ans);
269 widgetsCatalogController.deleteOnboardingWidget(1l);
272 @SuppressWarnings("unchecked")
274 public void updateWidgetCatalogWithFilesTest() throws Exception {
275 PowerMockito.mockStatic(EcompPortalUtils.class);
276 PowerMockito.mockStatic(SystemProperties.class);
277 PowerMockito.mockStatic(EPCommonSystemProperties.class);
278 PowerMockito.mockStatic(CipherUtil.class);
279 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
280 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
281 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
282 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
284 Mockito.when(CipherUtil
285 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
287 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
288 String ans = "success";
289 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
290 Mockito.when(template.postForObject(Mockito.any(String.class), Mockito.any(HttpEntity.class),
291 Mockito.any(Class.class))).thenReturn(ans);
292 MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
293 byte[] mockData = "test".getBytes();
294 String originalFilename = "Test_File.zip";
295 MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename, "application/zip",
297 request.addFile(mockMultipartFile);
298 String actual = widgetsCatalogController.updateWidgetCatalogWithFiles(request, 1l);
299 assertEquals(ans, actual);
302 @SuppressWarnings("unchecked")
304 public void createWidgetCatalogTest() throws Exception {
305 PowerMockito.mockStatic(EcompPortalUtils.class);
306 PowerMockito.mockStatic(SystemProperties.class);
307 PowerMockito.mockStatic(EPCommonSystemProperties.class);
308 PowerMockito.mockStatic(CipherUtil.class);
309 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
310 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
311 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
312 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
314 Mockito.when(CipherUtil
315 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
317 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
318 String ans = "success";
319 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
320 Mockito.when(template.postForObject(Mockito.any(String.class), Mockito.any(HttpEntity.class),
321 Mockito.any(Class.class))).thenReturn(ans);
322 MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
323 byte[] mockData = "test".getBytes();
324 String originalFilename = "Test_File.zip";
325 MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename, "application/zip",
327 request.addFile(mockMultipartFile);
328 String actual = widgetsCatalogController.createWidgetCatalog(request);
329 assertEquals(ans, actual);
332 @SuppressWarnings("unchecked")
334 public void getWidgetFrameworkTest() throws Exception {
335 PowerMockito.mockStatic(EcompPortalUtils.class);
336 PowerMockito.mockStatic(SystemProperties.class);
337 PowerMockito.mockStatic(EPCommonSystemProperties.class);
338 PowerMockito.mockStatic(CipherUtil.class);
339 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
340 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
341 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
342 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
344 Mockito.when(CipherUtil
345 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
347 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
348 Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class)))
349 .thenReturn("test123");
350 String result = widgetsCatalogController.getWidgetFramework(1l);
354 @SuppressWarnings("unchecked")
356 public void getWidgetControllerTest() throws Exception {
357 PowerMockito.mockStatic(EcompPortalUtils.class);
358 PowerMockito.mockStatic(SystemProperties.class);
359 PowerMockito.mockStatic(EPCommonSystemProperties.class);
360 PowerMockito.mockStatic(CipherUtil.class);
361 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
362 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
363 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
364 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
366 Mockito.when(CipherUtil
367 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
369 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
370 Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class)))
371 .thenReturn("test123");
372 String result = widgetsCatalogController.getWidgetController(1);
376 @SuppressWarnings("unchecked")
378 public void getWidgetCSSTest() throws Exception {
379 PowerMockito.mockStatic(EcompPortalUtils.class);
380 PowerMockito.mockStatic(SystemProperties.class);
381 PowerMockito.mockStatic(EPCommonSystemProperties.class);
382 PowerMockito.mockStatic(CipherUtil.class);
383 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
384 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
385 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
386 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
388 Mockito.when(CipherUtil
389 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
391 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
392 Mockito.when(template.getForObject(Mockito.anyString(), Mockito.any(Class.class), Mockito.any(String.class)))
393 .thenReturn("test123");
394 String result = widgetsCatalogController.getWidgetCSS(1);
399 public void getWidgetParameterResultTest() throws Exception {
400 PowerMockito.mockStatic(EcompPortalUtils.class);
401 PowerMockito.mockStatic(SystemProperties.class);
402 PowerMockito.mockStatic(EPCommonSystemProperties.class);
403 PowerMockito.mockStatic(CipherUtil.class);
404 PowerMockito.mockStatic(EPUserUtils.class);
405 EPUser user = mockUser.mockEPUser();
406 MockHttpServletRequest request = new MockHttpServletRequest();
407 Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user);
408 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
409 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
410 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
411 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
413 Mockito.when(CipherUtil
414 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
416 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
417 ResponseEntity<Long> ans = new ResponseEntity<>(1l, HttpStatus.OK);
418 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
419 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
420 Matchers.eq(Long.class))).thenReturn(ans);
421 List<MicroserviceParameter> defaultParam = new ArrayList<>();
422 MicroserviceParameter microserviceParameter = new MicroserviceParameter();
423 microserviceParameter.setId(1l);
424 microserviceParameter.setPara_key("test");
425 MicroserviceParameter microserviceParameter2 = new MicroserviceParameter();
426 microserviceParameter2.setId(2l);
427 microserviceParameter2.setPara_key("test2");
428 defaultParam.add(microserviceParameter);
429 defaultParam.add(microserviceParameter2);
430 Mockito.when(microserviceService.getParametersById(1)).thenReturn(defaultParam);
431 Mockito.when(widgetParameterService.getUserParamById(1l, user.getId(), 1l)).thenReturn(null);
432 WidgetCatalogParameter userValue = new WidgetCatalogParameter();
433 userValue.setUser_value("test123");
434 Mockito.when(widgetParameterService.getUserParamById(1l, user.getId(), 2l)).thenReturn(userValue);
435 PortalRestResponse<List<WidgetParameterResult>> actual = widgetsCatalogController
436 .getWidgetParameterResult(request, 1);
437 PortalRestResponse<List<WidgetParameterResult>> expected = new PortalRestResponse<List<WidgetParameterResult>>(
438 PortalRestStatusEnum.OK, "SUCCESS", new ArrayList<>());
439 assertEquals(expected.getStatus(), actual.getStatus());
442 @SuppressWarnings("unchecked")
444 public void doDownloadTest() throws Exception {
445 PowerMockito.mockStatic(EcompPortalUtils.class);
446 PowerMockito.mockStatic(SystemProperties.class);
447 PowerMockito.mockStatic(EPCommonSystemProperties.class);
448 PowerMockito.mockStatic(CipherUtil.class);
449 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
450 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
451 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
452 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
454 Mockito.when(CipherUtil
455 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
457 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
458 MockHttpServletRequest request = new MockHttpServletRequest();
459 MockHttpServletResponse response = new MockHttpServletResponse();
460 ResponseEntity<byte[]> mockData = new ResponseEntity("testfile.zip".getBytes(), HttpStatus.OK);
461 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
462 Matchers.eq(byte[].class))).thenReturn(mockData);
463 widgetsCatalogController.doDownload(request, response, 1l);
467 public void saveWidgetParameterTest() {
468 PowerMockito.mockStatic(EPUserUtils.class);
469 EPUser user = mockUser.mockEPUser();
470 WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter();
471 widgetCatalogParameter.setId(1l);
472 widgetCatalogParameter.setParamId(1l);
473 widgetCatalogParameter.setUserId(user.getId());
474 widgetCatalogParameter.setUser_value("test123");
475 MockHttpServletRequest request = new MockHttpServletRequest();
476 Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user);
477 Mockito.when(widgetParameterService.getUserParamById(widgetCatalogParameter.getWidgetId(),
478 widgetCatalogParameter.getUserId(), widgetCatalogParameter.getParamId())).thenReturn(widgetCatalogParameter);
479 PortalRestResponse<String> response = widgetsCatalogController.saveWidgetParameter(request,
480 widgetCatalogParameter);
481 PortalRestResponse<String> expected = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");
482 assertEquals(expected.getMessage(), response.getMessage());
486 public void saveWidgetParameterExceptionTest() {
487 PowerMockito.mockStatic(EPUserUtils.class);
488 EPUser user = mockUser.mockEPUser();
489 WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter();
490 widgetCatalogParameter.setId(1l);
491 widgetCatalogParameter.setParamId(1l);
492 widgetCatalogParameter.setUserId(user.getId());
493 widgetCatalogParameter.setUser_value("test123");
494 MockHttpServletRequest request = new MockHttpServletRequest();
495 Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user);
496 Mockito.doThrow(new NullPointerException()).when(widgetParameterService).getUserParamById(widgetCatalogParameter.getWidgetId(),
497 widgetCatalogParameter.getUserId(), widgetCatalogParameter.getParamId());
498 PortalRestResponse<String> response = widgetsCatalogController.saveWidgetParameter(request,
499 widgetCatalogParameter);
500 PortalRestResponse<String> expected = new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", "");
501 assertEquals(expected.getMessage(), response.getMessage());