417568dae787be769b59e731cf3661405501e26b
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / DashboardControllerTest.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.*;
41
42 import java.io.IOException;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.List;
46 import java.util.Map;
47
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
50
51 import org.junit.Before;
52 import org.junit.Ignore;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
55 import org.mockito.InjectMocks;
56 import org.mockito.Matchers;
57 import org.mockito.Mock;
58 import org.mockito.Mockito;
59 import org.mockito.MockitoAnnotations;
60 import org.onap.portalapp.portal.controller.DashboardController;
61 import org.onap.portalapp.portal.core.MockEPUser;
62 import org.onap.portalapp.portal.domain.EPUser;
63 import org.onap.portalapp.portal.domain.EcompAuditLog;
64 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
65 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
66 import org.onap.portalapp.portal.ecomp.model.SearchResultItem;
67 import org.onap.portalapp.portal.framework.MockitoTestSuite;
68 import org.onap.portalapp.portal.service.AdminRolesService;
69 import org.onap.portalapp.portal.service.AdminRolesServiceImpl;
70 import org.onap.portalapp.portal.service.DashboardSearchService;
71 import org.onap.portalapp.portal.service.DashboardSearchServiceImpl;
72 import org.onap.portalapp.portal.transport.CommonWidget;
73 import org.onap.portalapp.portal.transport.CommonWidgetMeta;
74 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
75 import org.onap.portalapp.portal.utils.EcompPortalUtils;
76 import org.onap.portalapp.portal.utils.PortalConstants;
77 import org.onap.portalapp.util.EPUserUtils;
78 import org.onap.portalsdk.core.domain.AuditLog;
79 import org.onap.portalsdk.core.domain.support.CollaborateList;
80 import org.onap.portalsdk.core.service.AuditService;
81 import org.onap.portalsdk.core.service.AuditServiceImpl;
82 import org.onap.portalsdk.core.util.SystemProperties;
83 import org.powermock.api.mockito.PowerMockito;
84 import org.powermock.core.classloader.annotations.PrepareForTest;
85 import org.powermock.modules.junit4.PowerMockRunner;
86 import org.springframework.beans.factory.annotation.Autowired;
87
88
89 @RunWith(PowerMockRunner.class)
90 @PrepareForTest({EPUserUtils.class, CollaborateList.class, SystemProperties.class, EPCommonSystemProperties.class})
91 public class DashboardControllerTest {
92         
93         @Mock
94         DashboardSearchService searchService = new DashboardSearchServiceImpl();
95         
96         /*@Mock
97         AuditService auditService = new AuditServiceImpl();*/
98         
99         @InjectMocks
100         DashboardController dashboardController = new DashboardController();
101
102         @Mock
103         AdminRolesService adminRolesService = new AdminRolesServiceImpl();
104         
105         @Autowired
106         AuditService auditService;
107         
108         
109         @Before
110         public void setup() {
111                 MockitoAnnotations.initMocks(this);
112         }
113
114         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
115
116         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
117         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
118
119         NullPointerException nullPointerException = new NullPointerException();
120         
121         MockEPUser mockUser = new MockEPUser();
122         
123         public CommonWidgetMeta mockCommonWidgetMeta() {
124                 CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta();
125                 List<CommonWidget> widgetList = new ArrayList<>();
126                 CommonWidget commonWidget = new CommonWidget();         
127                 commonWidget.setId((long) 1);
128                 commonWidget.setCategory("test");
129                 commonWidget.setHref("testhref");
130                 commonWidget.setTitle("testTitle");
131             commonWidget.setContent("testcontent");
132             commonWidget.setEventDate("testDate");
133             commonWidget.setSortOrder(1);                   
134                 widgetList.add(commonWidget);           
135                 commonWidgetMeta.setItems(widgetList);
136                 
137                 return commonWidgetMeta;
138         }
139         
140         public CommonWidget mockCommonWidget() {
141                 
142                 CommonWidget commonWidget = new CommonWidget();         
143                 commonWidget.setId((long) 1);
144                 commonWidget.setCategory("test");
145                 commonWidget.setHref("testhref");
146                 commonWidget.setTitle("testTitle");
147             commonWidget.setContent("testcontent");
148             commonWidget.setEventDate("testDate");
149             commonWidget.setSortOrder(1);
150             
151             return commonWidget;
152         }
153         
154         
155         @Test
156         public void getWidgetDataTest() throws IOException {
157                 
158                 String resourceType = null;
159                 PortalRestResponse<CommonWidgetMeta> expectedData = new PortalRestResponse<CommonWidgetMeta>();
160                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
161                 expectedData.setMessage("Unexpected resource type null");
162                 expectedData.setResponse(null);
163                 
164                 PortalRestResponse<CommonWidgetMeta> actualResponse =   dashboardController.getWidgetData(mockedRequest, resourceType);
165                 assertEquals(expectedData,actualResponse);              
166         }       
167         
168         @Test
169         public void getWidgetDataWithValidResourceTest() throws IOException {
170                 String resourceType = "EVENTS";
171                 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
172                 commonWidgetMeta.setCategory(null);
173                                 
174                 Mockito.when(searchService.getWidgetData(resourceType)).thenReturn(commonWidgetMeta);
175                 PortalRestResponse<CommonWidgetMeta> expectedData = new PortalRestResponse<CommonWidgetMeta>();
176                 expectedData.setStatus(PortalRestStatusEnum.OK);
177                 expectedData.setMessage("success");
178                 expectedData.setResponse(commonWidgetMeta);
179                 
180                 PortalRestResponse<CommonWidgetMeta> actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType);
181                 assertEquals(expectedData,actualResponse);
182         }
183                 
184         @Test
185         public void saveWidgetDataBulkNullTest() throws IOException {
186                 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
187                 commonWidgetMeta.setCategory(null);
188                 
189                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
190                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
191                 expectedData.setMessage("ERROR");
192                 expectedData.setResponse("Category cannot be null or empty");
193                 
194                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
195                 assertEquals(expectedData,actualResponse);              
196         }
197         
198         @Test
199         public void saveWidgetUnexpectedDataBulkTest() throws IOException {
200                 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
201                 commonWidgetMeta.setCategory("Unexpected Data");
202                 
203                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
204                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
205                 expectedData.setMessage("Unexpected resource type Unexpected Data");
206                 expectedData.setResponse(null);
207                 
208                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
209                 assertEquals(expectedData,actualResponse);
210                 
211         }
212                 
213         @Test
214         public void saveWidgetInvalidDataBulkTest() throws IOException {
215                 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
216                 commonWidgetMeta.setCategory("EVENTS");
217                 
218                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
219                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
220                 expectedData.setMessage("Invalid category: test");
221                 expectedData.setResponse(null);
222                 
223                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
224                 assertEquals(expectedData,actualResponse);              
225         }
226         
227         @Test
228         public void saveWidgetDataBulkTest() throws IOException {
229                 
230                 List<CommonWidget> widgetList = new ArrayList<>();              
231                 CommonWidget commonWidget = new CommonWidget("EVENTS", "http://test.com", "testTitle", "testcontent", "2017-07-01", 1);
232                 widgetList.add(commonWidget);
233                 CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta("EVENTS", widgetList);
234                 commonWidgetMeta.setItems(widgetList);          
235                 commonWidgetMeta.setCategory("EVENTS");         
236                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
237                 expectedData.setStatus(PortalRestStatusEnum.OK);
238                 expectedData.setMessage("success");
239                 expectedData.setResponse("success");
240                 
241                 Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn("success");
242                 
243                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
244                 assertEquals(expectedData,actualResponse);              
245         }
246         
247         @Test
248         public void saveWidgetDataNullTest() throws IOException {
249                                 
250                 CommonWidget commonWidget = mockCommonWidget(); 
251                 commonWidget.setId((long)1);
252                 commonWidget.setContent("test");
253                 commonWidget.setCategory(null);
254                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
255                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
256                 expectedData.setMessage("ERROR");
257                 expectedData.setResponse("Category cannot be null or empty");
258
259                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
260                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
261                 assertEquals(expectedData,actualResponse);
262                 
263         }
264         
265         @Test
266         public void saveWidgetDataTitleTest() throws IOException {                              
267                 CommonWidget commonWidget = mockCommonWidget(); 
268                 commonWidget.setId((long)1);
269                 commonWidget.setContent("test");
270                 commonWidget.setTitle("test");
271                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
272                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
273                 expectedData.setMessage("Invalid category: test");
274                 expectedData.setResponse(null);
275                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
276                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
277                 assertEquals(expectedData.getMessage(),actualResponse.getMessage());
278         }
279         
280         @Test
281         public void saveWidgetDataErrorTest() throws IOException {
282                                 
283                 CommonWidget commonWidget = mockCommonWidget();         
284                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
285                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
286                 expectedData.setMessage("Invalid category: test");
287                 expectedData.setResponse(null); 
288                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
289                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget,mockedRequest, mockedResponse);
290                 assertEquals(expectedData,actualResponse);              
291         }
292         
293         @Test
294         public void saveWidgetDataTest() throws IOException {
295                                 
296                 CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta();
297                 List<CommonWidget> widgetList = new ArrayList<>();
298                 CommonWidget commonWidget = new CommonWidget();         
299                 commonWidget.setId((long) 1);
300                 commonWidget.setCategory("EVENTS");
301                 commonWidget.setHref("http://test.com");
302                 commonWidget.setTitle("testTitle");
303             commonWidget.setContent("testcontent");
304             commonWidget.setEventDate("2017-07-01");
305             commonWidget.setSortOrder(1);                   
306                 widgetList.add(commonWidget);           
307                 commonWidgetMeta.setItems(widgetList);
308                 
309                 commonWidgetMeta.setCategory("EVENTS");
310                 
311                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
312                 expectedData.setStatus(PortalRestStatusEnum.OK);
313                 expectedData.setMessage("success");
314                 expectedData.setResponse("success"); 
315                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
316                 Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success");
317                 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
318                 assertEquals(expectedData,actualResponse);
319                 
320         }
321         
322         @Test
323         public void deleteWidgetDataTest() throws IOException {
324                                 
325                 CommonWidget commonWidget = mockCommonWidget();
326                 
327                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
328                 expectedData.setStatus(PortalRestStatusEnum.OK);
329                 expectedData.setMessage("success");
330                 expectedData.setResponse(null); 
331                 
332                 Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success");
333                 
334                 PortalRestResponse<String> actualResponse = dashboardController.deleteWidgetData(commonWidget);
335                 assertEquals(expectedData,actualResponse);
336                 
337         }
338                 
339         @Test
340         public void getActiveUsersTest(){
341                 List<String> activeUsers = new ArrayList<>();
342                 List<String> expectedUsersList = new ArrayList<>();
343                 EPUser user = mockUser.mockEPUser();
344                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
345                 String userId = user.getOrgUserId();
346                 Mockito.when(searchService.getRelatedUsers(userId)).thenReturn(activeUsers);
347                 expectedUsersList=      dashboardController.getActiveUsers(mockedRequest);
348                 assertEquals(expectedUsersList, activeUsers);
349         }
350         
351         
352         @Test
353         public void getActiveUsersExceptionTest(){
354                 List<String> activeUsers = new ArrayList<>();
355                 List<String> expectedUsersList = new ArrayList<>();
356                 EPUser user = mockUser.mockEPUser();
357                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
358                 String userId = user.getOrgUserId();
359                 Mockito.when(searchService.getRelatedUsers(userId)).thenThrow(nullPointerException);
360                 expectedUsersList = dashboardController.getActiveUsers(mockedRequest);
361                 assertEquals(expectedUsersList, activeUsers);
362         }
363                 
364         @Test
365         public void getOnlineUserUpdateRateTest(){
366                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
367                 expectedData.setStatus(PortalRestStatusEnum.OK);
368                 expectedData.setMessage("success");
369                 expectedData.setResponse("{onlineUserUpdateRate=1400000, onlineUserUpdateDuration=1400000}"); 
370                 
371                 PowerMockito.mockStatic(SystemProperties.class);
372                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
373                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE)).thenReturn("1400"); 
374                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION)).thenReturn("1400");
375                 
376                 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest);
377                 assertEquals(expectedData.getStatus(),actualResponse.getStatus());
378         }
379         
380         @Test
381         public void getOnlineUserUpdateRateExceptionTest(){
382                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
383                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
384                 expectedData.setMessage("java.lang.NullPointerException");
385                 expectedData.setResponse(null); 
386                 
387                 PowerMockito.mockStatic(SystemProperties.class);
388                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
389                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE)).thenThrow(nullPointerException); 
390                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION)).thenThrow(nullPointerException);
391                 
392                 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest);
393                 assertEquals(expectedData,actualResponse);
394         }
395         
396         @Test
397         public void getWindowWidthThresholdForRightMenuTest(){
398                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
399                 expectedData.setStatus(PortalRestStatusEnum.OK);
400                 expectedData.setMessage("success");
401                 expectedData.setResponse("{windowWidth=1400}"); 
402                 
403                 PowerMockito.mockStatic(SystemProperties.class);
404                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
405                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenReturn("1400");
406                 
407                 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest);
408                 assertEquals(expectedData.getStatus(),actualResponse.getStatus());
409         }
410         
411         @Test
412         public void getWindowWidthThresholdForRightMenuExceptionTest(){
413                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
414                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
415                 expectedData.setMessage("java.lang.NullPointerException");
416                 expectedData.setResponse(null); 
417                 
418                 PowerMockito.mockStatic(SystemProperties.class);
419                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
420                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenThrow(nullPointerException);
421                 
422                 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest);
423                 assertEquals(expectedData,actualResponse);
424         }
425         
426         @Test
427         public void getWindowWidthThresholdForLeftMenuTest(){
428                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
429                 expectedData.setStatus(PortalRestStatusEnum.OK);
430                 expectedData.setMessage("success");             
431                 expectedData.setResponse("{windowWidth=1400}"); 
432                 
433                 PowerMockito.mockStatic(SystemProperties.class);
434                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
435                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenReturn("1400");
436                 
437                 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest);
438                 assertEquals(expectedData.getStatus(),actualResponse.getStatus());
439         }
440         
441         @Test
442         public void getWindowWidthThresholdForLeftMenuExceptionTest(){
443                 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
444                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
445                 expectedData.setMessage("java.lang.NullPointerException");
446                 expectedData.setResponse(null); 
447                 
448                 PowerMockito.mockStatic(SystemProperties.class);
449                 PowerMockito.mockStatic(EPCommonSystemProperties.class);
450                 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenThrow(nullPointerException);
451                 
452                 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest);
453                 assertEquals(expectedData,actualResponse);
454         }
455                 
456         @Test
457         public void getActiveUsersNullTest(){
458                 PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
459                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
460                 expectedData.setMessage("User object is null? - check logs");
461                 expectedData.setResponse(new ArrayList<>()); 
462
463                 PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest);
464                 assertEquals(expectedData,actualResponse);
465         }
466         
467         @Test
468         public void activeUsersTest(){
469                 EPUser user = mockUser.mockEPUser();
470                 PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
471                 expectedData.setStatus(PortalRestStatusEnum.OK);
472                 expectedData.setMessage("success");
473                 expectedData.setResponse(new ArrayList<>()); 
474                 PowerMockito.mockStatic(EPUserUtils.class);
475                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
476                 PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest);
477                 assertEquals(expectedData,actualResponse);
478         }
479         
480         @Test
481         public void activeUsersExceptionTest(){
482                 EPUser user = mockUser.mockEPUser();
483                 user.setLoginId("test");
484                 PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
485                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
486                 expectedData.setMessage("null - check logs.");
487                 expectedData.setResponse(null);  
488                 
489                 PowerMockito.mockStatic(EPUserUtils.class);
490                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
491                 Mockito.when(searchService.getRelatedUsers(user.getLoginId())).thenThrow(nullPointerException);
492                 PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest);
493                 assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
494         }
495         @Test
496         public void searchPortalTestWhenSearchStringIsNull(){
497                 EPUser user = mockUser.mockEPUser();
498                 user.setLoginId("test");
499                 user.setId(1L);
500                 String searchString = null;
501                 //user.setLoginId("test");
502                 PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
503                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
504                 expectedData.setMessage("null - check logs.");
505                 expectedData.setResponse(Matchers.any());  
506                 
507                 PowerMockito.mockStatic(EPUserUtils.class);
508                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
509                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
510                 expectedResult.setMessage("null - check logs.");
511                 expectedResult.setResponse(null);
512                 expectedResult.setStatus(PortalRestStatusEnum.ERROR);
513                 //Mockito.doNothing().when(auditService).logActivity(auditLog, null);
514
515                 //Mockito.when(auditService.logActivity(auditLog, null).;
516                 //Mockito.when(searchService.searchResults(user.getLoginId(), searchString )).thenReturn((Map<String, List<SearchResultItem>>) expectedResult);
517                 PortalRestResponse<Map<String, List<SearchResultItem>>> actualResponse = dashboardController.searchPortal(mockedRequest, null);
518                 assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
519         }
520         
521         @Test
522         public void searchPortalTest(){
523                 EPUser user = null;
524                 String searchString = null;
525                 //user.setLoginId("test");
526                 PortalRestResponse<List<String>> expectedData = new PortalRestResponse<List<String>>();
527                 expectedData.setStatus(PortalRestStatusEnum.ERROR);
528                 expectedData.setMessage("null - check logs.");
529                 expectedData.setResponse(Matchers.any());  
530                 
531                 PowerMockito.mockStatic(EPUserUtils.class);
532                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
533                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
534                 expectedResult.setMessage("null - check logs.");
535                 expectedResult.setResponse(null);
536                 expectedResult.setStatus(PortalRestStatusEnum.ERROR);
537                 //Mockito.doNothing().when(auditService).logActivity(auditLog, null);
538
539                 //Mockito.when(auditService.logActivity(auditLog, null).;
540                 //Mockito.when(searchService.searchResults(user.getLoginId(), searchString )).thenReturn((Map<String, List<SearchResultItem>>) expectedResult);
541                 PortalRestResponse<Map<String, List<SearchResultItem>>> actualResponse = dashboardController.searchPortal(mockedRequest, null);
542                 assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
543         }
544         @Test
545         public void searchPortalTestWithException(){
546                 EPUser user = mockUser.mockEPUser();
547                 user.setLoginId("test");
548                 user.setId(1L);
549                 
550                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
551                 String searchString = "test";
552                 List<SearchResultItem> searchResultItemList = new ArrayList<SearchResultItem>();
553                 SearchResultItem searchResultItem = new SearchResultItem();
554
555                 searchResultItem.setId((long) 1);
556                 searchResultItem.setCategory("test");
557                 searchResultItem.setName("test_name");
558                 searchResultItem.setTarget("test_target");
559                 searchResultItem.setUuid("test_UUId");
560                 searchResultItemList.add(searchResultItem);
561                 Map<String, List<SearchResultItem>> expectedResultMap = new HashMap<String, List<SearchResultItem>>();
562                 expectedResultMap.put(searchString, searchResultItemList);
563                 
564                 AuditLog auditLog = new AuditLog();
565                 auditLog.setUserId(1L);
566                 auditLog.setActivityCode("test");
567                 auditLog.setComments("test");
568                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedResult = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
569                 expectedResult.setMessage("null - check logs.");
570                 expectedResult.setResponse(null);
571                 expectedResult.setStatus(PortalRestStatusEnum.ERROR);
572                 //Mockito.doNothing().when(auditService).logActivity(auditLog, null);
573
574                 //Mockito.when(auditService.logActivity(auditLog, null).;
575                 Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenReturn(expectedResultMap);
576                 PortalRestResponse<Map<String, List<SearchResultItem>>> actualResult = dashboardController.searchPortal(mockedRequest, searchString);
577                                 
578                 assertTrue(expectedResult.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
579
580         }
581         
582         @Test
583         public void searchPortalUserNullTest(){
584                 EPUser user = null;
585                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
586                 expectedData.setMessage("searchPortal: User object is null? - check logs");
587                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);               
588                 PortalRestResponse<Map<String, List<SearchResultItem>>> actualData = dashboardController.searchPortal(mockedRequest, null);
589                 assertEquals(actualData.getMessage(), expectedData.getMessage());
590         }
591         
592         @Test
593         public void searchPortalsearchStringNullTest(){
594                 EPUser user = mockUser.mockEPUser();
595                 String searchString = null;
596                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
597                 expectedData.setMessage("searchPortal: String string is null");
598                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);               
599                 PortalRestResponse<Map<String, List<SearchResultItem>>> actualData = dashboardController.searchPortal(mockedRequest, searchString);
600                 assertEquals(actualData.getMessage(), expectedData.getMessage());
601         }
602         @Ignore
603         @Test
604         public void searchPortalsearchStringTest(){
605                 EPUser user = mockUser.mockEPUser();
606                 String searchString = "test";
607                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
608                 expectedData.setMessage("success");
609                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);       
610                 Mockito.doNothing().when(auditService).logActivity(null, null);
611                 PortalRestResponse<Map<String, List<SearchResultItem>>> actualData = dashboardController.searchPortal(mockedRequest, searchString);
612                 assertEquals(actualData.getMessage(), expectedData.getMessage());
613         }
614         //@Ignore
615         @Test
616         public void searchPortalsearchStringExceptionTest(){
617                 EPUser user = mockUser.mockEPUser();
618                 String searchString = "test";
619                 PortalRestResponse<Map<String, List<SearchResultItem>>> expectedData = new PortalRestResponse<Map<String, List<SearchResultItem>>>();
620                 expectedData.setMessage("searchPortal: String string is null");
621                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);               
622                 Mockito.when(dashboardController.searchPortal(mockedRequest, searchString)).thenThrow(nullPointerException);
623         }
624         
625         
626 }