Widget MS startup fix and Onboarding changes
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / WidgetsCatalogControllerTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.portal.controller;
39
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
42
43 import java.util.ArrayList;
44 import java.util.List;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48
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;
91
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 {
97
98         @Mock
99         WidgetMService widgetMService = new WidgetMServiceImpl();
100
101         @Mock
102         MicroserviceService microserviceService = new MicroserviceServiceImpl();
103
104         @Mock
105         WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl();
106
107         @InjectMocks
108         WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController();
109
110         @Before
111         public void setup() {
112                 MockitoAnnotations.initMocks(this);
113         }
114
115         @Mock
116         WidgetServiceHeaders widgetServiceHeaders;
117
118         @Mock
119         RestTemplate template = new RestTemplate();
120
121         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
122
123         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
124         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
125
126         NullPointerException nullPointerException = new NullPointerException();
127
128         MockEPUser mockUser = new MockEPUser();
129
130         @Test
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"))
140                                 .thenReturn("test");
141                 Mockito.when(CipherUtil
142                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
143                                 .thenReturn("abc");
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);
155         }
156
157         @Test
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"))
167                                 .thenReturn("test");
168                 Mockito.when(CipherUtil
169                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
170                                 .thenReturn("abc");
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);
176         }
177
178         @Test
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"))
188                                 .thenReturn("test");
189                 Mockito.when(CipherUtil
190                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
191                                 .thenReturn("abc");
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);
203         }
204
205         @Test
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"))
215                                 .thenReturn("test");
216                 Mockito.when(CipherUtil
217                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
218                                 .thenReturn("abc");
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);
224         }
225
226         @Test
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"))
236                                 .thenReturn("test");
237                 Mockito.when(CipherUtil
238                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
239                                 .thenReturn("abc");
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();
246                 widget.setId(1l);
247                 widgetsCatalogController.updateWidgetCatalog(widget, 1);
248         }
249
250         @Test
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"))
260                                 .thenReturn("test");
261                 Mockito.when(CipherUtil
262                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
263                                 .thenReturn("abc");
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);
270         }
271
272         @SuppressWarnings("unchecked")
273         @Test
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"))
283                                 .thenReturn("test");
284                 Mockito.when(CipherUtil
285                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
286                                 .thenReturn("abc");
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",
296                                 mockData);
297                 request.addFile(mockMultipartFile);
298                 String actual = widgetsCatalogController.updateWidgetCatalogWithFiles(request, 1l);
299                 assertEquals(ans, actual);
300         }
301
302         @SuppressWarnings("unchecked")
303         @Test
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"))
313                                 .thenReturn("test");
314                 Mockito.when(CipherUtil
315                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
316                                 .thenReturn("abc");
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",
326                                 mockData);
327                 request.addFile(mockMultipartFile);
328                 String actual = widgetsCatalogController.createWidgetCatalog(request);
329                 assertEquals(ans, actual);
330         }
331
332         @SuppressWarnings("unchecked")
333         @Test
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"))
343                                 .thenReturn("test");
344                 Mockito.when(CipherUtil
345                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
346                                 .thenReturn("abc");
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);
351                 assertNull(result);
352         }
353
354         @SuppressWarnings("unchecked")
355         @Test
356         public void getWidgetCSSTest() 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"))
365                                 .thenReturn("test");
366                 Mockito.when(CipherUtil
367                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
368                                 .thenReturn("abc");
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.getWidgetCSS(1);
373                 assertNull(result);
374         }
375
376         @Test
377         public void getWidgetParameterResultTest() throws Exception {
378                 PowerMockito.mockStatic(EcompPortalUtils.class);
379                 PowerMockito.mockStatic(SystemProperties.class);
380                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
381                 PowerMockito.mockStatic(CipherUtil.class);
382                 PowerMockito.mockStatic(EPUserUtils.class);
383                 EPUser user = mockUser.mockEPUser();
384                 MockHttpServletRequest request = new MockHttpServletRequest();
385                 Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user);
386                 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
387                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
388                 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
389                 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
390                                 .thenReturn("test");
391                 Mockito.when(CipherUtil
392                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
393                                 .thenReturn("abc");
394                 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
395                 ResponseEntity<Long> ans = new ResponseEntity<>(1l, HttpStatus.OK);
396                 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
397                 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
398                                 Matchers.eq(Long.class))).thenReturn(ans);
399                 List<MicroserviceParameter> defaultParam = new ArrayList<>();
400                 MicroserviceParameter microserviceParameter = new MicroserviceParameter();
401                 microserviceParameter.setId(1l);
402                 microserviceParameter.setPara_key("test");
403                 MicroserviceParameter microserviceParameter2 = new MicroserviceParameter();
404                 microserviceParameter2.setId(2l);
405                 microserviceParameter2.setPara_key("test2");
406                 defaultParam.add(microserviceParameter);
407                 defaultParam.add(microserviceParameter2);
408                 Mockito.when(microserviceService.getParametersById(1)).thenReturn(defaultParam);
409                 Mockito.when(widgetParameterService.getUserParamById(1l, user.getId(), 1l)).thenReturn(null);
410                 WidgetCatalogParameter userValue = new WidgetCatalogParameter();
411                 userValue.setUser_value("test123");
412                 Mockito.when(widgetParameterService.getUserParamById(1l, user.getId(), 2l)).thenReturn(userValue);
413                 PortalRestResponse<List<WidgetParameterResult>> actual = widgetsCatalogController
414                                 .getWidgetParameterResult(request, 1);
415                 PortalRestResponse<List<WidgetParameterResult>> expected = new PortalRestResponse<List<WidgetParameterResult>>(
416                                 PortalRestStatusEnum.OK, "SUCCESS", new ArrayList<>());
417                 assertEquals(expected.getStatus(), actual.getStatus());
418         }
419
420         @SuppressWarnings("unchecked")
421         @Test
422         public void doDownloadTest() throws Exception {
423                 PowerMockito.mockStatic(EcompPortalUtils.class);
424                 PowerMockito.mockStatic(SystemProperties.class);
425                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
426                 PowerMockito.mockStatic(CipherUtil.class);
427                 Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1");
428                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https");
429                 Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test");
430                 Mockito.when(EcompPortalUtils.getPropertyOrDefault("microservices.widget.username", "widget_user"))
431                                 .thenReturn("test");
432                 Mockito.when(CipherUtil
433                                 .decryptPKC(EcompPortalUtils.getPropertyOrDefault("microservices.widget.password", "widget_password")))
434                                 .thenReturn("abc");
435                 Mockito.when(widgetMService.getServiceLocation("widgets-service", "test")).thenReturn("test.com");
436                 MockHttpServletRequest request = new MockHttpServletRequest();
437                 MockHttpServletResponse response = new MockHttpServletResponse();
438                 ResponseEntity<byte[]> mockData = new ResponseEntity("testfile.zip".getBytes(), HttpStatus.OK);
439                 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(),
440                                 Matchers.eq(byte[].class))).thenReturn(mockData);
441                 widgetsCatalogController.doDownload(request, response, 1l);
442         }
443
444         @Test
445         public void saveWidgetParameterTest() {
446                 PowerMockito.mockStatic(EPUserUtils.class);
447                 EPUser user = mockUser.mockEPUser();
448                 WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter();
449                 widgetCatalogParameter.setId(1l);
450                 widgetCatalogParameter.setParamId(1l);
451                 widgetCatalogParameter.setUserId(user.getId());
452                 widgetCatalogParameter.setUser_value("test123");
453                 MockHttpServletRequest request = new MockHttpServletRequest();
454                 Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user);
455                 Mockito.when(widgetParameterService.getUserParamById(widgetCatalogParameter.getWidgetId(),
456                                 widgetCatalogParameter.getUserId(), widgetCatalogParameter.getParamId())).thenReturn(widgetCatalogParameter);
457                 PortalRestResponse<String> response = widgetsCatalogController.saveWidgetParameter(request,
458                                 widgetCatalogParameter);
459                 PortalRestResponse<String> expected = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");
460                 assertEquals(expected.getMessage(), response.getMessage());
461         }
462         
463         @Test
464         public void saveWidgetParameterExceptionTest() {
465                 PowerMockito.mockStatic(EPUserUtils.class);
466                 EPUser user = mockUser.mockEPUser();
467                 WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter();
468                 widgetCatalogParameter.setId(1l);
469                 widgetCatalogParameter.setParamId(1l);
470                 widgetCatalogParameter.setUserId(user.getId());
471                 widgetCatalogParameter.setUser_value("test123");
472                 MockHttpServletRequest request = new MockHttpServletRequest();
473                 Mockito.when(EPUserUtils.getUserSession(request)).thenReturn(user);
474                 Mockito.doThrow(new NullPointerException()).when(widgetParameterService).getUserParamById(widgetCatalogParameter.getWidgetId(),
475                                 widgetCatalogParameter.getUserId(), widgetCatalogParameter.getParamId());
476                 PortalRestResponse<String> response = widgetsCatalogController.saveWidgetParameter(request,
477                                 widgetCatalogParameter);
478                 PortalRestResponse<String> expected = new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", "");
479                 assertEquals(expected.getMessage(), response.getMessage());
480         }
481 }