Security/ Package Name changes
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / DashboardSearchServiceImplTest.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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.service;
39
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertTrue;
42
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
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;
63
64 public class DashboardSearchServiceImplTest {
65         
66         @Mock
67         DataAccessService dataAccessService;
68         
69         @InjectMocks
70         DashboardSearchServiceImpl dashboardSearchServiceImpl = new DashboardSearchServiceImpl();
71
72         @Before
73         public void setup() {
74                 MockitoAnnotations.initMocks(this);
75         }
76
77         NullPointerException nullPointerException = new NullPointerException();
78         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
79         MockEPUser mockUser = new MockEPUser();
80
81         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
82     
83         @Test
84         public void searchResultsTest()
85         {
86                 Map<String, String> params = new HashMap<>();
87                 params.put("userId", "guestT");
88                 params.put("searchQuery", "test");
89                 
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"));
97         }
98         
99         @Test
100         public void getRelatedUsersTest()
101         {
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);
108         }
109         @Test
110         public void getWidgetDataTest()
111         {
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");
122         }
123         
124         @Test
125         public void saveWidgetDataBulkTest()
126         {
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");
134         }
135         
136         @Test
137         public void saveWidgetDataTest()
138         {
139                 CommonWidget commonWidget = new CommonWidget();
140                 Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null);
141                  assertEquals(dashboardSearchServiceImpl.saveWidgetData(commonWidget), "success");
142         }
143         
144         @Test
145         public void deleteWidgetDataTest()
146         {
147                 CommonWidget commonWidget = new CommonWidget();
148                 Mockito.doNothing().when(dataAccessService).deleteDomainObject(commonWidget, null);
149                  assertEquals(dashboardSearchServiceImpl.deleteWidgetData(commonWidget), "success");
150         }
151 }