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 java.util.ArrayList;
41 import java.util.List;
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
46 import org.junit.Before;
47 import org.junit.Test;
48 import org.mockito.InjectMocks;
49 import org.mockito.Mock;
50 import org.mockito.Mockito;
51 import org.mockito.MockitoAnnotations;
52 import org.onap.portalapp.portal.core.MockEPUser;
53 import org.onap.portalapp.portal.domain.EPApp;
54 import org.onap.portalapp.portal.domain.EPUser;
55 import org.onap.portalapp.portal.domain.EPUserApp;
56 import org.onap.portalapp.portal.domain.EpAppType;
57 import org.onap.portalapp.portal.domain.PersUserAppSelection;
58 import org.onap.portalapp.portal.framework.MockitoTestSuite;
59 import org.onap.portalapp.portal.service.AdminRolesService;
60 import org.onap.portalapp.portal.service.PersUserAppServiceImpl;
61 import org.onap.portalapp.portal.service.UserRolesService;
62 import org.onap.portalsdk.core.service.DataAccessService;
64 public class PersUserAppServiceImplTest {
67 DataAccessService dataAccessService;
69 AdminRolesService adminRolesService;
71 UserRolesService userRolesService;
75 MockitoAnnotations.initMocks(this);
79 PersUserAppServiceImpl persUserAppServiceImpl = new PersUserAppServiceImpl();
81 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
83 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
84 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
85 NullPointerException nullPointerException = new NullPointerException();
86 MockEPUser mockUser = new MockEPUser();
88 public EPApp getApp() {
89 EPApp app = new EPApp();
91 app.setImageUrl("test");
92 app.setAppDescription("test");
93 app.setAppNotes("test");
94 app.setLandingPage("test");
96 app.setAppRestEndpoint("test");
97 app.setAlternateLandingPage("test");
99 app.setMlAppName("test");
100 app.setMlAppAdminId("test");
101 app.setAppBasicAuthUsername("test");
102 app.setAppBasicAuthPassword("test");
104 app.setEnabled(false);
105 app.setUebKey("test");
106 app.setUebSecret("test");
107 app.setUebTopicName("test");
108 app.setAppType(EpAppType.GUI);
112 @Test(expected = IllegalArgumentException.class)
113 public void setPersUserAppValueIfUserNull() {
114 persUserAppServiceImpl.setPersUserAppValue(null, null, false, false);
118 public void setPersUserAppValueTest() {
119 EPApp app = getApp();
120 EPUser user = mockUser.mockEPUser();
121 List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>();
122 PersUserAppSelection persUserAppSelection = new PersUserAppSelection();
123 persUserAppSelection.setId((long) 1);
124 persUserAppSelectionList.add(persUserAppSelection);
125 Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null))
126 .thenReturn(persUserAppSelectionList);
127 Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserAppSelection, null);
128 persUserAppServiceImpl.setPersUserAppValue(user, app, false, true);
132 public void setPersUserAppValueIfSelectTest() {
133 EPApp app = getApp();
134 EPUser user = mockUser.mockEPUser();
135 List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>();
136 PersUserAppSelection persUserAppSelection = new PersUserAppSelection();
137 persUserAppSelection.setId((long) 1);
138 persUserAppSelectionList.add(persUserAppSelection);
139 Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null))
140 .thenReturn(persUserAppSelectionList);
141 Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null);
142 persUserAppServiceImpl.setPersUserAppValue(user, app, true, true);
146 public void setPersUserAppValueIfOpenTest() {
147 EPApp app = getApp();
149 EPUser user = mockUser.mockEPUser();
150 List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>();
151 PersUserAppSelection persUserAppSelection = new PersUserAppSelection();
152 persUserAppSelection.setId((long) 1);
153 persUserAppSelectionList.add(persUserAppSelection);
154 Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null))
155 .thenReturn(persUserAppSelectionList);
156 Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null);
157 persUserAppServiceImpl.setPersUserAppValue(user, app, true, true);
161 public void setPersUserAppValueIfAppNotOpenTest() {
162 EPApp app = getApp();
164 EPUser user = mockUser.mockEPUser();
165 List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>();
166 PersUserAppSelection persUserAppSelection = new PersUserAppSelection();
167 persUserAppSelection.setId((long) 1);
168 persUserAppSelectionList.add(persUserAppSelection);
169 Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null))
170 .thenReturn(persUserAppSelectionList);
171 Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null);
172 Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
173 List<EPUserApp> roles = new ArrayList<>();
174 EPUserApp epUserApp = new EPUserApp();
175 roles.add(epUserApp);
176 Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles);
177 persUserAppServiceImpl.setPersUserAppValue(user, app, true, false);
181 public void setPersUserAppValueIfNotPortalAdminTest() {
182 EPApp app = getApp();
184 EPUser user = mockUser.mockEPUser();
185 List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>();
186 PersUserAppSelection persUserAppSelection = new PersUserAppSelection();
187 persUserAppSelection.setId((long) 1);
188 persUserAppSelectionList.add(persUserAppSelection);
189 Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null))
190 .thenReturn(persUserAppSelectionList);
191 Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserAppSelection, null);
192 Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false);
193 List<EPUserApp> roles = new ArrayList<>();
194 EPUserApp epUserApp = new EPUserApp();
195 roles.add(epUserApp);
196 Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles);
197 persUserAppServiceImpl.setPersUserAppValue(user, app, true, false);
201 public void setPersUserAppValueNewTest() {
202 EPApp app = getApp();
204 EPUser user = mockUser.mockEPUser();
205 List<PersUserAppSelection> persUserAppSelectionList = new ArrayList<>();
206 PersUserAppSelection persUserAppSelection = new PersUserAppSelection();
207 persUserAppSelection.setId((long) 1);
208 persUserAppSelectionList.add(persUserAppSelection);
209 Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null))
210 .thenReturn(persUserAppSelectionList);
211 Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null);
212 Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
213 List<EPUserApp> roles = new ArrayList<>();
214 EPUserApp epUserApp = new EPUserApp();
215 roles.add(epUserApp);
216 Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles);
217 persUserAppServiceImpl.setPersUserAppValue(user, app, false, false);