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.assertEquals;
41 import static org.junit.Assert.assertNull;
43 import java.io.BufferedReader;
44 import java.io.ByteArrayInputStream;
45 import java.io.IOException;
46 import java.io.PrintWriter;
47 import java.io.StringReader;
48 import java.io.StringWriter;
49 import java.nio.charset.StandardCharsets;
50 import java.util.ArrayList;
51 import java.util.HashMap;
52 import java.util.List;
54 import java.util.SortedSet;
55 import java.util.TreeSet;
57 import javax.servlet.http.HttpServletRequest;
58 import javax.servlet.http.HttpServletResponse;
60 import org.json.simple.JSONObject;
61 import org.junit.Before;
62 import org.junit.Test;
63 import org.junit.runner.RunWith;
64 import org.mockito.InjectMocks;
65 import org.mockito.Matchers;
66 import org.mockito.Mock;
67 import org.mockito.Mockito;
68 import org.mockito.MockitoAnnotations;
69 import org.onap.portalapp.controller.core.RoleController;
70 import org.onap.portalapp.controller.core.RoleFunctionListController;
71 import org.onap.portalapp.controller.core.RoleListController;
72 import org.onap.portalapp.portal.core.MockEPUser;
73 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
74 import org.onap.portalapp.portal.domain.CentralizedApp;
75 import org.onap.portalapp.portal.domain.EPApp;
76 import org.onap.portalapp.portal.domain.EPUser;
77 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
78 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
79 import org.onap.portalapp.portal.framework.MockitoTestSuite;
80 import org.onap.portalapp.portal.service.AdminRolesService;
81 import org.onap.portalapp.portal.service.EPAppService;
82 import org.onap.portalapp.portal.service.ExternalAccessRolesService;
83 import org.onap.portalapp.portal.transport.CentralV2Role;
84 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
85 import org.onap.portalapp.portal.utils.EcompPortalUtils;
86 import org.onap.portalapp.util.EPUserUtils;
87 import org.onap.portalsdk.core.domain.Role;
88 import org.onap.portalsdk.core.service.AuditService;
89 import org.powermock.api.mockito.PowerMockito;
90 import org.powermock.core.classloader.annotations.PrepareForTest;
91 import org.powermock.modules.junit4.PowerMockRunner;
92 import org.springframework.http.HttpStatus;
93 import org.springframework.http.ResponseEntity;
94 import org.springframework.mock.web.DelegatingServletInputStream;
95 import org.springframework.web.servlet.ModelAndView;
97 import com.fasterxml.jackson.databind.JsonNode;
98 import com.fasterxml.jackson.databind.ObjectMapper;
100 @RunWith(PowerMockRunner.class)
101 @PrepareForTest({ EPUserUtils.class, EcompPortalUtils.class })
102 public class RoleManageControllerTest {
105 RoleController roleController;
108 RoleListController roleListController;
111 RoleFunctionListController roleFunctionListController;
114 ExternalAccessRolesService externalAccessRolesService;
116 EPUserUtils ePUserUtils = new EPUserUtils();
119 ExternalAccessRolesService externalAccessRolesService1 = null;
122 RoleManageController roleManageController = new RoleManageController();
125 EPAppService appService;
128 AuditService auditService;
131 AdminRolesService adminRolesService;
134 public void setup() {
135 MockitoAnnotations.initMocks(this);
138 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
140 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
141 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
142 NullPointerException nullPointerException = new NullPointerException();
143 MockEPUser mockUser = new MockEPUser();
145 private DelegatingServletInputStream dsi;
148 public void removeRoleRoleFunctionTest() throws Exception {
150 ModelAndView modelandView = new ModelAndView("login.htm");
151 Mockito.when(roleController.removeRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView);
152 ModelAndView expectedModelandView = roleManageController.removeRoleRoleFunction(mockedRequest, mockedResponse);
153 assertEquals(expectedModelandView, modelandView);
157 public void addRoleRoRoleFunctionTest() throws Exception {
158 ModelAndView modelandView = new ModelAndView("login.htm");
159 Mockito.when(roleController.addRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView);
160 ModelAndView expectedModelandView = roleManageController.addRoleRoRoleFunction(mockedRequest, mockedResponse);
161 assertEquals(expectedModelandView, modelandView);
165 public void removeChildRoleTest() throws Exception {
166 ModelAndView modelandView = new ModelAndView("login.htm");
167 Mockito.when(roleController.removeChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
168 ModelAndView expectedModelandView = roleManageController.removeChildRole(mockedRequest, mockedResponse);
169 assertEquals(expectedModelandView, modelandView);
173 public void getRoleIfRoleIdNullTest() throws Exception {
174 PowerMockito.mockStatic(EPUserUtils.class);
175 PowerMockito.mockStatic(EcompPortalUtils.class);
176 EPUser user = mockUser.mockEPUser();
177 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
178 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
179 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
180 Mockito.when(adminRolesService.isAccountAdminOfApplication(user, CentralApp())).thenReturn(true);
181 List<EPApp> apps = new ArrayList<>();
182 apps.add(CentralApp());
183 Mockito.when(externalAccessRolesService.getApp(CentralApp().getUebKey())).thenReturn(apps);
184 ResponseEntity<String> result = new ResponseEntity<>(HttpStatus.OK);
185 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(apps.get(0))).thenReturn(result);
186 CentralV2Role answer = new CentralV2Role();
187 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer);
188 List<CentralV2RoleFunction> finalRoleFunctionList = new ArrayList<>();
189 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(finalRoleFunctionList);
190 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(null);
191 StringWriter sw = new StringWriter();
192 PrintWriter writer = new PrintWriter(sw);
193 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
194 List<EPApp> appList = new ArrayList<>();
195 appList.add(CentralApp());
196 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
197 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
198 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
199 roleManageController.getRole(mockedRequest, mockedResponse, (long) 1, null);
202 @Test(expected = Exception.class)
203 public void getRoleExceptionTest() throws Exception {
204 Mockito.when(appService.getApp((long) 1)).thenReturn(mockApp());
205 CentralV2Role answer = new CentralV2Role();
206 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer);
207 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenThrow(nullPointerException);
208 roleManageController.getRole(mockedRequest, mockedResponse, (long) 1, null);
213 public void getRoleIfRoleIdNotNullTest() throws Exception {
214 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
215 CentralV2Role answer = new CentralV2Role();
216 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer);
217 List<CentralV2RoleFunction> finalRoleFunctionList = new ArrayList<>();
218 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(finalRoleFunctionList);
219 StringWriter sw = new StringWriter();
220 PrintWriter writer = new PrintWriter(sw);
221 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
222 CentralV2Role currentRole = new CentralV2Role();
223 SortedSet<CentralV2Role> parentRoles = new TreeSet<>();
224 CentralV2Role centralV2Role = new CentralV2Role();
225 centralV2Role.setName("test");
226 parentRoles.add(centralV2Role);
227 currentRole.setParentRoles(parentRoles);
228 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(currentRole);
229 List<CentralV2Role> availableChildRoles = new ArrayList<>();
230 availableChildRoles.add(currentRole);
231 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(availableChildRoles);
232 List<EPApp> appList = new ArrayList<>();
233 appList.add(CentralApp());
234 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
235 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
236 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
237 roleManageController.getRole(mockedRequest, mockedResponse, (long) 1, (long) 1);
240 public EPApp mockApp() {
241 EPApp app = new EPApp();
244 app.setImageUrl("test");
245 app.setDescription("test");
246 app.setNotes("test");
249 app.setAppRestEndpoint("test");
250 app.setAlternateUrl("test");
252 app.setMlAppName("test");
253 app.setMlAppAdminId("test");
254 app.setUsername("test");
255 app.setAppPassword("test");
257 app.setEnabled(false);
258 app.setUebKey("test");
259 app.setUebSecret("test");
260 app.setUebTopicName("test");
267 public void getRolesTest() throws Exception {
268 EPApp app = mockApp();
269 app.setCentralAuth(true);
270 PowerMockito.mockStatic(EPUserUtils.class);
271 PowerMockito.mockStatic(EcompPortalUtils.class);
272 EPUser user = mockUser.mockEPUser();
273 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
274 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
275 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
276 Mockito.when(adminRolesService.isAccountAdminOfApplication(user, app)).thenReturn(true);
277 List<CentralV2Role> answer = new ArrayList<>();
278 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
279 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(answer);
280 StringWriter sw = new StringWriter();
281 PrintWriter writer = new PrintWriter(sw);
282 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
283 List<EPApp> appList = new ArrayList<>();
284 appList.add(CentralApp());
285 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
286 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
287 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
288 roleManageController.getRoles(mockedRequest, mockedResponse, (long) 1);
292 public void getRolesExceptionTest() throws Exception {
293 EPApp app = CentralApp();
294 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
295 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenThrow(new java.lang.Exception());
296 roleManageController.getRoles(mockedRequest, mockedResponse, (long) 1);
301 public void getRoleFunctionListTest() throws Exception {
302 PowerMockito.mockStatic(EPUserUtils.class);
303 PowerMockito.mockStatic(EcompPortalUtils.class);
304 EPUser user = mockUser.mockEPUser();
305 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
306 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
307 Mockito.when(adminRolesService.isAccountAdminOfApplication(user, CentralApp())).thenReturn(true);
308 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
309 List<CentralV2RoleFunction> answer = new ArrayList<>();
310 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(answer);
311 StringWriter sw = new StringWriter();
312 PrintWriter writer = new PrintWriter(sw);
313 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
314 List<EPApp> appList = new ArrayList<>();
315 appList.add(CentralApp());
316 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
317 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
318 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
319 roleManageController.getRoleFunctionList(mockedRequest, mockedResponse, (long) 1);
322 @Test(expected = Exception.class)
323 public void getRoleFunctionListExceptionTest() throws Exception {
324 Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp());
325 roleManageController.getRoleFunctionList(mockedRequest, mockedResponse, (long) 1);
329 public void saveRoleFunctionTest() throws Exception {
330 PowerMockito.mockStatic(EPUserUtils.class);
331 PowerMockito.mockStatic(EcompPortalUtils.class);
332 EPUser user = mockUser.mockEPUser();
333 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
334 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
335 Mockito.when(adminRolesService.isAccountAdminOfApplication(user, CentralApp())).thenReturn(true);
336 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
337 Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test");
338 CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction();
339 addNewFunc.setCode("Test");
340 addNewFunc.setType("Test");
341 addNewFunc.setAction("Test");
342 addNewFunc.setName("Test");
343 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
344 roleFunction.setCode("Test|Test|Test");
345 Mockito.when(externalAccessRolesService.getRoleFunction("Test|Test|Test", "test")).thenReturn(roleFunction);
346 Mockito.when(externalAccessRolesService.saveCentralRoleFunction(Matchers.anyObject(), Matchers.anyObject()))
348 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunction.getCode())).thenReturn("Test");
349 Mockito.when(EcompPortalUtils.getFunctionType(roleFunction.getCode())).thenReturn("Test");
350 Mockito.when(EcompPortalUtils.getFunctionAction(roleFunction.getCode())).thenReturn("Test");
351 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
352 List<EPUser> userList = new ArrayList<>();
354 List<EPApp> appList = new ArrayList<>();
355 appList.add(CentralApp());
356 Mockito.when(externalAccessRolesService.getUser("guestT")).thenReturn(userList);
357 StringWriter sw = new StringWriter();
358 PrintWriter writer = new PrintWriter(sw);
359 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
360 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
361 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
362 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
363 PortalRestResponse<String> actual = roleManageController.saveRoleFunction(mockedRequest, mockedResponse,
364 addNewFunc, (long) 1);
365 PortalRestResponse<String> expected = new PortalRestResponse<String>(PortalRestStatusEnum.OK,
366 "Saved Successfully!", "Success");
367 assertEquals(expected, actual);
371 public void saveRoleFunctionExceptionTest() throws Exception {
372 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
373 Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test");
374 CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction();
375 addNewFunc.setCode("Test");
376 addNewFunc.setName("Test");
377 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(null);
378 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1);
382 public void saveRoleFunctionIfAppNotCentralizedTest() throws Exception {
383 CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction();
384 addNewFunc.setCode("Test");
385 addNewFunc.setName("Test");
386 Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp());
387 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1);
391 public void removeRoleFunctionTest() throws Exception {
392 PowerMockito.mockStatic(EPUserUtils.class);
393 PowerMockito.mockStatic(EcompPortalUtils.class);
394 EPUser user = mockUser.mockEPUser();
395 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
396 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
397 Mockito.when(adminRolesService.isAccountAdminOfApplication(user, CentralApp())).thenReturn(true);
398 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
399 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
400 String roleFun = "{\"name\":\"Test\",\"type\":\"Test\",\"action\":\"Test\", \"code\":\"Test\"}";
401 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
402 Mockito.when(externalAccessRolesService.getRoleFunction("Test|Test|Test", "test")).thenReturn(roleFunction);
403 StringWriter sw = new StringWriter();
404 PrintWriter writer = new PrintWriter(sw);
405 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
406 Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject()))
408 List<EPApp> appList = new ArrayList<>();
409 appList.add(CentralApp());
410 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
411 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
412 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
413 PortalRestResponse<String> actual = roleManageController.removeRoleFunction(mockedRequest, mockedResponse,
415 PortalRestResponse<String> expected = new PortalRestResponse<String>(PortalRestStatusEnum.OK,
416 "Deleted Successfully!", "Success");
417 assertEquals(expected, actual);
421 public void removeRoleFunctionExceptionTest() throws Exception {
422 EPUser user = mockUser.mockEPUser();
423 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
424 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
425 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
426 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
427 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction);
428 StringWriter sw = new StringWriter();
429 PrintWriter writer = new PrintWriter(sw);
430 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
431 Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject()))
433 List<EPApp> appList = new ArrayList<>();
434 appList.add(CentralApp());
435 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
436 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
437 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
438 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
442 public void removeRoleFunctionIfAppNotCentralizedTest() throws Exception {
443 EPApp app = mockApp();
444 app.setCentralAuth(false);
445 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
446 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
447 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
451 public void syncRolesTest() throws Exception {
452 PowerMockito.mockStatic(EPUserUtils.class);
453 PowerMockito.mockStatic(EcompPortalUtils.class);
454 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
455 EPUser user = mockUser.mockEPUser();
456 EPApp app = mockApp();
458 Mockito.when(appService.getApp(1l)).thenReturn(app);
459 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
460 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
461 Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
462 List<EPApp> appList = new ArrayList<>();
463 appList.add(CentralApp());
464 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
465 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
466 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
467 PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
468 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
469 portalRestResponse.setMessage("Sync roles completed successfully!");
470 portalRestResponse.setResponse("Success");
471 portalRestResponse.setStatus(PortalRestStatusEnum.OK);
472 assertEquals(portalRestResponse, actual);
476 public void syncRolesException() throws Exception {
477 Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
478 PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
479 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
480 portalRestResponse.setMessage(null);
481 portalRestResponse.setResponse("Failed");
482 portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
483 assertEquals(portalRestResponse, actual);
487 public void syncRolesFunctionsTest() throws Exception {
488 PowerMockito.mockStatic(EPUserUtils.class);
489 PowerMockito.mockStatic(EcompPortalUtils.class);
490 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
491 EPApp app = mockApp();
493 EPUser user = mockUser.mockEPUser();
494 Mockito.when(appService.getApp(1l)).thenReturn(app);
495 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
496 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
497 Mockito.doNothing().when(externalAccessRolesService).syncRoleFunctionFromExternalAccessSystem(app);
498 List<EPApp> appList = new ArrayList<>();
499 appList.add(CentralApp());
500 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
501 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
502 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
503 PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
504 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
505 portalRestResponse.setMessage("Sync Functions completed successfully!");
506 portalRestResponse.setResponse("Success");
507 portalRestResponse.setStatus(PortalRestStatusEnum.OK);
508 assertEquals(portalRestResponse, actual);
512 public void syncRolesFunctionsException() throws Exception {
513 Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
514 PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
515 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
516 portalRestResponse.setMessage(null);
517 portalRestResponse.setResponse("Failed");
518 portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
519 assertEquals(portalRestResponse, actual);
523 public void addChildRoleTest() throws Exception {
524 ModelAndView modelandView = new ModelAndView("login.htm");
525 Mockito.when(roleController.addChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
526 ModelAndView expectedModelandView = roleManageController.addChildRole(mockedRequest, mockedResponse);
527 assertEquals(expectedModelandView, modelandView);
531 public void removeRoleTest() throws Exception {
532 PowerMockito.mockStatic(EPUserUtils.class);
533 PowerMockito.mockStatic(EcompPortalUtils.class);
534 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
535 List<EPUser> epuserList = new ArrayList<>();
536 List<EPApp> appList = new ArrayList<>();
537 appList.add(CentralApp());
538 EPUser user = mockUser.mockEPUser();
539 epuserList.add(user);
540 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
541 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
542 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
543 StringWriter sw = new StringWriter();
544 PrintWriter writer = new PrintWriter(sw);
545 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
546 ExternalRequestFieldsValidator res = new ExternalRequestFieldsValidator(true, "success");
547 Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(), Matchers.anyString(),
548 Matchers.anyString())).thenReturn(res);
549 Mockito.when(externalAccessRolesService.getUser(Matchers.anyString())).thenReturn(epuserList);
550 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
551 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
552 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
553 Map<String, Object> expedtedResponse = new HashMap<String, Object>();
554 expedtedResponse.put("restCallStatus", " Unauthorized user");
555 expedtedResponse.put("availableRoles", new ArrayList<>());
556 Map<String, Object> actualResponse = roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1,
558 assertEquals(actualResponse.size(), expedtedResponse.size());
562 @Test(expected = Exception.class)
563 public void removeRoleExceptionTest() throws Exception {
564 EPUser user = mockUser.mockEPUser();
565 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
566 Mockito.when(appService.getApp((long) 1)).thenThrow(nullPointerException);
567 StringWriter sw = new StringWriter();
568 PrintWriter writer = new PrintWriter(sw);
569 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
570 roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1);
573 @SuppressWarnings("unchecked")
575 public void saveRoleNewTest() throws Exception {
576 PowerMockito.mockStatic(EPUserUtils.class);
577 PowerMockito.mockStatic(EcompPortalUtils.class);
578 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
579 List<EPUser> epuserList = new ArrayList<>();
580 List<EPApp> appList = new ArrayList<>();
581 appList.add(CentralApp());
582 EPUser user = mockUser.mockEPUser();
583 epuserList.add(user);
584 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
585 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
586 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
587 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
588 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
589 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
590 JSONObject roleJson = new JSONObject();
591 roleJson.put("name", "test");
592 JSONObject roleJson2 = new JSONObject();
593 List<JSONObject> childRolesJson = new ArrayList<>();
594 List<JSONObject> roleFunctions = new ArrayList<>();
595 roleJson2.put("role", roleJson);
596 roleJson2.put("childRoles", childRolesJson);
597 roleJson2.put("roleFunctions", roleFunctions);
598 ObjectMapper mapper = new ObjectMapper();
599 JsonNode actualObj = mapper.readTree(roleJson2.toString());
600 dsi = new DelegatingServletInputStream(
601 new ByteArrayInputStream(actualObj.toString().getBytes(StandardCharsets.UTF_8)));
602 Mockito.when(mockedRequest.getInputStream()).thenReturn(dsi);
603 Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(actualObj.toString())));
604 Mockito.when(mockedRequest.getContentType()).thenReturn("application/json");
605 Mockito.when(mockedRequest.getCharacterEncoding()).thenReturn("UTF-8");
606 Mockito.when(externalAccessRolesService.ConvertCentralRoleToRole(Matchers.anyString())).thenReturn(new Role());
607 ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, "");
608 Mockito.when(externalAccessRolesService.saveRoleForApplication(Matchers.any(), Matchers.any()))
609 .thenReturn(externalRequestFieldsValidator);
610 Map<String, Object> actual = roleManageController.saveRole(mockedRequest, mockedResponse, CentralApp().getId());
611 final Map<String, Object> expected = new HashMap<>();
612 expected.put("role", new CentralV2Role(null, "test"));
613 expected.put("status", "Success");
614 assertEquals(expected, actual);
617 @SuppressWarnings("unchecked")
619 public void saveRoleUpdateTest() throws Exception {
620 PowerMockito.mockStatic(EPUserUtils.class);
621 PowerMockito.mockStatic(EcompPortalUtils.class);
622 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
623 List<EPUser> epuserList = new ArrayList<>();
624 List<EPApp> appList = new ArrayList<>();
625 appList.add(CentralApp());
626 EPUser user = mockUser.mockEPUser();
627 epuserList.add(user);
628 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
629 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
630 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
631 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
632 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
633 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
634 JSONObject roleJson = new JSONObject();
635 roleJson.put("id", 1);
636 roleJson.put("name", "test");
637 roleJson.put("active", true);
638 JSONObject roleJson2 = new JSONObject();
639 List<JSONObject> childRolesJson = new ArrayList<>();
640 List<JSONObject> roleFunctions = new ArrayList<>();
641 JSONObject roleFunction = new JSONObject();
642 roleFunction.put("code", "test");
643 roleFunction.put("name", "test");
644 roleFunction.put("type", "test");
645 roleFunction.put("action", "test");
646 roleFunctions.add(roleFunction);
647 roleJson.put("roleFunctions", roleFunctions);
648 roleJson2.put("role", roleJson);
649 roleJson2.put("childRoles", childRolesJson);
650 roleJson2.put("roleFunctions", roleFunctions);
651 ObjectMapper mapper = new ObjectMapper();
652 JsonNode actualObj = mapper.readTree(roleJson2.toString());
653 dsi = new DelegatingServletInputStream(
654 new ByteArrayInputStream(actualObj.toString().getBytes(StandardCharsets.UTF_8)));
655 Mockito.when(mockedRequest.getInputStream()).thenReturn(dsi);
656 Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(actualObj.toString())));
657 Mockito.when(mockedRequest.getContentType()).thenReturn("application/json");
658 Mockito.when(mockedRequest.getCharacterEncoding()).thenReturn("UTF-8");
659 Mockito.when(externalAccessRolesService.ConvertCentralRoleToRole(Matchers.anyString())).thenReturn(new Role());
660 ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, "");
661 Mockito.when(externalAccessRolesService.saveRoleForApplication(Matchers.any(), Matchers.any()))
662 .thenReturn(externalRequestFieldsValidator);
663 CentralV2Role cenV2Role = new CentralV2Role(1l, "test1");
664 cenV2Role.setActive(true);
665 Mockito.when(externalAccessRolesService.getRoleInfo(Matchers.anyLong(), Matchers.any())).thenReturn(cenV2Role);
666 Map<String, Object> actual = roleManageController.saveRole(mockedRequest, mockedResponse, CentralApp().getId());
667 final Map<String, Object> expected = new HashMap<>();
668 expected.put("status", "Success");
669 assertEquals(expected.get("status"), actual.get("status"));
672 @SuppressWarnings("unchecked")
674 public void saveRoleInvalidRoleExceptionTest() throws Exception {
675 PowerMockito.mockStatic(EPUserUtils.class);
676 PowerMockito.mockStatic(EcompPortalUtils.class);
677 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
678 List<EPUser> epuserList = new ArrayList<>();
679 List<EPApp> appList = new ArrayList<>();
680 appList.add(CentralApp());
681 EPUser user = mockUser.mockEPUser();
682 epuserList.add(user);
683 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
684 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
685 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
686 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
687 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
688 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
689 JSONObject roleJson = new JSONObject();
690 roleJson.put("id", 1);
691 roleJson.put("name", "test%%");
692 roleJson.put("active", true);
693 JSONObject roleJson2 = new JSONObject();
694 List<JSONObject> childRolesJson = new ArrayList<>();
695 List<JSONObject> roleFunctions = new ArrayList<>();
696 JSONObject roleFunction = new JSONObject();
697 roleFunction.put("code", "test");
698 roleFunction.put("name", "test");
699 roleFunction.put("type", "test");
700 roleFunction.put("action", "test");
701 roleFunctions.add(roleFunction);
702 roleJson.put("roleFunctions", roleFunctions);
703 roleJson2.put("role", roleJson);
704 roleJson2.put("childRoles", childRolesJson);
705 roleJson2.put("roleFunctions", roleFunctions);
706 ObjectMapper mapper = new ObjectMapper();
707 JsonNode actualObj = mapper.readTree(roleJson2.toString());
708 dsi = new DelegatingServletInputStream(
709 new ByteArrayInputStream(actualObj.toString().getBytes(StandardCharsets.UTF_8)));
710 Mockito.when(mockedRequest.getInputStream()).thenReturn(dsi);
711 Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(actualObj.toString())));
712 Mockito.when(mockedRequest.getContentType()).thenReturn("application/json");
713 Mockito.when(mockedRequest.getCharacterEncoding()).thenReturn("UTF-8");
714 Map<String, Object> actual = roleManageController.saveRole(mockedRequest, mockedResponse, CentralApp().getId());
715 final Map<String, Object> expected = new HashMap<>();
716 expected.put("error", "Invalid role name found for 'test%%'. Any one of the following characters '%,(),=,:,comma, and double quotes' are not allowed");
717 assertEquals(expected.get("error"), actual.get("error"));
721 public void saveRoleUnauthorizedUserExceptionTest() throws Exception {
722 PowerMockito.mockStatic(EPUserUtils.class);
723 PowerMockito.mockStatic(EcompPortalUtils.class);
724 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
725 List<EPUser> epuserList = new ArrayList<>();
726 List<EPApp> appList = new ArrayList<>();
727 appList.add(CentralApp());
728 EPUser user = mockUser.mockEPUser();
729 epuserList.add(user);
730 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
731 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
732 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(false);
733 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
734 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
735 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
736 Map<String, Object> actual = roleManageController.saveRole(mockedRequest, mockedResponse, CentralApp().getId());
737 final Map<String, Object> expected = new HashMap<>();
738 expected.put("error", " Unauthorized user");
739 assertEquals(expected.get("error"), actual.get("error"));
743 public void toggleRoleTest() throws Exception {
744 PowerMockito.mockStatic(EPUserUtils.class);
745 PowerMockito.mockStatic(EcompPortalUtils.class);
746 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
747 List<EPUser> epuserList = new ArrayList<>();
748 List<EPApp> appList = new ArrayList<>();
749 appList.add(CentralApp());
750 EPUser user = mockUser.mockEPUser();
751 epuserList.add(user);
752 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
753 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
754 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
755 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
756 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
757 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
758 CentralV2Role role = new CentralV2Role(1l, "test");
759 role.setActive(true);
760 Role currentRole = new Role();
761 currentRole.setName("test");
762 Mockito.when(externalAccessRolesService.getRoleInfo(Matchers.anyLong(), Matchers.any())).thenReturn(role);
763 Mockito.when(externalAccessRolesService.ConvertCentralRoleToRole(Matchers.anyString())).thenReturn(currentRole);
764 ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, "");
765 Mockito.when(externalAccessRolesService.saveRoleForApplication(Matchers.any(),Matchers.any())).thenReturn(externalRequestFieldsValidator);
766 Map<String, Object> actual = roleManageController.toggleRole(mockedRequest, mockedResponse, CentralApp().getId(), 1l);
767 final Map<String, Object> expected = new HashMap<>();
768 expected.put("restcallStatus", "Success");
769 assertEquals(expected.get("restcallStatus"), actual.get("restcallStatus"));
773 public void toggleRoleUnauthorizedUserExceptionTest() throws Exception {
774 PowerMockito.mockStatic(EPUserUtils.class);
775 PowerMockito.mockStatic(EcompPortalUtils.class);
776 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
777 List<EPUser> epuserList = new ArrayList<>();
778 List<EPApp> appList = new ArrayList<>();
779 appList.add(CentralApp());
780 EPUser user = mockUser.mockEPUser();
781 epuserList.add(user);
782 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
783 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
784 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(false);
785 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
786 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
787 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
788 Map<String, Object> actual = roleManageController.toggleRole(mockedRequest, mockedResponse, CentralApp().getId(), 1l);
789 final Map<String, Object> expected = new HashMap<>();
790 expected.put("restcallStatus", " Unauthorized user");
791 assertEquals(expected.get("restcallStatus"), actual.get("restcallStatus"));
794 @Test(expected = NullPointerException.class)
795 public void toggleRoleExceptionTest() throws Exception {
796 PowerMockito.mockStatic(EPUserUtils.class);
797 PowerMockito.mockStatic(EcompPortalUtils.class);
798 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
799 List<EPUser> epuserList = new ArrayList<>();
800 List<EPApp> appList = new ArrayList<>();
801 appList.add(CentralApp());
802 EPUser user = mockUser.mockEPUser();
803 epuserList.add(user);
804 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
805 Mockito.doThrow(new NullPointerException()).when(appService).getApp((long) 1);
806 roleManageController.toggleRole(mockedRequest, mockedResponse, CentralApp().getId(), 1l);
810 public void toggleRoleFailedTest() throws Exception {
811 PowerMockito.mockStatic(EPUserUtils.class);
812 PowerMockito.mockStatic(EcompPortalUtils.class);
813 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
814 List<EPUser> epuserList = new ArrayList<>();
815 List<EPApp> appList = new ArrayList<>();
816 appList.add(CentralApp());
817 EPUser user = mockUser.mockEPUser();
818 epuserList.add(user);
819 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
820 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
821 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
822 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
823 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
824 Mockito.when(externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
825 CentralV2Role role = new CentralV2Role(1l, "test");
826 role.setActive(true);
827 Role currentRole = new Role();
828 currentRole.setName("test");
829 Mockito.when(externalAccessRolesService.getRoleInfo(Matchers.anyLong(), Matchers.any())).thenReturn(role);
830 Mockito.when(externalAccessRolesService.ConvertCentralRoleToRole(Matchers.anyString())).thenReturn(currentRole);
831 ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, "");
832 Mockito.when(externalAccessRolesService.saveRoleForApplication(Matchers.any(),Matchers.any())).thenReturn(externalRequestFieldsValidator);
833 Map<String, Object> actual = roleManageController.toggleRole(mockedRequest, mockedResponse, CentralApp().getId(), 1l);
834 final Map<String, Object> expected = new HashMap<>();
835 expected.put("restcallStatus", "Toggle Role Failed");
836 assertEquals(expected.get("restcallStatus"), actual.get("restcallStatus"));
840 public void getAvailableChildRolesTest() throws Exception {
841 List<CentralV2Role> centralV2Roles = new ArrayList<>();
842 CentralV2Role centralV2Role = new CentralV2Role();
843 centralV2Role.setName("test");
844 centralV2Role.setId(1l);
845 CentralV2Role centralV2Role2 = new CentralV2Role();
846 centralV2Role2.setName("test");
847 centralV2Role2.setId(1l);
848 centralV2Roles.add(centralV2Role);
849 centralV2Roles.add(centralV2Role2);
850 SortedSet<CentralV2RoleFunction> roleFuns = new TreeSet<>();
851 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test", "test");
852 roleFuns.add(centralV2RoleFunction);
853 CentralV2Role currentRole = new CentralV2Role();
854 currentRole.setName("test");
855 currentRole.setId(1l);
856 currentRole.setRoleFunctions(roleFuns);
857 Mockito.when(externalAccessRolesService.getRolesForApp(CentralApp().getUebKey())).thenReturn(centralV2Roles);
858 Mockito.when(externalAccessRolesService.getRoleInfo(1l, CentralApp().getUebKey())).thenReturn(currentRole);
859 List<CentralV2Role> actual = roleManageController.getAvailableChildRoles(CentralApp().getUebKey(), 1l);
860 assertEquals(new ArrayList<>().size(), actual.size());
864 public void getCentralizedAppRolesTest() throws IOException {
865 PowerMockito.mockStatic(EPUserUtils.class);
866 EPUser user = mockUser.mockEPUser();
867 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
868 List<CentralizedApp> cenApps = new ArrayList<>();
869 CentralizedApp centralizedApp = new CentralizedApp();
870 centralizedApp.setAppId(1);
871 centralizedApp.setAppName("Test");
872 cenApps.add(centralizedApp);
873 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
874 Mockito.when(externalAccessRolesService.getCentralizedAppsOfUser(Matchers.anyString())).thenReturn(cenApps);
875 List<CentralizedApp> actual = roleManageController.getCentralizedAppRoles(mockedRequest, mockedResponse, user.getOrgUserId());
876 assertEquals(cenApps.size(), actual.size());
880 public void getCentralizedAppRolesExceptionTest() throws IOException {
881 PowerMockito.mockStatic(EPUserUtils.class);
882 EPUser user = mockUser.mockEPUser();
883 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
884 List<CentralizedApp> cenApps = new ArrayList<>();
885 CentralizedApp centralizedApp = new CentralizedApp();
886 centralizedApp.setAppId(1);
887 centralizedApp.setAppName("Test");
888 cenApps.add(centralizedApp);
889 Mockito.when(adminRolesService.isAccountAdmin(Matchers.anyObject())).thenReturn(false);
890 List<CentralizedApp> actual = roleManageController.getCentralizedAppRoles(mockedRequest, mockedResponse, user.getOrgUserId());
894 public CentralV2RoleFunction mockCentralRoleFunction() {
895 CentralV2RoleFunction roleFunction = new CentralV2RoleFunction();
896 roleFunction.setCode("Test");
897 roleFunction.setName("Test");
898 roleFunction.setAppId((long) 1);
902 public EPApp CentralApp() {
903 EPApp app = mockApp();
904 app.setCentralAuth(true);
905 app.setNameSpace("com.test");
909 public EPApp NonCentralApp() {
910 EPApp app = mockApp();
911 app.setCentralAuth(false);