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.service;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertTrue;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.List;
48 import javax.servlet.http.HttpServletRequest;
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.mockito.InjectMocks;
53 import org.mockito.Mock;
54 import org.mockito.Mockito;
55 import org.mockito.MockitoAnnotations;
56 import org.onap.portalapp.portal.core.MockEPUser;
57 import org.onap.portalapp.portal.ecomp.model.SearchResultItem;
58 import org.onap.portalapp.portal.framework.MockitoTestSuite;
59 import org.onap.portalapp.portal.service.DashboardSearchServiceImpl;
60 import org.onap.portalapp.portal.transport.CommonWidget;
61 import org.onap.portalapp.portal.transport.CommonWidgetMeta;
62 import org.onap.portalsdk.core.service.DataAccessService;
64 public class DashboardSearchServiceImplTest {
67 DataAccessService dataAccessService;
70 DashboardSearchServiceImpl dashboardSearchServiceImpl = new DashboardSearchServiceImpl();
74 MockitoAnnotations.initMocks(this);
77 NullPointerException nullPointerException = new NullPointerException();
78 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
79 MockEPUser mockUser = new MockEPUser();
81 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
84 public void searchResultsTest()
86 Map<String, String> params = new HashMap<>();
87 params.put("userId", "guestT");
88 params.put("searchQuery", "test");
90 List<SearchResultItem> list = new ArrayList<>();
91 SearchResultItem searchResultItem= new SearchResultItem();
92 searchResultItem.setCategory("test");
93 list.add(searchResultItem);
94 Mockito.when(dataAccessService.executeNamedQuery("searchPortal", params, null)).thenReturn(list);
95 Map<String, List<SearchResultItem>> result = dashboardSearchServiceImpl.searchResults("guestT", "test");
96 assertTrue(result.keySet().contains("test"));
100 public void getRelatedUsersTest()
102 List<String> activeUsers = new ArrayList<>();
103 Map<String, String> params = new HashMap<>();
104 params.put("userId", "guestT");
105 Mockito.when(dataAccessService.executeNamedQuery("relatedUsers", params, null)).thenReturn(activeUsers);
106 List<String> expectedActiveUsers = dashboardSearchServiceImpl.getRelatedUsers("guestT");
107 assertEquals(expectedActiveUsers,activeUsers);
110 public void getWidgetDataTest()
112 CommonWidgetMeta CommonWidgetMeta = null;
113 Map<String, String> params = new HashMap<>();
114 params.put("cat", "test");
115 @SuppressWarnings("unchecked")
116 List<CommonWidget> widgetItems = new ArrayList<>();
117 CommonWidget commonWidget = new CommonWidget();
118 widgetItems.add(commonWidget);
119 Mockito.when(dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null)).thenReturn(widgetItems);
120 CommonWidgetMeta expectedCommonWidgetMeta =dashboardSearchServiceImpl.getWidgetData("test");
121 assertEquals(expectedCommonWidgetMeta.getCategory(), "test");
125 public void saveWidgetDataBulkTest()
127 CommonWidgetMeta CommonWidgetMeta = new CommonWidgetMeta();
128 List<CommonWidget> widgetList = new ArrayList<>();
129 CommonWidget commonWidget = new CommonWidget();
130 widgetList.add(commonWidget);
131 CommonWidgetMeta.setItems(widgetList);
132 Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null);
133 assertEquals(dashboardSearchServiceImpl.saveWidgetDataBulk(CommonWidgetMeta), "success");
137 public void saveWidgetDataTest()
139 CommonWidget commonWidget = new CommonWidget();
140 Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null);
141 assertEquals(dashboardSearchServiceImpl.saveWidgetData(commonWidget), "success");
145 public void deleteWidgetDataTest()
147 CommonWidget commonWidget = new CommonWidget();
148 Mockito.doNothing().when(dataAccessService).deleteDomainObject(commonWidget, null);
149 assertEquals(dashboardSearchServiceImpl.deleteWidgetData(commonWidget), "success");