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.*;
42 import java.io.IOException;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.List;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
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;
89 @RunWith(PowerMockRunner.class)
90 @PrepareForTest({EPUserUtils.class, CollaborateList.class, SystemProperties.class, EPCommonSystemProperties.class})
91 public class DashboardControllerTest {
94 DashboardSearchService searchService = new DashboardSearchServiceImpl();
97 AuditService auditService = new AuditServiceImpl();*/
100 DashboardController dashboardController = new DashboardController();
103 AdminRolesService adminRolesService = new AdminRolesServiceImpl();
106 AuditService auditService;
110 public void setup() {
111 MockitoAnnotations.initMocks(this);
114 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
116 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
117 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
119 NullPointerException nullPointerException = new NullPointerException();
121 MockEPUser mockUser = new MockEPUser();
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);
137 return commonWidgetMeta;
140 public CommonWidget mockCommonWidget() {
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);
156 public void getWidgetDataTest() throws IOException {
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);
164 PortalRestResponse<CommonWidgetMeta> actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType);
165 assertEquals(expectedData,actualResponse);
169 public void getWidgetDataWithValidResourceTest() throws IOException {
170 String resourceType = "EVENTS";
171 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
172 commonWidgetMeta.setCategory(null);
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);
180 PortalRestResponse<CommonWidgetMeta> actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType);
181 assertEquals(expectedData,actualResponse);
185 public void saveWidgetDataBulkNullTest() throws IOException {
186 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
187 commonWidgetMeta.setCategory(null);
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");
194 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
195 assertEquals(expectedData,actualResponse);
199 public void saveWidgetUnexpectedDataBulkTest() throws IOException {
200 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
201 commonWidgetMeta.setCategory("Unexpected Data");
203 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
204 expectedData.setStatus(PortalRestStatusEnum.ERROR);
205 expectedData.setMessage("Unexpected resource type Unexpected Data");
206 expectedData.setResponse(null);
208 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
209 assertEquals(expectedData,actualResponse);
214 public void saveWidgetInvalidDataBulkTest() throws IOException {
215 CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta();
216 commonWidgetMeta.setCategory("EVENTS");
218 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
219 expectedData.setStatus(PortalRestStatusEnum.ERROR);
220 expectedData.setMessage("Invalid category: test");
221 expectedData.setResponse(null);
223 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
224 assertEquals(expectedData,actualResponse);
228 public void saveWidgetDataBulkTest() throws IOException {
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");
241 Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn("success");
243 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta);
244 assertEquals(expectedData,actualResponse);
248 public void saveWidgetDataNullTest() throws IOException {
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");
259 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
260 PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
261 assertEquals(expectedData,actualResponse);
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());
281 public void saveWidgetDataErrorTest() throws IOException {
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);
294 public void saveWidgetDataTest() throws IOException {
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);
309 commonWidgetMeta.setCategory("EVENTS");
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);
323 public void deleteWidgetDataTest() throws IOException {
325 CommonWidget commonWidget = mockCommonWidget();
327 PortalRestResponse<String> expectedData = new PortalRestResponse<String>();
328 expectedData.setStatus(PortalRestStatusEnum.OK);
329 expectedData.setMessage("success");
330 expectedData.setResponse(null);
332 Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success");
334 PortalRestResponse<String> actualResponse = dashboardController.deleteWidgetData(commonWidget);
335 assertEquals(expectedData,actualResponse);
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);
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);
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}");
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");
376 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest);
377 assertEquals(expectedData.getStatus(),actualResponse.getStatus());
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);
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);
392 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest);
393 assertEquals(expectedData,actualResponse);
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}");
403 PowerMockito.mockStatic(SystemProperties.class);
404 PowerMockito.mockStatic(EPCommonSystemProperties.class);
405 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenReturn("1400");
407 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest);
408 assertEquals(expectedData.getStatus(),actualResponse.getStatus());
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);
418 PowerMockito.mockStatic(SystemProperties.class);
419 PowerMockito.mockStatic(EPCommonSystemProperties.class);
420 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenThrow(nullPointerException);
422 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest);
423 assertEquals(expectedData,actualResponse);
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}");
433 PowerMockito.mockStatic(SystemProperties.class);
434 PowerMockito.mockStatic(EPCommonSystemProperties.class);
435 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenReturn("1400");
437 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest);
438 assertEquals(expectedData.getStatus(),actualResponse.getStatus());
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);
448 PowerMockito.mockStatic(SystemProperties.class);
449 PowerMockito.mockStatic(EPCommonSystemProperties.class);
450 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenThrow(nullPointerException);
452 PortalRestResponse<Map<String, String>> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest);
453 assertEquals(expectedData,actualResponse);
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<>());
463 PortalRestResponse<List<String>> actualResponse = dashboardController.activeUsers(mockedRequest);
464 assertEquals(expectedData,actualResponse);
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);
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);
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);
496 public void searchPortalTestWhenSearchStringIsNull(){
497 EPUser user = mockUser.mockEPUser();
498 user.setLoginId("test");
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());
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);
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);
522 public void searchPortalTest(){
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());
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);
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);
545 public void searchPortalTestWithException(){
546 EPUser user = mockUser.mockEPUser();
547 user.setLoginId("test");
550 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
551 String searchString = "test";
552 List<SearchResultItem> searchResultItemList = new ArrayList<SearchResultItem>();
553 SearchResultItem searchResultItem = new SearchResultItem();
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);
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);
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);
578 assertTrue(expectedResult.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0);
583 public void searchPortalUserNullTest(){
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());
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());
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());
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);