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.assertFalse;
42 import static org.junit.Assert.assertNotEquals;
43 import static org.junit.Assert.assertNotNull;
44 import static org.junit.Assert.assertTrue;
46 import java.util.ArrayList;
47 import java.util.HashMap;
48 import java.util.List;
51 import java.util.SortedSet;
52 import java.util.TreeSet;
54 import javax.servlet.http.HttpServletRequest;
55 import javax.servlet.http.HttpServletResponse;
57 import org.hibernate.SQLQuery;
58 import org.hibernate.Session;
59 import org.hibernate.SessionFactory;
60 import org.hibernate.Transaction;
61 import org.hibernate.criterion.Criterion;
62 import org.hibernate.criterion.Restrictions;
63 import org.json.JSONObject;
64 import org.junit.After;
65 import org.junit.Before;
66 import org.junit.Test;
67 import org.junit.runner.RunWith;
68 import org.mockito.InjectMocks;
69 import org.mockito.Matchers;
70 import org.mockito.Mock;
71 import org.mockito.Mockito;
72 import org.mockito.MockitoAnnotations;
73 import org.onap.portalapp.portal.core.MockEPUser;
74 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
75 import org.onap.portalapp.portal.domain.CentralizedApp;
76 import org.onap.portalapp.portal.domain.EPApp;
77 import org.onap.portalapp.portal.domain.EPAppRoleFunction;
78 import org.onap.portalapp.portal.domain.EPRole;
79 import org.onap.portalapp.portal.domain.EPUser;
80 import org.onap.portalapp.portal.domain.EPUserApp;
81 import org.onap.portalapp.portal.ecomp.model.UploadRoleFunctionExtSystem;
82 import org.onap.portalapp.portal.exceptions.InactiveApplicationException;
83 import org.onap.portalapp.portal.exceptions.InvalidUserException;
84 import org.onap.portalapp.portal.framework.MockitoTestSuite;
85 import org.onap.portalapp.portal.transport.BulkUploadRoleFunction;
86 import org.onap.portalapp.portal.transport.BulkUploadUserRoles;
87 import org.onap.portalapp.portal.transport.CentralRole;
88 import org.onap.portalapp.portal.transport.CentralUser;
89 import org.onap.portalapp.portal.transport.CentralV2Role;
90 import org.onap.portalapp.portal.transport.CentralizedAppRoles;
91 import org.onap.portalapp.portal.transport.EcompUserRoles;
92 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
93 import org.onap.portalapp.portal.transport.GlobalRoleWithApplicationRoleFunction;
94 import org.onap.portalapp.portal.transport.LocalRole;
95 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
96 import org.onap.portalapp.portal.utils.EcompPortalUtils;
97 import org.onap.portalapp.portal.utils.PortalConstants;
98 import org.onap.portalapp.util.EPUserUtils;
99 import org.onap.portalsdk.core.domain.Role;
100 import org.onap.portalsdk.core.domain.RoleFunction;
101 import org.onap.portalsdk.core.restful.domain.EcompUser;
102 import org.onap.portalsdk.core.service.DataAccessService;
103 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
104 import org.onap.portalsdk.core.util.SystemProperties;
105 import org.powermock.api.mockito.PowerMockito;
106 import org.powermock.core.classloader.annotations.PrepareForTest;
107 import org.powermock.modules.junit4.PowerMockRunner;
108 import org.springframework.http.HttpEntity;
109 import org.springframework.http.HttpHeaders;
110 import org.springframework.http.HttpMethod;
111 import org.springframework.http.HttpStatus;
112 import org.springframework.http.ResponseEntity;
113 import org.springframework.web.client.HttpClientErrorException;
114 import org.springframework.web.client.RestTemplate;
116 import com.fasterxml.jackson.databind.ObjectMapper;
118 @RunWith(PowerMockRunner.class)
119 @PrepareForTest({ EcompPortalUtils.class, Criterion.class, EPUserUtils.class, Restrictions.class, SystemProperties.class,
120 EPCommonSystemProperties.class })
121 public class ExternalAccessRolesServiceImplTest {
123 DataAccessService dataAccessService = new DataAccessServiceImpl();
126 RestTemplate template = new RestTemplate();
129 ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl();
132 EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
135 SessionFactory sessionFactory;
141 Transaction transaction;
144 public void setup() {
145 MockitoAnnotations.initMocks(this);
146 Mockito.when(sessionFactory.openSession()).thenReturn(session);
147 Mockito.when(session.beginTransaction()).thenReturn(transaction);
151 public void after() {
155 private static final String APP_ROLE_NAME_PARAM = "appRoleName";
157 private static final String GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM = "getRoletoUpdateInExternalAuthSystem";
159 private static final String GET_PORTAL_APP_ROLES_QUERY = "getPortalAppRoles";
161 private static final String GET_ROLE_FUNCTION_QUERY = "getRoleFunction";
163 private static final String FUNCTION_CODE_PARAMS = "functionCode";
165 private static final String FUNCTION_PIPE = "|";
167 private static final String APP_ID = "appId";
169 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
171 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
172 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
173 NullPointerException nullPointerException = new NullPointerException();
174 MockEPUser mockUser = new MockEPUser();
175 String uebKey = "test-ueb-key";
177 public EPApp mockApp() {
178 EPApp app = new EPApp();
180 app.setImageUrl("test");
181 app.setNameSpace("com.test.app");
182 app.setCentralAuth(true);
183 app.setDescription("test");
184 app.setNotes("test");
186 app.setId((long) 10);
187 app.setAppRestEndpoint("test");
188 app.setAlternateUrl("test");
190 app.setMlAppName("test");
191 app.setMlAppAdminId("test");
192 app.setUsername("test");
193 app.setAppPassword("test");
195 app.setEnabled(true);
196 app.setUebKey("test");
197 app.setUebSecret("test");
198 app.setUebTopicName("test");
203 @SuppressWarnings("deprecation")
205 public void getAppRolesIfAppIsPortalTest() throws Exception {
206 List<EPRole> applicationRoles = new ArrayList<>();
207 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
208 List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 1);
209 assertEquals(expectedApplicationRoles, applicationRoles);
212 @SuppressWarnings("deprecation")
214 public void getAppRolesTest() throws Exception {
215 List<EPRole> applicationRoles = new ArrayList<>();
216 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
217 List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 10);
218 assertEquals(expectedApplicationRoles, applicationRoles);
221 @SuppressWarnings("deprecation")
223 public void getAppExceptionTest() throws Exception {
224 List<EPApp> app = new ArrayList<>();
225 Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
227 List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey);
228 assertEquals(app, expectedapp);
231 @Test(expected = InactiveApplicationException.class)
232 public void getAppErrorTest() throws Exception {
233 List<EPApp> appList = new ArrayList<>();
234 EPApp app = mockApp();
235 app.setEnabled(false);
237 final Map<String, String> appUebkeyParams = new HashMap<>();
238 appUebkeyParams.put("appKey", "test-ueb-key");
239 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
240 .thenReturn(appList);
241 externalAccessRolesServiceImpl.getApp(uebKey);
245 public void getAppTest() throws Exception {
246 List<EPApp> appList = new ArrayList<>();
247 EPApp app = mockApp();
250 final Map<String, String> appUebkeyParams = new HashMap<>();
251 appUebkeyParams.put("appKey", "test-ueb-key");
252 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
253 .thenReturn(appList);
254 List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey);
255 assertEquals(appList, expectedapp);
259 public void addRoleTest() throws Exception {
260 HttpHeaders headers = new HttpHeaders();
261 PowerMockito.mockStatic(EcompPortalUtils.class);
262 PowerMockito.mockStatic(SystemProperties.class);
263 PowerMockito.mockStatic(EPCommonSystemProperties.class);
264 String uebKey = "test-ueb-key";
265 Role role = new Role();
266 role.setId((long) 25);
267 EPApp app = mockApp();
268 app.setEnabled(true);
269 app.setId((long) 10);
270 app.setNameSpace("test_namesapce");
271 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
272 List<EPApp> appList = new ArrayList<>();
274 List<EPRole> roleList = new ArrayList<>();
275 EPRole ePRole = new EPRole();
276 role.setName("Test Role");
277 roleList.add(ePRole);
278 final Map<String, String> appUebkeyParams = new HashMap<>();
279 appUebkeyParams.put("appKey", "test-ueb-key");
280 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
281 .thenReturn(appList);
282 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
283 getPartnerAppRoleParams.put("appRoleId", role.getId());
284 getPartnerAppRoleParams.put("appId", app.getId());
285 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
286 .thenReturn(roleList);
287 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL))
288 .thenReturn("Testurl");
289 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
290 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
291 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
293 assertTrue(externalAccessRolesServiceImpl.addRole(role, uebKey));
297 public void addRoleMethodNotAllowedTest() throws Exception {
298 HttpHeaders headers = new HttpHeaders();
299 PowerMockito.mockStatic(EcompPortalUtils.class);
300 PowerMockito.mockStatic(SystemProperties.class);
301 PowerMockito.mockStatic(EPCommonSystemProperties.class);
302 Role role = new Role();
303 role.setId((long) 25);
304 EPApp app = mockApp();
305 app.setEnabled(true);
306 app.setId((long) 10);
307 app.setNameSpace("test_namesapce");
308 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
309 List<EPApp> appList = new ArrayList<>();
311 List<EPRole> roleList = new ArrayList<>();
312 EPRole ePRole = new EPRole();
313 role.setName("Test Role");
314 roleList.add(ePRole);
315 final Map<String, String> appUebkeyParams = new HashMap<>();
316 appUebkeyParams.put("appKey", "test-ueb-key");
317 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
318 .thenReturn(appList);
319 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
320 getPartnerAppRoleParams.put("appRoleId", role.getId());
321 getPartnerAppRoleParams.put("appId", app.getId());
322 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
323 .thenReturn(roleList);
324 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL))
325 .thenReturn("Testurl");
326 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
327 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
328 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
329 assertFalse(externalAccessRolesServiceImpl.addRole(role, uebKey));
332 public EPApp getApp() {
333 EPApp app = new EPApp();
335 app.setImageUrl("test");
336 app.setDescription("test");
337 app.setNotes("test");
340 app.setAppRestEndpoint("test");
341 app.setAlternateUrl("test");
343 app.setMlAppName("test");
344 app.setMlAppAdminId("test");
345 app.setUsername("test");
346 app.setAppPassword("test");
348 app.setEnabled(false);
349 app.setUebKey("test");
350 app.setUebSecret("test");
351 app.setUebTopicName("test");
357 public void deleteCentralRoleFunctionTest() throws Exception {
358 PowerMockito.mockStatic(EcompPortalUtils.class);
359 PowerMockito.mockStatic(SystemProperties.class);
360 PowerMockito.mockStatic(EPCommonSystemProperties.class);
361 final Map<String, String> params = new HashMap<>();
362 EPApp app = mockApp();
363 params.put("functionCode", "menu_fun_code");
364 params.put("appId", String.valueOf(10));
365 List<CentralV2RoleFunction> centralRoleFunctionList = new ArrayList<>();
366 CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
367 domainCentralRoleFunction.setCode("menu_fun_code");
368 centralRoleFunctionList.add(domainCentralRoleFunction);
369 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null))
370 .thenReturn(centralRoleFunctionList);
371 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
372 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.OK);
373 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
374 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
375 HttpHeaders headers = new HttpHeaders();
376 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
377 Mockito.doNothing().when(dataAccessService).deleteDomainObjects(EPAppRoleFunction.class,
378 "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null);
379 assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app));
383 public void deleteRoleForApplicationTest() throws Exception {
384 EPApp app = mockApp();
386 List<EPApp> appList = new ArrayList<>();
388 final Map<String, String> appUebkeyParams = new HashMap<>();
389 appUebkeyParams.put("appKey", app.getUebKey());
390 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
391 .thenReturn(appList);
392 final Map<String, String> deleteRoleParams = new HashMap<>();
393 deleteRoleParams.put(APP_ROLE_NAME_PARAM, "test_delete");
394 deleteRoleParams.put(APP_ID, String.valueOf(app.getId()));
395 List<EPRole> epRoleList = new ArrayList<>();
396 EPRole epRole = new EPRole();
397 epRole.setName("test_delete");
399 epRole.setActive(true);
400 epRole.setAppRoleId(11l);
401 epRoleList.add(epRole);
403 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, deleteRoleParams, null))
404 .thenReturn(epRoleList);
405 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
406 appRoleFuncsParams.put("appId", app.getId());
407 appRoleFuncsParams.put("roleId", epRole.getId());
408 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
409 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
410 epAppRoleFunction.setCode("test_code");
411 epAppRoleFunction.setAppId(app.getId());
412 epAppRoleFunction.setRoleAppId(null);
413 appRoleFunctionList.add(epAppRoleFunction);
415 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
416 .thenReturn(appRoleFunctionList);
417 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
418 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
419 PowerMockito.mockStatic(EcompPortalUtils.class);
420 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
421 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
422 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
423 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
424 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
425 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
426 assertTrue(externalAccessRolesServiceImpl.deleteRoleForApplication(epRole.getName(), app.getUebKey()));
430 public void deleteRoleForPortalApplicationTest() throws Exception {
431 EPApp app = mockApp();
433 List<EPApp> appList = new ArrayList<>();
435 final Map<String, String> appUebkeyParams = new HashMap<>();
436 appUebkeyParams.put("appKey", app.getUebKey());
437 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
438 .thenReturn(appList);
439 final Map<String, String> deleteRoleParams2 = new HashMap<>();
440 deleteRoleParams2.put(APP_ROLE_NAME_PARAM, "test_delete");
441 List<EPRole> epRoleList2 = new ArrayList<>();
442 EPRole epRole = new EPRole();
443 epRole.setName("test_delete");
445 epRole.setActive(true);
446 epRoleList2.add(epRole);
447 Mockito.when(dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, deleteRoleParams2, null))
448 .thenReturn(epRoleList2);
449 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
450 appRoleFuncsParams.put("appId", app.getId());
451 appRoleFuncsParams.put("roleId", epRole.getId());
452 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
453 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
454 epAppRoleFunction.setCode("test_code");
455 epAppRoleFunction.setAppId(app.getId());
456 epAppRoleFunction.setRoleAppId(null);
457 appRoleFunctionList.add(epAppRoleFunction);
459 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
460 .thenReturn(appRoleFunctionList);
461 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
462 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
463 PowerMockito.mockStatic(EcompPortalUtils.class);
464 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
465 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
466 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
467 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
468 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
469 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
470 assertTrue(externalAccessRolesServiceImpl.deleteRoleForApplication(epRole.getName(), app.getUebKey()));
474 public void deleteCentralRoleFunctionFailTest() throws Exception {
475 final Map<String, String> params = new HashMap<>();
476 EPApp app = mockApp();
477 params.put("functionCode", "menu_fun_code");
478 params.put("appId", String.valueOf(10));
479 List<CentralV2RoleFunction> centralRoleFunctionList = new ArrayList<>();
480 CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
481 domainCentralRoleFunction.setCode("menu_fun_code");
482 centralRoleFunctionList.add(domainCentralRoleFunction);
483 HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.NOT_FOUND);
484 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null))
485 .thenReturn(centralRoleFunctionList);
486 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
487 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(httpClientErrorException);
488 HttpHeaders headers = new HttpHeaders();
489 PowerMockito.mockStatic(EcompPortalUtils.class);
490 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
491 Mockito.doNothing().when(dataAccessService).deleteDomainObjects(EPAppRoleFunction.class,
492 "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null);
493 boolean returnedValue = externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app);
494 assertTrue(returnedValue);
498 public void deleteCentralRoleFunctionExceptionTest() {
499 final Map<String, String> params = new HashMap<>();
500 EPApp app = mockApp();
501 params.put("functionCd", "menu_fun_code");
502 params.put("appId", String.valueOf(10));
503 List<CentralV2RoleFunction> centralRoleFunctionList = new ArrayList<>();
504 CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
505 domainCentralRoleFunction.setCode("menu_fun_code");
506 centralRoleFunctionList.add(domainCentralRoleFunction);
507 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionDetails", params, null))
508 .thenThrow(nullPointerException);
509 assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app));
513 public void getRoleFunctionTest() throws Exception {
514 PowerMockito.mockStatic(EcompPortalUtils.class);
515 PowerMockito.mockStatic(EPCommonSystemProperties.class);
516 PowerMockito.mockStatic(SystemProperties.class);
517 EPApp app = mockApp();
518 List<EPApp> appList = new ArrayList<>();
520 final Map<String, String> appUebkeyParams = new HashMap<>();
521 appUebkeyParams.put("appKey", app.getUebKey());
522 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
523 .thenReturn(appList);
524 Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code");
525 Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
526 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
527 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
528 CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
529 getRoleFuncList.add(getCenRole);
530 final Map<String, String> params = new HashMap<>();
531 params.put(FUNCTION_CODE_PARAMS, "test_type|type_code|*");
532 params.put(APP_ID, String.valueOf(app.getId()));
533 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null))
534 .thenReturn(getRoleFuncList);
535 CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
537 assertEquals("type_code", actual.getCode());
541 public void getRoleFunctionMutilpleFilterTest() throws Exception {
542 PowerMockito.mockStatic(EcompPortalUtils.class);
543 PowerMockito.mockStatic(EPCommonSystemProperties.class);
544 PowerMockito.mockStatic(SystemProperties.class);
545 EPApp app = mockApp();
546 List<EPApp> appList = new ArrayList<>();
548 final Map<String, String> appUebkeyParams = new HashMap<>();
549 appUebkeyParams.put("appKey", app.getUebKey());
550 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
551 .thenReturn(appList);
552 CentralV2RoleFunction expected = new CentralV2RoleFunction(null, "type_code", "test_name", null, "test_type",
554 Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code");
555 Mockito.when(EcompPortalUtils.getFunctionCode("test_type_1|type_code_1|*")).thenReturn("type_code_1");
556 Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
557 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
558 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
559 CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
560 CentralV2RoleFunction getCenRole2 = new CentralV2RoleFunction("test_type_1|type_code_1|*", "test_name_1");
561 getRoleFuncList.add(getCenRole);
562 getRoleFuncList.add(getCenRole2);
563 final Map<String, String> params = new HashMap<>();
564 params.put(FUNCTION_CODE_PARAMS, "test_type|type_code|*");
565 params.put(APP_ID, String.valueOf(app.getId()));
566 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null))
567 .thenReturn(getRoleFuncList);
568 CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
570 assertEquals(expected.getCode(), actual.getCode());
574 public void getUserTest() throws InvalidUserException {
575 List<EPUser> userList = new ArrayList<>();
576 EPUser user = mockUser.mockEPUser();
578 final Map<String, String> userParams = new HashMap<>();
579 userParams.put("org_user_id", "guestT");
580 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
581 .thenReturn(userList);
582 List<EPUser> expectedUserList = externalAccessRolesServiceImpl.getUser("guestT");
583 assertEquals(expectedUserList, userList);
587 public void getV2UserWithRolesTest() throws Exception {
588 EPApp app = mockApp();
590 EPUser user = mockUser.mockEPUser();
591 List<EPApp> appList = new ArrayList<>();
593 final Map<String, String> appUebkeyParams = new HashMap<>();
594 appUebkeyParams.put("appKey", app.getUebKey());
595 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
596 .thenReturn(appList);
597 final Map<String, String> userParams = new HashMap<>();
598 userParams.put("org_user_id", user.getOrgUserId());
599 List<EPUser> userList = new ArrayList<>();
600 Set<EPUserApp> userAppSet = user.getEPUserApps();
601 EPUserApp epUserApp = new EPUserApp();
602 EPRole epRole = new EPRole();
603 epRole.setName("test");
605 epRole.setActive(true);
606 epRole.setAppRoleId(11l);
607 epUserApp.setApp(app);
608 epUserApp.setUserId(user.getId());
609 epUserApp.setRole(epRole);
610 userAppSet.add(epUserApp);
611 user.setUserApps(userAppSet);
613 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
614 .thenReturn(userList);
615 final Map<String, Long> params = new HashMap<>();
616 List<CentralV2RoleFunction> appRoleFunctionList = new ArrayList<>();
617 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
618 centralV2RoleFunction.setCode("test_type|test_code|*");
619 centralV2RoleFunction.setName("test name");
620 centralV2RoleFunction.setAppId(app.getId());
621 appRoleFunctionList.add(centralV2RoleFunction);
622 params.put("roleId", epUserApp.getRole().getId());
623 params.put(APP_ID, epUserApp.getApp().getId());
624 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
625 .thenReturn(appRoleFunctionList);
626 String actual = externalAccessRolesServiceImpl.getV2UserWithRoles(user.getOrgUserId(), app.getUebKey());
627 String notExpected = "";
628 assertNotEquals(actual, notExpected);
632 public void saveCentralRoleFunctionNewTestForV2() throws Exception {
633 PowerMockito.mockStatic(EcompPortalUtils.class);
634 EPApp app = mockApp();
636 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
637 centralV2RoleFunction.setCode("test_code");
638 centralV2RoleFunction.setName("test name");
639 centralV2RoleFunction.setAppId(app.getId());
640 centralV2RoleFunction.setAction("*");
641 centralV2RoleFunction.setType("test_type");
642 final Map<String, String> params = new HashMap<>();
643 params.put("appId", String.valueOf(1));
645 List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
646 appRoleFunc.add(centralV2RoleFunction);
647 params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
648 + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
649 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
650 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
651 HttpHeaders headers = new HttpHeaders();
652 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
653 JSONObject mockJsonObjectPerm = new JSONObject();
654 JSONObject mockJsonObjectFinalPerm = new JSONObject();
655 mockJsonObjectPerm.put("type", "com.test.app.test_type");
656 mockJsonObjectPerm.put("instance", "com.test.app.test_code");
657 mockJsonObjectPerm.put("action", "*");
658 mockJsonObjectPerm.put("description", "test name");
659 List<JSONObject> mockJson = new ArrayList<>();
660 mockJson.add(mockJsonObjectPerm);
661 mockJsonObjectFinalPerm.put("perm", mockJson);
662 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
663 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
664 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
665 ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
666 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
667 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
668 Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
669 assertEquals(true, actual);
673 public void saveCentralRoleFunctionUpdateForV2Test() throws Exception {
674 PowerMockito.mockStatic(EcompPortalUtils.class);
675 EPApp app = mockApp();
677 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
678 centralV2RoleFunction.setCode("test_code");
679 centralV2RoleFunction.setName("test name2");
680 centralV2RoleFunction.setAppId(app.getId());
681 centralV2RoleFunction.setAction("*");
682 centralV2RoleFunction.setType("test_type");
683 CentralV2RoleFunction centralV2RoleFunctionExisting = new CentralV2RoleFunction();
684 centralV2RoleFunctionExisting.setCode("test_code");
685 centralV2RoleFunctionExisting.setName("test name");
686 centralV2RoleFunctionExisting.setAppId(app.getId());
687 centralV2RoleFunctionExisting.setAction("*");
688 centralV2RoleFunctionExisting.setType("test_type");
689 final Map<String, String> params = new HashMap<>();
690 params.put("appId", String.valueOf(1));
691 List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
692 appRoleFunc.add(centralV2RoleFunctionExisting);
693 params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
694 + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
695 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
696 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
697 HttpHeaders headers = new HttpHeaders();
698 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
699 JSONObject mockJsonObjectPerm = new JSONObject();
700 JSONObject mockJsonObjectFinalPerm = new JSONObject();
701 mockJsonObjectPerm.put("type", "com.test.app.test_type");
702 mockJsonObjectPerm.put("instance", "test_code");
703 mockJsonObjectPerm.put("action", "*");
704 mockJsonObjectPerm.put("description", "test name");
705 List<JSONObject> mockJson = new ArrayList<>();
706 mockJson.add(mockJsonObjectPerm);
707 mockJsonObjectFinalPerm.put("perm", mockJson);
708 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
709 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
710 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
711 ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
712 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
713 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
714 Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
715 assertEquals(true, actual);
718 @SuppressWarnings("deprecation")
720 public void getAllAppUsersTest() throws Exception {
721 PowerMockito.mockStatic(EcompPortalUtils.class);
722 PowerMockito.mockStatic(EPUserUtils.class);
723 EPApp app = new EPApp();
724 app.setEnabled(true);
725 app.setId((long) 10);
726 List<EPApp> appList = new ArrayList<>();
727 final Map<String, String> appUebkeyParams = new HashMap<>();
729 appUebkeyParams.put("appKey", app.getUebKey());
730 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
731 .thenReturn(appList);
732 List<EPRole> applicationRoles = new ArrayList<>();
733 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
734 Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
735 .thenReturn(appList);
736 final Map<String, Long> appParams = new HashMap<>();
737 appParams.put("appId", app.getId());
738 List<EcompUserRoles> userList = new ArrayList<>();
739 EcompUserRoles ecompUserRoles = new EcompUserRoles();
740 ecompUserRoles.setOrgUserId("guestT");
741 ecompUserRoles.setRoleId((long) 1);
742 ecompUserRoles.setRoleName("test");
743 ecompUserRoles.setFunctionCode("test_type|test_instance|test_action");
744 ecompUserRoles.setFunctionName("test1");
745 EcompUserRoles ecompUserRoles2 = new EcompUserRoles();
746 ecompUserRoles2.setOrgUserId("guestT");
747 ecompUserRoles2.setRoleId((long) 2);
748 ecompUserRoles2.setRoleName("test new");
749 ecompUserRoles2.setFunctionCode("test_instance2");
750 ecompUserRoles2.setFunctionName("test2");
751 userList.add(ecompUserRoles);
752 userList.add(ecompUserRoles2);
753 Mockito.when(EcompPortalUtils.getFunctionCode(ecompUserRoles.getFunctionCode())).thenReturn("test_instance");
754 Mockito.when(EPUserUtils.decodeFunctionCode("test_instance")).thenReturn("test_instance");
755 Mockito.when(EcompPortalUtils.getFunctionCode(ecompUserRoles2.getFunctionCode())).thenReturn("test_instance2");
756 Mockito.when(EPUserUtils.decodeFunctionCode("test_instance2")).thenReturn("test_instance2");
757 Mockito.when(EcompPortalUtils.getFunctionType("test_type|test_instance|test_action")).thenReturn("test_type");
758 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|test_instance|test_action")).thenReturn("test_action");
759 Mockito.when(dataAccessService.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
760 List<EcompUser> usersfinalList = externalAccessRolesServiceImpl.getAllAppUsers(app.getUebKey());
761 assertEquals(usersfinalList.get(0).getRoles().size(), 2);
765 public void getGlobalRolesOfPortalTest() {
766 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(null);
767 assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), null);
771 public void getGlobalRolesOfPortalExceptionTest() {
772 List<EPRole> globalRoles = new ArrayList<>();
773 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null))
774 .thenThrow(nullPointerException);
775 assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), globalRoles);
779 public void getRolesForAppTest() throws Exception {
780 EPApp app = mockApp();
782 List<EPApp> appList = new ArrayList<>();
783 final Map<String, String> appUebkeyParams = new HashMap<>();
785 appUebkeyParams.put("appKey", app.getUebKey());
786 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
787 .thenReturn(appList);
788 List<EPRole> applicationRoles = new ArrayList<>();
789 EPRole appRole = new EPRole();
790 appRole.setActive(true);
791 appRole.setAppId(app.getId());
792 appRole.setAppRoleId(100l);
794 appRole.setName("test");
795 applicationRoles.add(appRole);
796 final Map<String, Long> appParams = new HashMap<>();
797 appParams.put("appId", app.getId());
798 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
799 .thenReturn(applicationRoles);
800 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
801 CentralV2RoleFunction v2RoleFunction = new CentralV2RoleFunction();
802 v2RoleFunction.setAppId(app.getId());
803 v2RoleFunction.setCode("test_type|test_code|*");
804 v2RoleFunction.setName("test name");
805 cenRoleFuncList.add(v2RoleFunction);
806 final Map<String, Long> params = new HashMap<>();
807 params.put("roleId", appRole.getId());
808 params.put(APP_ID, appList.get(0).getId());
809 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
810 .thenReturn(cenRoleFuncList);
811 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
812 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
813 mockGlobalRole.setActive(true);
814 mockGlobalRole.setAppId(app.getId());
815 mockGlobalRole.setRoleId(1111l);
816 mockGlobalRole.setRoleName("global_test");
817 mockGlobalRole.setFunctionCd("test_type|test_code|*");
818 mockGlobalRole.setFunctionName("test name");
819 mockGlobalRoles.add(mockGlobalRole);
820 Map<String, Long> params2 = new HashMap<>();
821 params2.put("appId", app.getId());
822 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params2, null))
823 .thenReturn(mockGlobalRoles);
824 List<EPRole> globalRoles = new ArrayList<>();
825 EPRole globalRole = new EPRole();
826 globalRole.setName("global_test");
827 globalRole.setId(1111l);
828 globalRole.setActive(true);
829 globalRoles.add(globalRole);
830 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
831 List<CentralV2Role> expected = new ArrayList<>();
832 CentralV2Role cenV2Role = new CentralV2Role();
833 CentralV2Role cenV2Role2 = new CentralV2Role();
834 expected.add(cenV2Role);
835 expected.add(cenV2Role2);
836 List<CentralV2Role> actual = externalAccessRolesServiceImpl.getRolesForApp(app.getUebKey());
837 assertEquals(expected.size(), actual.size());
841 public void getRoleFuncListTest() throws Exception {
842 EPApp app = mockApp();
843 List<EPApp> appList = new ArrayList<>();
844 final Map<String, String> appUebkeyParams = new HashMap<>();
846 appUebkeyParams.put("appKey", app.getUebKey());
847 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
848 .thenReturn(appList);
849 final Map<String, Long> params = new HashMap<>();
850 params.put(APP_ID, app.getId());
851 List<CentralV2RoleFunction> expected = new ArrayList<>();
852 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
853 expected.add(centralV2RoleFunction);
854 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(expected);
855 List<CentralV2RoleFunction> actual = externalAccessRolesServiceImpl.getRoleFuncList(app.getUebKey());
856 assertEquals(expected, actual);
860 public void getRoleInfoTest() throws Exception {
861 EPApp app = mockApp();
863 List<EPApp> appList = new ArrayList<>();
864 final Map<String, String> appUebkeyParams = new HashMap<>();
866 appUebkeyParams.put("appKey", app.getUebKey());
867 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
868 .thenReturn(appList);
869 List<EPRole> globalRoles = new ArrayList<>();
870 EPRole globalRole = new EPRole();
871 globalRole.setName("global_test");
872 globalRole.setId(2l);
873 globalRole.setActive(true);
874 globalRoles.add(globalRole);
875 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
876 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
877 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
878 mockGlobalRole.setActive(true);
879 mockGlobalRole.setAppId(app.getId());
880 mockGlobalRole.setRoleId(2l);
881 mockGlobalRole.setRoleName("global_test");
882 mockGlobalRole.setFunctionCd("test_type|test_code|*");
883 mockGlobalRole.setFunctionName("test name");
884 mockGlobalRoles.add(mockGlobalRole);
885 Map<String, Long> params = new HashMap<>();
886 params.put("roleId", 2l);
887 params.put("requestedAppId", 2l);
888 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", params, null))
889 .thenReturn(mockGlobalRoles);
890 CentralV2Role actual = externalAccessRolesServiceImpl.getRoleInfo(2l, app.getUebKey());
891 assertNotEquals(null, actual);
895 public void getPartnerRoleInfoTest() throws Exception {
896 EPApp app = mockApp();
898 List<EPApp> appList = new ArrayList<>();
899 final Map<String, String> appUebkeyParams = new HashMap<>();
901 appUebkeyParams.put("appKey", app.getUebKey());
902 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
903 .thenReturn(appList);
904 List<EPRole> applicationRoles = new ArrayList<>();
905 EPRole appRole = new EPRole();
906 appRole.setActive(true);
907 appRole.setAppId(app.getId());
908 appRole.setAppRoleId(100l);
910 appRole.setName("test");
911 applicationRoles.add(appRole);
912 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
913 getPartnerAppRoleParams.put("appRoleId", 10l);
914 getPartnerAppRoleParams.put("appId", app.getId());
915 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
916 .thenReturn(applicationRoles);
917 final Map<String, Long> params = new HashMap<>();
918 params.put("roleId", appRole.getId());
919 params.put(APP_ID, app.getId());
920 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
921 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
922 cenRoleFuncList.add(centralV2RoleFunction);
923 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
924 .thenReturn(cenRoleFuncList);
925 CentralV2Role actual = externalAccessRolesServiceImpl.getRoleInfo(10l, app.getUebKey());
926 assertNotEquals(null, actual);
930 public void saveRoleForPortalApplicationNewTest() throws Exception {
931 PowerMockito.mockStatic(EcompPortalUtils.class);
932 EPApp app = mockApp();
934 Role addRoleTest = new Role();
935 addRoleTest.setActive(true);
936 addRoleTest.setName("Test");
937 List<EPApp> appList = new ArrayList<>();
938 final Map<String, String> appUebkeyParams = new HashMap<>();
940 appUebkeyParams.put("appKey", app.getUebKey());
941 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
942 .thenReturn(appList);
943 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
944 HttpHeaders headers = new HttpHeaders();
945 JSONObject mockJsonObjectRole = new JSONObject();
946 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
947 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectRole.toString(), HttpStatus.OK);
948 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
949 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
950 final Map<String, String> epAppPortalRoleParams = new HashMap<>();
951 epAppPortalRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
952 List<EPRole> getRoleCreated = new ArrayList<>();
953 EPRole roleCreate = new EPRole();
954 roleCreate.setActive(true);
955 roleCreate.setId(10l);
956 roleCreate.setName("test");
957 getRoleCreated.add(roleCreate);
958 Mockito.when(dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, epAppPortalRoleParams, null))
959 .thenReturn(getRoleCreated);
960 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
961 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
962 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
963 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
964 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
966 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
967 assertEquals(expected, actual);
971 public void saveRoleForPortalApplicationUpdateTest() throws Exception {
972 PowerMockito.mockStatic(EPCommonSystemProperties.class);
973 PowerMockito.mockStatic(EcompPortalUtils.class);
974 PowerMockito.mockStatic(SystemProperties.class);
975 EPApp app = mockApp();
977 Role addRoleTest = new Role();
978 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
979 RoleFunction roleFunc = new RoleFunction();
980 roleFunc.setName("Test Name");
981 roleFunc.setCode("test_type|test_instance|*");
982 RoleFunction roleFunc2 = new RoleFunction();
983 roleFunc2.setName("Test Name3");
984 roleFunc2.setCode("test_type3|test_instance3|*");
985 roleFuncSet.add(roleFunc);
986 roleFuncSet.add(roleFunc2);
987 addRoleTest.setActive(true);
988 addRoleTest.setName("Test2");
989 addRoleTest.setId(2l);
990 addRoleTest.setRoleFunctions(roleFuncSet);
991 List<EPApp> appList = new ArrayList<>();
992 final Map<String, String> appUebkeyParams = new HashMap<>();
994 appUebkeyParams.put("appKey", app.getUebKey());
995 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
996 .thenReturn(appList);
997 List<EPRole> globalRoles = new ArrayList<>();
998 EPRole globalRole = new EPRole();
999 globalRole.setName("global_test");
1000 globalRole.setId(1111l);
1001 globalRole.setActive(true);
1002 globalRoles.add(globalRole);
1003 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1004 List<EPRole> epRoleList = new ArrayList<>();
1005 EPRole getEPRole = new EPRole();
1006 getEPRole.setName("Test");
1007 getEPRole.setId(2l);
1008 getEPRole.setActive(true);
1009 epRoleList.add(getEPRole);
1010 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1011 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1012 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1013 .thenReturn(epRoleList);
1014 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1015 HttpHeaders headers = new HttpHeaders();
1016 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1017 JSONObject mockJsonObjectRole = new JSONObject();
1018 JSONObject mockJsonObjectFinalRole = new JSONObject();
1019 JSONObject mockJsonObjectPerm1 = new JSONObject();
1020 JSONObject mockJsonObjectPerm2 = new JSONObject();
1021 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1022 mockJsonObjectPerm1.put("instance", "test_instance");
1023 mockJsonObjectPerm1.put("action", "*");
1024 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1025 mockJsonObjectPerm2.put("instance", "test_instance2");
1026 mockJsonObjectPerm2.put("action", "*");
1027 List<JSONObject> permsList = new ArrayList<>();
1028 permsList.add(mockJsonObjectPerm1);
1029 permsList.add(mockJsonObjectPerm2);
1030 mockJsonObjectRole.put("name", "com.test.app.Test");
1031 mockJsonObjectRole.put("perms", permsList);
1032 mockJsonObjectRole.put("description",
1033 "{\"id\":\"2\",\"name\":\"Test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
1034 List<JSONObject> roleList = new ArrayList<>();
1035 roleList.add(mockJsonObjectRole);
1036 mockJsonObjectFinalRole.put("role", roleList);
1037 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1038 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1039 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1040 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1041 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1042 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1043 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1044 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1045 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1046 final Map<String, String> params = new HashMap<>();
1047 params.put("uebKey", app.getUebKey());
1048 params.put("roleId", String.valueOf(getEPRole.getId()));
1049 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1050 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1051 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1052 bulkUploadUserRoles.setOrgUserId("guestT");
1053 bulkUploadUserRoles.setRoleName("Test2");
1054 userRolesList.add(bulkUploadUserRoles);
1055 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1056 .thenReturn(userRolesList);
1058 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1060 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1061 .thenReturn("@test.com");
1062 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1063 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1064 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1065 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1066 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1067 appRoleFuncsParams.put("appId", app.getId());
1068 appRoleFuncsParams.put("roleId", getEPRole.getId());
1070 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1071 .thenReturn(appRoleFunctionList);
1072 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1073 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1074 final Map<String, String> getAppFunctionParams = new HashMap<>();
1075 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1076 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1077 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1078 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1079 v2RoleFunction.add(v2RoleFunction1);
1080 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1081 .thenReturn(v2RoleFunction);
1082 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1083 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1084 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1085 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1086 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1087 v2RoleFunction2.add(v2RoleFunction3);
1088 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1089 .thenReturn(v2RoleFunction2);
1090 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1092 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1093 assertEquals(expected, actual);
1097 public void saveRoleExitsInDbButNotInExtAuthSystemTest() throws Exception {
1098 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1099 PowerMockito.mockStatic(EcompPortalUtils.class);
1100 PowerMockito.mockStatic(SystemProperties.class);
1101 EPApp app = mockApp();
1103 Role addRoleTest = new Role();
1104 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1105 RoleFunction roleFunc = new RoleFunction();
1106 roleFunc.setName("Test Name");
1107 roleFunc.setCode("test_type|test_instance|*");
1108 RoleFunction roleFunc2 = new RoleFunction();
1109 roleFunc2.setName("Test Name3");
1110 roleFunc2.setCode("test_type3|test_instance3|*");
1111 roleFuncSet.add(roleFunc);
1112 roleFuncSet.add(roleFunc2);
1113 addRoleTest.setActive(true);
1114 addRoleTest.setName("Test2");
1115 addRoleTest.setId(2l);
1116 addRoleTest.setRoleFunctions(roleFuncSet);
1117 List<EPApp> appList = new ArrayList<>();
1118 final Map<String, String> appUebkeyParams = new HashMap<>();
1120 appUebkeyParams.put("appKey", app.getUebKey());
1121 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1122 .thenReturn(appList);
1123 List<EPRole> globalRoles = new ArrayList<>();
1124 EPRole globalRole = new EPRole();
1125 globalRole.setName("global_test");
1126 globalRole.setId(1111l);
1127 globalRole.setActive(true);
1128 globalRoles.add(globalRole);
1129 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1130 List<EPRole> epRoleList = new ArrayList<>();
1131 EPRole getEPRole = new EPRole();
1132 getEPRole.setName("Test");
1133 getEPRole.setId(2l);
1134 getEPRole.setActive(true);
1135 epRoleList.add(getEPRole);
1136 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1137 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1138 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1139 .thenReturn(epRoleList);
1140 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1141 HttpHeaders headers = new HttpHeaders();
1142 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1143 JSONObject mockJsonObjectFinalRole = new JSONObject();
1144 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1145 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1146 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1147 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1148 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1149 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1150 final Map<String, String> params = new HashMap<>();
1151 params.put("uebKey", app.getUebKey());
1152 params.put("roleId", String.valueOf(getEPRole.getId()));
1153 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1154 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1155 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1156 bulkUploadUserRoles.setOrgUserId("guestT");
1157 bulkUploadUserRoles.setRoleName("Test2");
1158 userRolesList.add(bulkUploadUserRoles);
1159 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1160 .thenReturn(userRolesList);
1162 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1164 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1165 .thenReturn("@test.com");
1166 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1167 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1168 appRoleFuncsParams.put("appId", app.getId());
1169 appRoleFuncsParams.put("roleId", getEPRole.getId());
1171 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1172 .thenReturn(appRoleFunctionList);
1173 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1174 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1175 final Map<String, String> getAppFunctionParams = new HashMap<>();
1176 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1177 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1178 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1179 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1180 v2RoleFunction.add(v2RoleFunction1);
1181 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1182 .thenReturn(v2RoleFunction);
1183 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1184 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1185 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1186 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1187 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1188 v2RoleFunction2.add(v2RoleFunction3);
1189 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1190 .thenReturn(v2RoleFunction2);
1191 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1193 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1194 assertEquals(expected, actual);
1198 public void saveGlobalRoleForPortalApplicationUpdateTest() throws Exception {
1199 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1200 PowerMockito.mockStatic(EcompPortalUtils.class);
1201 PowerMockito.mockStatic(SystemProperties.class);
1202 EPApp app = mockApp();
1204 Role addRoleTest = new Role();
1205 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1206 RoleFunction roleFunc = new RoleFunction();
1207 roleFunc.setName("Test Name");
1208 roleFunc.setCode("test_type|test_instance|*");
1209 RoleFunction roleFunc2 = new RoleFunction();
1210 roleFunc2.setName("Test Name3");
1211 roleFunc2.setCode("test_type3|test_instance3|*");
1212 roleFuncSet.add(roleFunc);
1213 roleFuncSet.add(roleFunc2);
1214 addRoleTest.setActive(true);
1215 addRoleTest.setName("global_test2");
1216 addRoleTest.setId(1111l);
1217 addRoleTest.setRoleFunctions(roleFuncSet);
1218 List<EPApp> appList = new ArrayList<>();
1219 final Map<String, String> appUebkeyParams = new HashMap<>();
1221 appUebkeyParams.put("appKey", app.getUebKey());
1222 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1223 .thenReturn(appList);
1224 List<EPRole> globalRoles = new ArrayList<>();
1225 EPRole globalRole = new EPRole();
1226 globalRole.setName("global_test");
1227 globalRole.setId(1111l);
1228 globalRole.setActive(true);
1229 globalRoles.add(globalRole);
1230 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1231 List<EPRole> epRoleList = new ArrayList<>();
1232 EPRole getEPRole = new EPRole();
1233 getEPRole.setName("global_test");
1234 getEPRole.setId(1111l);
1235 getEPRole.setActive(true);
1236 epRoleList.add(getEPRole);
1237 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1238 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1239 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1240 .thenReturn(epRoleList);
1241 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1242 HttpHeaders headers = new HttpHeaders();
1243 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1244 JSONObject mockJsonObjectRole = new JSONObject();
1245 JSONObject mockJsonObjectFinalRole = new JSONObject();
1246 JSONObject mockJsonObjectPerm1 = new JSONObject();
1247 JSONObject mockJsonObjectPerm2 = new JSONObject();
1248 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1249 mockJsonObjectPerm1.put("instance", "test_instance");
1250 mockJsonObjectPerm1.put("action", "*");
1251 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1252 mockJsonObjectPerm2.put("instance", "test_instance2");
1253 mockJsonObjectPerm2.put("action", "*");
1254 List<JSONObject> permsList = new ArrayList<>();
1255 permsList.add(mockJsonObjectPerm1);
1256 permsList.add(mockJsonObjectPerm2);
1257 mockJsonObjectRole.put("name", "com.test.app.global_test");
1258 mockJsonObjectRole.put("perms", permsList);
1259 mockJsonObjectRole.put("description",
1260 "{\"id\":\"1111\",\"name\":\"global_test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
1261 List<JSONObject> roleList = new ArrayList<>();
1262 roleList.add(mockJsonObjectRole);
1263 mockJsonObjectFinalRole.put("role", roleList);
1264 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1265 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1266 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1267 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1268 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1269 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1270 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1271 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1272 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1273 final Map<String, String> params = new HashMap<>();
1274 params.put("uebKey", app.getUebKey());
1275 params.put("roleId", String.valueOf(getEPRole.getId()));
1276 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1277 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1278 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1279 bulkUploadUserRoles.setOrgUserId("guestT");
1280 bulkUploadUserRoles.setRoleName("Test2");
1281 userRolesList.add(bulkUploadUserRoles);
1282 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1283 .thenReturn(userRolesList);
1285 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1287 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1288 .thenReturn("@test.com");
1289 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1290 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1291 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1292 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1293 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1294 appRoleFuncsParams.put("appId", app.getId());
1295 appRoleFuncsParams.put("roleId", getEPRole.getId());
1297 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1298 .thenReturn(appRoleFunctionList);
1299 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1300 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1301 final Map<String, String> getAppFunctionParams = new HashMap<>();
1302 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1303 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1304 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1305 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1306 v2RoleFunction.add(v2RoleFunction1);
1307 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1308 .thenReturn(v2RoleFunction);
1309 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1310 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1311 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1312 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1313 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1314 v2RoleFunction2.add(v2RoleFunction3);
1315 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1316 .thenReturn(v2RoleFunction2);
1317 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1319 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1320 assertEquals(expected, actual);
1324 public void saveRoleForPartnerApplicationUpdateTest() throws Exception {
1325 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1326 PowerMockito.mockStatic(EcompPortalUtils.class);
1327 PowerMockito.mockStatic(SystemProperties.class);
1328 EPApp app = mockApp();
1330 Role addRoleTest = new Role();
1331 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1332 RoleFunction roleFunc = new RoleFunction();
1333 roleFunc.setName("Test Name");
1334 roleFunc.setCode("test_type|test_instance|*");
1335 RoleFunction roleFunc2 = new RoleFunction();
1336 roleFunc2.setName("Test Name3");
1337 roleFunc2.setCode("test_type3|test_instance3|*");
1338 roleFuncSet.add(roleFunc);
1339 roleFuncSet.add(roleFunc2);
1340 addRoleTest.setActive(false);
1341 addRoleTest.setName("Test2");
1342 addRoleTest.setId(22l);
1343 addRoleTest.setRoleFunctions(roleFuncSet);
1344 List<EPApp> appList = new ArrayList<>();
1345 final Map<String, String> appUebkeyParams = new HashMap<>();
1347 appUebkeyParams.put("appKey", app.getUebKey());
1348 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1349 .thenReturn(appList);
1350 List<EPRole> globalRoles = new ArrayList<>();
1351 EPRole globalRole = new EPRole();
1352 globalRole.setName("global_test");
1353 globalRole.setId(1111l);
1354 globalRole.setActive(true);
1355 globalRoles.add(globalRole);
1356 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1357 List<EPRole> epRoleList = new ArrayList<>();
1358 EPRole getEPRole = new EPRole();
1359 getEPRole.setName("Test2");
1360 getEPRole.setId(2l);
1361 getEPRole.setActive(true);
1362 getEPRole.setAppRoleId(22l);
1363 epRoleList.add(getEPRole);
1364 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1365 getPortalAppRoleParams.put("appRoleId", addRoleTest.getId());
1366 getPortalAppRoleParams.put("appId", app.getId());
1367 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPortalAppRoleParams, null))
1368 .thenReturn(epRoleList);
1369 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1370 HttpHeaders headers = new HttpHeaders();
1371 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1372 JSONObject mockJsonObjectRole = new JSONObject();
1373 JSONObject mockJsonObjectFinalRole = new JSONObject();
1374 JSONObject mockJsonObjectPerm1 = new JSONObject();
1375 JSONObject mockJsonObjectPerm2 = new JSONObject();
1376 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1377 mockJsonObjectPerm1.put("instance", "test_instance");
1378 mockJsonObjectPerm1.put("action", "*");
1379 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1380 mockJsonObjectPerm2.put("instance", "test_instance2");
1381 mockJsonObjectPerm2.put("action", "*");
1382 List<JSONObject> permsList = new ArrayList<>();
1383 permsList.add(mockJsonObjectPerm1);
1384 permsList.add(mockJsonObjectPerm2);
1385 mockJsonObjectRole.put("name", "com.test.app.Test");
1386 mockJsonObjectRole.put("perms", permsList);
1387 mockJsonObjectRole.put("description",
1388 "{\"id\":\"2\",\"name\":\"Test2\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"22\"}");
1389 List<JSONObject> roleList = new ArrayList<>();
1390 roleList.add(mockJsonObjectRole);
1391 mockJsonObjectFinalRole.put("role", roleList);
1392 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1393 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1394 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1395 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1396 final Map<String, String> getPartnerAppRoleParams = new HashMap<>();
1397 getPartnerAppRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
1398 getPartnerAppRoleParams.put("appId", String.valueOf(app.getId()));
1399 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1400 getPartnerAppRoleParams, null)).thenReturn(epRoleList);
1401 ResponseEntity<String> updateRoleResponse = new ResponseEntity<>(HttpStatus.OK);
1402 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
1403 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateRoleResponse);
1404 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1405 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1406 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1407 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1408 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1409 final Map<String, String> params = new HashMap<>();
1410 params.put("uebKey", app.getUebKey());
1411 params.put("roleId", String.valueOf(getEPRole.getId()));
1412 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1413 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1414 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1415 bulkUploadUserRoles.setOrgUserId("guestT");
1416 bulkUploadUserRoles.setRoleName("Test2");
1417 userRolesList.add(bulkUploadUserRoles);
1418 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1419 .thenReturn(userRolesList);
1421 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1423 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1424 .thenReturn("@test.com");
1425 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1426 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1427 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1428 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1429 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1430 appRoleFuncsParams.put("appId", app.getId());
1431 appRoleFuncsParams.put("roleId", getEPRole.getId());
1433 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1434 .thenReturn(appRoleFunctionList);
1435 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1436 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1437 final Map<String, String> getAppFunctionParams = new HashMap<>();
1438 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1439 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1440 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1441 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1442 v2RoleFunction.add(v2RoleFunction1);
1443 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1444 .thenReturn(v2RoleFunction);
1445 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1446 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1447 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1448 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1449 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1450 v2RoleFunction2.add(v2RoleFunction3);
1451 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1452 .thenReturn(v2RoleFunction2);
1453 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1455 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1456 assertEquals(expected, actual);
1460 public void saveGlobalRoleFunctionsForPartnerApplicationUpdateTest() throws Exception {
1461 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1462 PowerMockito.mockStatic(EcompPortalUtils.class);
1463 PowerMockito.mockStatic(SystemProperties.class);
1464 EPApp app = mockApp();
1466 Role addRoleTest = new Role();
1467 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1468 RoleFunction roleFunc = new RoleFunction();
1469 roleFunc.setName("Test Name");
1470 roleFunc.setCode("test_type|test_instance|*");
1471 RoleFunction roleFunc2 = new RoleFunction();
1472 roleFunc2.setName("Test Name3");
1473 roleFunc2.setCode("test_type3|test_instance3|*");
1474 roleFuncSet.add(roleFunc);
1475 roleFuncSet.add(roleFunc2);
1476 addRoleTest.setActive(true);
1477 addRoleTest.setName("global_test");
1478 addRoleTest.setId(1111l);
1479 addRoleTest.setRoleFunctions(roleFuncSet);
1480 List<EPApp> appList = new ArrayList<>();
1481 final Map<String, String> appUebkeyParams = new HashMap<>();
1483 appUebkeyParams.put("appKey", app.getUebKey());
1484 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1485 .thenReturn(appList);
1486 List<EPRole> globalRoles = new ArrayList<>();
1487 EPRole globalRole = new EPRole();
1488 globalRole.setName("global_test");
1489 globalRole.setId(1111l);
1490 globalRole.setActive(true);
1491 EPRole globalRole2 = new EPRole();
1492 globalRole2.setName("global_test2");
1493 globalRole2.setId(2222l);
1494 globalRole2.setActive(true);
1495 globalRoles.add(globalRole);
1496 globalRoles.add(globalRole2);
1497 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1498 List<EPRole> getGlobalRoles = new ArrayList<>();
1499 EPRole getEPGlobalRole = new EPRole();
1500 getEPGlobalRole.setName("global_test");
1501 getEPGlobalRole.setId(1111l);
1502 getEPGlobalRole.setActive(true);
1503 getGlobalRoles.add(getEPGlobalRole);
1504 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1505 getPortalAppRoleParams.put("roleId", globalRole.getId());
1506 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1507 .thenReturn(getGlobalRoles);
1508 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1509 Mockito.when(epAppCommonServiceImpl.getApp(PortalConstants.PORTAL_APP_ID)).thenReturn(app);
1510 JSONObject mockJsonObjectPerm = new JSONObject();
1511 JSONObject mockJsonObjectPerm2 = new JSONObject();
1512 JSONObject mockJsonObjectPerm3 = new JSONObject();
1513 JSONObject mockJsonObjectPerm4 = new JSONObject();
1514 JSONObject mockJsonObjectFinalPerm = new JSONObject();
1515 mockJsonObjectPerm.put("type", "com.test.app.test_type");
1516 mockJsonObjectPerm.put("instance", "test_instance");
1517 mockJsonObjectPerm.put("action", "*");
1518 mockJsonObjectPerm.put("description", "Test Name");
1519 mockJsonObjectPerm2.put("type", "com.test.app.access");
1520 mockJsonObjectPerm2.put("instance", "test_instance2");
1521 mockJsonObjectPerm2.put("action", "*");
1522 mockJsonObjectPerm2.put("description", "Test Name2");
1523 mockJsonObjectPerm3.put("type", "com.test.app.test_type3");
1524 mockJsonObjectPerm3.put("instance", "test_instance3");
1525 mockJsonObjectPerm3.put("action", "*");
1526 mockJsonObjectPerm3.put("description", "Test Name3");
1527 mockJsonObjectPerm4.put("type", "com.test.app.test_type4");
1528 mockJsonObjectPerm4.put("instance", "test_instance4");
1529 mockJsonObjectPerm4.put("action", "*");
1530 mockJsonObjectPerm4.put("description", "Test Name4");
1531 List<JSONObject> mockJson = new ArrayList<>();
1532 mockJson.add(mockJsonObjectPerm);
1533 mockJson.add(mockJsonObjectPerm2);
1534 mockJson.add(mockJsonObjectPerm3);
1535 mockJson.add(mockJsonObjectPerm4);
1536 mockJsonObjectFinalPerm.put("perm", mockJson);
1537 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
1538 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1539 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1540 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1541 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
1542 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1543 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
1544 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1545 final Map<String, Long> epAppRoleFuncParams = new HashMap<>();
1546 epAppRoleFuncParams.put("requestedAppId", app.getId());
1547 epAppRoleFuncParams.put("roleId", globalRole.getId());
1548 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
1549 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
1550 mockGlobalRole.setActive(true);
1551 mockGlobalRole.setAppId(app.getId());
1552 mockGlobalRole.setRoleId(1111l);
1553 mockGlobalRole.setRoleName("global_test");
1554 mockGlobalRole.setFunctionCd("test_type4|test_instance4|*");
1555 mockGlobalRole.setFunctionName("test name");
1556 mockGlobalRoles.add(mockGlobalRole);
1557 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", epAppRoleFuncParams, null))
1558 .thenReturn(mockGlobalRoles);
1559 ResponseEntity<String> delResponse = new ResponseEntity<>(HttpStatus.OK);
1560 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1561 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1562 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1563 appRoleFuncsParams.put("appId", app.getId());
1564 appRoleFuncsParams.put("roleId", globalRole.getId());
1565 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1566 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
1567 epAppRoleFunction.setAppId(app.getId());
1568 epAppRoleFunction.setRoleAppId("1");
1569 epAppRoleFunction.setCode("test");
1570 epAppRoleFunction.setRoleId(1111l);
1571 appRoleFunctionList.add(epAppRoleFunction);
1573 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1574 .thenReturn(appRoleFunctionList);
1575 final Map<String, String> getAppFunctionParams = new HashMap<>();
1576 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1577 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1578 Mockito.when(EcompPortalUtils.getFunctionCode("test_type4|test_instance4|*")).thenReturn("test_instance4");
1579 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1580 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1581 List<CentralV2RoleFunction> roleFunction = new ArrayList<>();
1582 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, roleFunc.getCode(),
1583 roleFunc.getName(), app.getId(), null);
1584 roleFunction.add(centralV2RoleFunction);
1585 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1586 .thenReturn(roleFunction);
1587 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1588 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1589 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1590 List<CentralV2RoleFunction> roleFunction2 = new ArrayList<>();
1591 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, roleFunc2.getCode(),
1592 roleFunc2.getName(), app.getId(), null);
1593 roleFunction2.add(centralV2RoleFunction2);
1594 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1595 .thenReturn(roleFunction2);
1596 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1598 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1599 assertEquals(expected, actual);
1603 public void syncRoleFunctionFromExternalAccessSystemTest() {
1604 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1605 PowerMockito.mockStatic(EcompPortalUtils.class);
1606 PowerMockito.mockStatic(SystemProperties.class);
1607 EPApp app = mockApp();
1609 JSONObject mockJsonObjectFinalPerm = new JSONObject();
1610 JSONObject mockJsonObjectPerm = new JSONObject();
1611 JSONObject mockJsonObjectPerm2 = new JSONObject();
1612 JSONObject mockJsonObjectPerm3 = new JSONObject();
1613 mockJsonObjectPerm.put("type", "com.test.app.test_type");
1614 mockJsonObjectPerm.put("instance", "test_instance");
1615 mockJsonObjectPerm.put("action", "*");
1616 mockJsonObjectPerm.put("description", "test_name");
1617 List<String> rolePermList = new ArrayList<>();
1618 rolePermList.add("com.test.app|test1");
1619 mockJsonObjectPerm.put("roles", rolePermList);
1620 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1621 mockJsonObjectPerm2.put("instance", "test_instance2");
1622 List<String> rolePermList2 = new ArrayList<>();
1623 rolePermList2.add("com.test.app|test1");
1624 rolePermList2.add("com.test.app|test2");
1625 rolePermList2.add("com.test.app|test6");
1626 rolePermList2.add("com.test.app.new|global_test");
1627 mockJsonObjectPerm2.put("action", "*");
1628 mockJsonObjectPerm2.put("roles", rolePermList2);
1629 mockJsonObjectPerm2.put("description", "test_name2");
1630 mockJsonObjectPerm3.put("type", "com.test.app.access");
1631 mockJsonObjectPerm3.put("instance", "test_instance3");
1632 mockJsonObjectPerm3.put("action", "*");
1633 mockJsonObjectPerm3.put("description", "test_name3");
1634 List<JSONObject> permsList = new ArrayList<>();
1635 permsList.add(mockJsonObjectPerm);
1636 permsList.add(mockJsonObjectPerm2);
1637 permsList.add(mockJsonObjectPerm3);
1638 mockJsonObjectFinalPerm.put("perm", permsList);
1639 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
1640 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1641 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1642 final Map<String, Long> params = new HashMap<>();
1643 params.put(APP_ID, app.getId());
1644 List<CentralV2RoleFunction> appFunctions = new ArrayList<>();
1645 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*",
1646 "test_name", app.getId(), null);
1647 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_instance2", "test_name2",
1649 CentralV2RoleFunction centralV2RoleFunction3 = new CentralV2RoleFunction(null, "test_instance5", "test_name5",
1651 appFunctions.add(centralV2RoleFunction);
1652 appFunctions.add(centralV2RoleFunction2);
1653 appFunctions.add(centralV2RoleFunction3);
1654 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(appFunctions);
1655 List<EPRole> globalRoles = new ArrayList<>();
1656 EPRole globalRole = new EPRole();
1657 globalRole.setName("global_test");
1658 globalRole.setId(1111l);
1659 globalRole.setActive(true);
1660 globalRoles.add(globalRole);
1661 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1662 List<EPRole> getCurrentRoleList = new ArrayList<>();
1663 EPRole getEPRole = new EPRole();
1664 getEPRole.setName("test1");
1665 getEPRole.setId(2l);
1666 getEPRole.setActive(true);
1667 EPRole getEPRole2 = new EPRole();
1668 getEPRole2.setName("global_test");
1669 getEPRole2.setId(1111l);
1670 getEPRole2.setActive(true);
1671 EPRole getEPRole3 = new EPRole();
1672 getEPRole3.setName("test2");
1673 getEPRole3.setId(4l);
1674 getEPRole3.setActive(true);
1675 getCurrentRoleList.add(getEPRole);
1676 getCurrentRoleList.add(getEPRole2);
1677 getCurrentRoleList.add(getEPRole3);
1678 final Map<String, Long> appParams = new HashMap<>();
1679 appParams.put("appId", app.getId());
1680 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
1681 .thenReturn(getCurrentRoleList);
1682 final Map<String, String> appSyncFuncsParams = new HashMap<>();
1683 appSyncFuncsParams.put("appId", String.valueOf(app.getId()));
1684 appSyncFuncsParams.put("functionCd", "");
1685 List<CentralV2RoleFunction> roleFunctionList = new ArrayList<>();
1686 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1687 .thenReturn(roleFunctionList);
1688 String code = centralV2RoleFunction.getCode();
1689 appSyncFuncsParams.put("functionCd", code);
1690 CentralV2RoleFunction getCentralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*",
1691 "test_name", app.getId(), null);
1692 roleFunctionList.add(getCentralV2RoleFunction);
1693 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1694 .thenReturn(roleFunctionList);
1695 List<LocalRole> localRoles = new ArrayList<>();
1696 LocalRole localRole = new LocalRole();
1697 localRole.setRoleId(2);
1698 localRole.setRolename("test1");
1699 LocalRole localRole2 = new LocalRole();
1700 localRole2.setRoleId(3);
1701 localRole2.setRolename("test3");
1702 localRoles.add(localRole);
1703 localRoles.add(localRole2);
1704 final Map<String, String> appRoleFuncParams = new HashMap<>();
1705 appRoleFuncParams.put("functionCd", "test_type2|test_instance2|*");
1706 appRoleFuncParams.put("appId", String.valueOf(app.getId()));
1707 Mockito.when(dataAccessService.executeNamedQuery("getCurrentAppRoleFunctions", appRoleFuncParams, null))
1708 .thenReturn(localRoles);
1709 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app", app.getNameSpace())).thenReturn(true);
1710 Mockito.when(EcompPortalUtils.getFunctionCode("test_type2|test_instance2|*")).thenReturn("test_instance2");
1711 appSyncFuncsParams.put("functionCd", "test_instance2");
1712 List<CentralV2RoleFunction> roleFunctionList2 = new ArrayList<>();
1713 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1714 .thenReturn(roleFunctionList2);
1715 String code2 = "test_type2|test_instance2|*";
1716 appSyncFuncsParams.put("functionCd", code2);
1717 CentralV2RoleFunction getCentralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_type2|test_instance2|*",
1718 "test_name2", app.getId(), null);
1719 roleFunctionList2.add(getCentralV2RoleFunction2);
1720 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1721 .thenReturn(roleFunctionList2);
1722 final Map<String, Long> params3 = new HashMap<>();
1723 params3.put("appId", app.getId());
1724 params3.put("roleId", getEPRole2.getId());
1725 List<EPAppRoleFunction> currentGlobalRoleFunctionsList = new ArrayList<>();
1726 EPAppRoleFunction addGlobalRoleFunction = new EPAppRoleFunction();
1727 addGlobalRoleFunction.setAppId(app.getId());
1728 addGlobalRoleFunction.setCode("test_type|test_instance|*");
1729 addGlobalRoleFunction.setRoleId(1111l);
1730 currentGlobalRoleFunctionsList.add(addGlobalRoleFunction);
1731 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", params3, null))
1732 .thenReturn(currentGlobalRoleFunctionsList);
1733 final Map<String, String> roleParams = new HashMap<>();
1734 roleParams.put(APP_ROLE_NAME_PARAM, "test6");
1735 roleParams.put("appId", String.valueOf(app.getId()));
1736 List<EPRole> roleCreated = new ArrayList<>();
1737 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null))
1738 .thenReturn(roleCreated);
1739 final Map<String, String> getRoleByNameParams = new HashMap<>();
1740 getRoleByNameParams.put(APP_ROLE_NAME_PARAM, "test6");
1741 getRoleByNameParams.put("appId", String.valueOf(app.getId()));
1742 EPRole getNewEPRole = new EPRole();
1743 getNewEPRole.setName("test6");
1744 getNewEPRole.setId(8l);
1745 getNewEPRole.setActive(true);
1746 List<EPRole> roleCreated2 = new ArrayList<>();
1747 roleCreated2.add(getNewEPRole);
1748 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1749 getRoleByNameParams, null)).thenReturn(roleCreated2);
1750 EPRole getNewEPRoleFinal = new EPRole();
1751 getNewEPRoleFinal.setName("test6");
1752 getNewEPRoleFinal.setId(8l);
1753 getNewEPRoleFinal.setActive(true);
1754 getNewEPRoleFinal.setAppRoleId(8l);
1755 final Map<String, String> getRoleByNameParams2 = new HashMap<>();
1756 getRoleByNameParams2.put(APP_ROLE_NAME_PARAM, "test6");
1757 getRoleByNameParams2.put("appId", String.valueOf(app.getId()));
1758 List<EPRole> roleCreated3 = new ArrayList<>();
1759 roleCreated3.add(getNewEPRole);
1760 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1761 getRoleByNameParams2, null)).thenReturn(roleCreated3);
1762 List<EPRole> roleInfo = new ArrayList<>();
1763 roleInfo.add(getNewEPRoleFinal);
1764 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1765 getPartnerAppRoleParams.put("appRoleId", getNewEPRoleFinal.getId());
1766 getPartnerAppRoleParams.put("appId", app.getId());
1767 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
1768 .thenReturn(roleInfo);
1769 externalAccessRolesServiceImpl.syncRoleFunctionFromExternalAccessSystem(app);
1773 public void syncApplicationRolesWithEcompDBTest() {
1774 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1775 PowerMockito.mockStatic(EcompPortalUtils.class);
1776 PowerMockito.mockStatic(SystemProperties.class);
1777 EPApp app = mockApp();
1779 JSONObject mockJsonObjectRole = new JSONObject();
1780 JSONObject mockJsonObjectRole2 = new JSONObject();
1781 JSONObject mockJsonObjectFinalRole = new JSONObject();
1782 JSONObject mockJsonObjectPerm1 = new JSONObject();
1783 JSONObject mockJsonObjectPerm2 = new JSONObject();
1784 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1785 mockJsonObjectPerm1.put("instance", "test_instance");
1786 mockJsonObjectPerm1.put("action", "*");
1787 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1788 mockJsonObjectPerm2.put("instance", "test_instance2");
1789 mockJsonObjectPerm2.put("action", "*");
1790 List<JSONObject> permsList = new ArrayList<>();
1791 permsList.add(mockJsonObjectPerm1);
1792 permsList.add(mockJsonObjectPerm2);
1793 mockJsonObjectRole.put("name", "com.test.app.Test");
1794 mockJsonObjectRole.put("perms", permsList);
1795 mockJsonObjectRole.put("description",
1796 "{\"id\":\"2\",\"name\":\"test1\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"2\"}");
1797 mockJsonObjectRole2.put("name", "com.test.app.Test2");
1798 List<JSONObject> permsList2 = new ArrayList<>();
1799 permsList2.add(mockJsonObjectPerm1);
1800 mockJsonObjectRole2.put("perms", permsList2);
1801 List<JSONObject> roleList = new ArrayList<>();
1802 roleList.add(mockJsonObjectRole);
1803 roleList.add(mockJsonObjectRole2);
1804 mockJsonObjectFinalRole.put("role", roleList);
1805 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1806 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1807 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1808 List<EPRole> getCurrentRoleList = new ArrayList<>();
1809 EPRole getEPRole = new EPRole();
1810 getEPRole.setName("Test");
1811 getEPRole.setId(2l);
1812 getEPRole.setAppId(app.getId());
1813 getEPRole.setAppRoleId(2l);
1814 getEPRole.setActive(true);
1815 EPRole getEPRole2 = new EPRole();
1816 getEPRole2.setName("Test3");
1817 getEPRole2.setId(3l);
1818 getEPRole.setAppId(app.getId());
1819 getEPRole.setAppRoleId(3l);
1820 getEPRole2.setActive(true);
1821 getCurrentRoleList.add(getEPRole);
1822 getCurrentRoleList.add(getEPRole2);
1823 final Map<String, Long> appParams = new HashMap<>();
1824 appParams.put("appId", app.getId());
1825 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
1826 .thenReturn(getCurrentRoleList);
1827 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type", app.getNameSpace()))
1829 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type2", app.getNameSpace()))
1831 List<EPAppRoleFunction> appRoleFunctions = new ArrayList<>();
1832 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
1833 epAppRoleFunction.setAppId(app.getId());
1834 epAppRoleFunction.setCode("test_type|test_instance|*");
1835 epAppRoleFunction.setRoleId(getEPRole.getId());
1836 appRoleFunctions.add(epAppRoleFunction);
1837 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1838 appRoleFuncsParams.put("appId", app.getId());
1839 appRoleFuncsParams.put("roleId", Long.valueOf(getEPRole.getId()));
1841 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1842 .thenReturn(appRoleFunctions);
1843 List<CentralV2RoleFunction> getV2RoleFunction = new ArrayList<>();
1844 final Map<String, String> appFuncsParams = new HashMap<>();
1845 appFuncsParams.put("appId", String.valueOf(app.getId()));
1846 appFuncsParams.put("functionCd", "test_instance2");
1847 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null))
1848 .thenReturn(getV2RoleFunction);
1849 appFuncsParams.put("functionCd", "test_type2|test_instance2|*");
1850 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
1851 centralV2RoleFunction.setAppId(app.getId());
1852 centralV2RoleFunction.setCode("test_type2|test_instance2|*");
1853 centralV2RoleFunction.setName("test_name2");
1854 getV2RoleFunction.add(centralV2RoleFunction);
1855 final Map<String, String> extRoleParams = new HashMap<>();
1856 List<EPRole> roleListDeactivate = new ArrayList<>();
1857 extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3");
1858 extRoleParams.put(APP_ID, app.getId().toString());
1859 EPRole getEPRoleDeactivate = new EPRole();
1860 getEPRoleDeactivate.setName("Test3");
1861 getEPRoleDeactivate.setId(3l);
1862 getEPRoleDeactivate.setAppId(app.getId());
1863 getEPRoleDeactivate.setAppRoleId(3l);
1864 roleListDeactivate.add(getEPRoleDeactivate);
1866 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, extRoleParams, null))
1867 .thenReturn(roleListDeactivate);
1868 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null))
1869 .thenReturn(getV2RoleFunction);
1870 List<EPRole> updateLocalFromExtAuth = new ArrayList<>();
1871 updateLocalFromExtAuth.add(getEPRole);
1872 final Map<String, String> roleParams = new HashMap<>();
1873 roleParams.put(APP_ROLE_NAME_PARAM, getEPRole.getName());
1874 roleParams.put(APP_ID, app.getId().toString());
1875 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null))
1876 .thenReturn(updateLocalFromExtAuth);
1877 roleParams.put(APP_ROLE_NAME_PARAM, getEPRole2.getName());
1878 List<EPRole> updateLocalFromExtAuth2 = new ArrayList<>();
1879 updateLocalFromExtAuth.add(getEPRole);
1880 Mockito.when(dataAccessService.executeNamedQuery("getRoletoUpdateInExternalAuthSystem", roleParams, null))
1881 .thenReturn(updateLocalFromExtAuth2);
1882 final Map<String, String> globalRoleParams = new HashMap<>();
1883 globalRoleParams.put("appId", String.valueOf(app.getId()));
1884 globalRoleParams.put("appRoleName", "Test2");
1885 List<EPRole> addNewRoleList = new ArrayList<>();
1886 EPRole addRoleInLocal = new EPRole();
1887 addRoleInLocal.setName("Test2");
1888 addRoleInLocal.setId(4l);
1889 addRoleInLocal.setAppId(app.getId());
1890 addRoleInLocal.setActive(true);
1891 addNewRoleList.add(addRoleInLocal);
1893 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, globalRoleParams, null))
1894 .thenReturn(addNewRoleList);
1895 final Map<String, String> params = new HashMap<>();
1896 params.put(APP_ROLE_NAME_PARAM, "Test2");
1897 params.put(APP_ID, app.getId().toString());
1898 addRoleInLocal.setAppRoleId(4l);
1899 addNewRoleList.add(addRoleInLocal);
1900 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, params, null))
1901 .thenReturn(addNewRoleList);
1902 externalAccessRolesServiceImpl.syncApplicationRolesWithEcompDB(app);
1906 public void deleteDependencyRoleRecord() throws Exception {
1907 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1908 PowerMockito.mockStatic(EcompPortalUtils.class);
1909 PowerMockito.mockStatic(SystemProperties.class);
1910 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
1911 EPApp app = mockApp();
1913 EPUser user = mockUser.mockEPUser();
1914 List<EPApp> appList = new ArrayList<>();
1915 final Map<String, String> appUebkeyParams = new HashMap<>();
1917 appUebkeyParams.put("appKey", app.getUebKey());
1918 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1919 .thenReturn(appList);
1920 List<EPRole> epRoleList = new ArrayList<>();
1921 EPRole getEPRole = new EPRole();
1922 getEPRole.setName("Test");
1923 getEPRole.setId(2l);
1924 getEPRole.setAppRoleId(2l);
1925 getEPRole.setActive(true);
1926 epRoleList.add(getEPRole);
1927 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1928 getPartnerAppRoleParams.put("appRoleId", getEPRole.getId());
1929 getPartnerAppRoleParams.put("appId", app.getId());
1930 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
1931 .thenReturn(epRoleList);
1932 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1933 JSONObject getUser = new JSONObject();
1934 getUser.put("name", "com.test.app.test1");
1935 ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
1936 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1937 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1938 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
1939 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1940 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
1941 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
1942 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l,
1943 app.getUebKey(), user.getOrgUserId());
1944 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1945 assertEquals(expected, actual);
1949 public void deleteDependencyRoleRecordForPortal() throws Exception {
1950 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1951 PowerMockito.mockStatic(EcompPortalUtils.class);
1952 PowerMockito.mockStatic(SystemProperties.class);
1953 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
1954 EPApp app = mockApp();
1956 EPUser user = mockUser.mockEPUser();
1957 List<EPApp> appList = new ArrayList<>();
1958 final Map<String, String> appUebkeyParams = new HashMap<>();
1960 appUebkeyParams.put("appKey", app.getUebKey());
1961 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1962 .thenReturn(appList);
1963 List<EPRole> epRoleList = new ArrayList<>();
1964 EPRole getEPRole = new EPRole();
1965 getEPRole.setName("Test");
1966 getEPRole.setId(2l);
1967 getEPRole.setAppRoleId(2l);
1968 getEPRole.setActive(true);
1969 epRoleList.add(getEPRole);
1970 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1971 getPartnerAppRoleParams.put("roleId", getEPRole.getId());
1972 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPartnerAppRoleParams, null))
1973 .thenReturn(epRoleList);
1974 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1975 JSONObject getUser = new JSONObject();
1976 getUser.put("name", "com.test.app.test1");
1977 ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
1978 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1979 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1980 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
1981 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1982 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
1983 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
1984 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l,
1985 app.getUebKey(), user.getOrgUserId());
1986 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1987 assertEquals(expected, actual);
1991 public void bulkUploadFunctionsTest() throws Exception {
1992 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1993 PowerMockito.mockStatic(EcompPortalUtils.class);
1994 PowerMockito.mockStatic(SystemProperties.class);
1995 EPApp app = mockApp();
1997 List<EPApp> appList = new ArrayList<>();
1998 final Map<String, String> appUebkeyParams = new HashMap<>();
2000 appUebkeyParams.put("appKey", app.getUebKey());
2001 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2002 .thenReturn(appList);
2003 List<RoleFunction> roleFuncList = new ArrayList<>();
2004 RoleFunction roleFunc = new RoleFunction();
2005 roleFunc.setCode("test_code");
2006 roleFunc.setName("test_name");
2007 RoleFunction roleFunc2 = new RoleFunction();
2008 roleFunc2.setCode("test_code2");
2009 roleFunc2.setName("test_name2");
2010 roleFuncList.add(roleFunc);
2011 roleFuncList.add(roleFunc2);
2012 Mockito.when(dataAccessService.executeNamedQuery("getAllFunctions", null, null)).thenReturn(roleFuncList);
2013 JSONObject perm = new JSONObject();
2014 JSONObject permList = new JSONObject();
2015 perm.put("type", app.getNameSpace() + ".access");
2016 perm.put("instance", "type_instance");
2017 perm.put("action", "*");
2018 List<JSONObject> addPerms = new ArrayList<>();
2020 permList.put("perm", addPerms);
2021 ResponseEntity<String> getResponse = new ResponseEntity<>(permList.toString(), HttpStatus.OK);
2022 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
2023 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2024 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2025 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2026 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2027 Integer actual = externalAccessRolesServiceImpl.bulkUploadFunctions(app.getUebKey());
2028 Integer expected = 2;
2029 assertEquals(expected, actual);
2033 public void bulkUploadRolesTest() throws Exception {
2034 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2035 PowerMockito.mockStatic(EcompPortalUtils.class);
2036 PowerMockito.mockStatic(SystemProperties.class);
2037 EPApp app = mockApp();
2039 List<EPApp> appList = new ArrayList<>();
2040 final Map<String, String> appUebkeyParams = new HashMap<>();
2042 appUebkeyParams.put("appKey", app.getUebKey());
2043 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2044 .thenReturn(appList);
2045 List<EPRole> epRoleList = new ArrayList<>();
2046 EPRole getEPRole = new EPRole();
2047 getEPRole.setName("Test");
2048 getEPRole.setId(2l);
2049 getEPRole.setAppRoleId(2l);
2050 getEPRole.setActive(true);
2051 EPRole getEPRole2 = new EPRole();
2052 getEPRole2.setName("Test2");
2053 getEPRole2.setId(3l);
2054 getEPRole2.setAppRoleId(3l);
2055 getEPRole2.setActive(true);
2056 epRoleList.add(getEPRole);
2057 epRoleList.add(getEPRole2);
2058 final Map<String, Long> appParams = new HashMap<>();
2059 appParams.put("appId", app.getId());
2060 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
2061 .thenReturn(epRoleList);
2062 List<EPRole> epRoleList1 = new ArrayList<>();
2063 EPRole ePRole = new EPRole();
2064 ePRole.setName("Test");
2066 ePRole.setAppRoleId(2l);
2067 ePRole.setActive(true);
2068 epRoleList1.add(ePRole);
2069 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
2070 getPartnerAppRoleParams.put("appRoleId", ePRole.getId());
2071 getPartnerAppRoleParams.put("appId", app.getId());
2072 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
2073 .thenReturn(epRoleList1);
2074 List<EPRole> epRoleList2 = new ArrayList<>();
2075 EPRole ePRole2 = new EPRole();
2076 ePRole2.setName("Test2");
2078 ePRole2.setAppRoleId(3l);
2079 ePRole2.setActive(true);
2080 epRoleList2.add(ePRole2);
2081 final Map<String, Long> getPartnerAppRoleParams2 = new HashMap<>();
2082 getPartnerAppRoleParams2.put("appRoleId", ePRole2.getId());
2083 getPartnerAppRoleParams2.put("appId", app.getId());
2084 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams2, null))
2085 .thenReturn(epRoleList2);
2086 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2087 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2088 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2089 Integer actual = externalAccessRolesServiceImpl.bulkUploadRoles(app.getUebKey());
2090 Integer expected = 3;
2091 assertEquals(expected, actual);
2095 public void bulkUploadUserRolesTest() throws Exception {
2096 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2097 PowerMockito.mockStatic(EcompPortalUtils.class);
2098 PowerMockito.mockStatic(SystemProperties.class);
2099 EPApp app = mockApp();
2101 EPUser user = mockUser.mockEPUser();
2102 List<EPApp> appList = new ArrayList<>();
2103 final Map<String, String> appUebkeyParams = new HashMap<>();
2105 appUebkeyParams.put("appKey", app.getUebKey());
2106 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2107 .thenReturn(appList);
2108 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
2109 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
2110 bulkUploadUserRoles.setAppNameSpace(app.getName());
2111 bulkUploadUserRoles.setOrgUserId(user.getOrgUserId());
2112 bulkUploadUserRoles.setRoleName("Test1");
2113 BulkUploadUserRoles bulkUploadUserRoles2 = new BulkUploadUserRoles();
2114 bulkUploadUserRoles2.setAppNameSpace(app.getName());
2115 bulkUploadUserRoles2.setOrgUserId(user.getOrgUserId());
2116 bulkUploadUserRoles2.setRoleName("Test2");
2117 userRolesList.add(bulkUploadUserRoles);
2118 userRolesList.add(bulkUploadUserRoles2);
2119 final Map<String, String> appParams = new HashMap<>();
2120 appParams.put("uebKey", app.getUebKey());
2121 Mockito.when(dataAccessService.executeNamedQuery("getBulkUserRoles", appParams, null))
2122 .thenReturn(userRolesList);
2123 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2124 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2125 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2126 Integer actual = externalAccessRolesServiceImpl.bulkUploadUserRoles(app.getUebKey());
2127 Integer expected = 2;
2128 assertEquals(expected, actual);
2132 public void getUserRolesTest() throws Exception {
2133 EPApp app = mockApp();
2134 EPUser user = mockUser.mockEPUser();
2135 List<EPApp> appList = new ArrayList<>();
2136 final Map<String, String> appUebkeyParams = new HashMap<>();
2138 appUebkeyParams.put("appKey", app.getUebKey());
2139 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2140 .thenReturn(appList);
2141 final Map<String, String> userParams = new HashMap<>();
2142 userParams.put("org_user_id", user.getOrgUserId());
2143 List<EPUser> userList = new ArrayList<>();
2144 Set<EPUserApp> userAppSet = user.getEPUserApps();
2145 EPUserApp epUserApp = new EPUserApp();
2146 EPRole epRole = new EPRole();
2147 epRole.setName("test");
2149 epRole.setActive(true);
2150 epRole.setAppRoleId(11l);
2151 epUserApp.setApp(app);
2152 epUserApp.setUserId(user.getId());
2153 epUserApp.setRole(epRole);
2154 userAppSet.add(epUserApp);
2155 user.setUserApps(userAppSet);
2157 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
2158 .thenReturn(userList);
2159 CentralUser actual = externalAccessRolesServiceImpl.getUserRoles(user.getOrgUserId(), app.getUebKey());
2160 assertNotNull(actual);
2163 @SuppressWarnings("unchecked")
2165 public void getActiveRolesTest() throws Exception {
2166 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2167 PowerMockito.mockStatic(EcompPortalUtils.class);
2168 PowerMockito.mockStatic(SystemProperties.class);
2169 PowerMockito.mockStatic(EPUserUtils.class);
2170 PowerMockito.mockStatic(Restrictions.class);
2171 PowerMockito.mockStatic(Criterion.class);
2172 EPApp app = mockApp();
2174 List<EPApp> appList = new ArrayList<>();
2175 final Map<String, String> appUebkeyParams = new HashMap<>();
2177 appUebkeyParams.put("appKey", app.getUebKey());
2178 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2179 .thenReturn(appList);
2180 List<EPRole> epRoles = new ArrayList<>();
2181 EPRole getEPRole = new EPRole();
2182 getEPRole.setName("Test");
2183 getEPRole.setId(2l);
2184 getEPRole.setActive(true);
2185 EPRole getEPRole2 = new EPRole();
2186 getEPRole2.setName("Test2");
2187 getEPRole2.setId(3l);
2188 getEPRole2.setActive(true);
2189 epRoles.add(getEPRole);
2190 epRoles.add(getEPRole2);
2191 List<Criterion> restrictionsList = new ArrayList<Criterion>();
2192 Criterion active_ynCrt = Restrictions.eq("active", Boolean.TRUE);
2193 Criterion appIdCrt = Restrictions.isNull("appId");
2194 Criterion andCrit = Restrictions.and(active_ynCrt, appIdCrt);
2195 restrictionsList.add(andCrit);
2196 Mockito.when((List<EPRole>) dataAccessService.getList(EPRole.class, null, restrictionsList, null))
2197 .thenReturn(epRoles);
2198 final Map<String, Long> params = new HashMap<>();
2199 params.put("roleId", getEPRole.getId());
2200 params.put(APP_ID, app.getId());
2201 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
2202 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|test_instance|*",
2204 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction("test_instance2", "test_name2");
2205 cenRoleFuncList.add(centralV2RoleFunction);
2206 cenRoleFuncList.add(centralV2RoleFunction2);
2207 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
2208 .thenReturn(cenRoleFuncList);
2209 final Map<String, Long> params2 = new HashMap<>();
2210 params2.put("roleId", getEPRole2.getId());
2211 params2.put(APP_ID, app.getId());
2212 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params2, null))
2213 .thenReturn(cenRoleFuncList);
2214 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
2215 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
2216 mockGlobalRole.setActive(true);
2217 mockGlobalRole.setAppId(app.getId());
2218 mockGlobalRole.setRoleId(1111l);
2219 mockGlobalRole.setRoleName("global_test");
2220 mockGlobalRole.setFunctionCd("test_type|test_code|*");
2221 mockGlobalRole.setFunctionName("test name");
2222 mockGlobalRoles.add(mockGlobalRole);
2223 Map<String, Long> params3 = new HashMap<>();
2224 params3.put("appId", app.getId());
2225 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params3, null))
2226 .thenReturn(mockGlobalRoles);
2227 Mockito.when(EcompPortalUtils.getFunctionCode(centralV2RoleFunction.getCode())).thenReturn("test_instance");
2228 Mockito.when(EcompPortalUtils.getFunctionCode(centralV2RoleFunction2.getCode())).thenReturn("test_instance2");
2229 List<CentralV2Role> actual = externalAccessRolesServiceImpl.getActiveRoles(app.getUebKey());
2230 assertEquals(actual.size(), 3);
2234 public void bulkUploadRolesFunctionsTest() throws Exception {
2235 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2236 PowerMockito.mockStatic(EcompPortalUtils.class);
2237 PowerMockito.mockStatic(SystemProperties.class);
2238 EPApp app = mockApp();
2239 List<EPApp> appList = new ArrayList<>();
2240 final Map<String, String> appUebkeyParams = new HashMap<>();
2242 appUebkeyParams.put("appKey", app.getUebKey());
2243 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2244 .thenReturn(appList);
2245 List<EPRole> applicationRoles = new ArrayList<>();
2246 EPRole getEPRole = new EPRole();
2247 getEPRole.setName("Test");
2248 getEPRole.setId(2l);
2249 getEPRole.setActive(true);
2250 EPRole getEPRole2 = new EPRole();
2251 getEPRole2.setName("Test2");
2252 getEPRole2.setId(3l);
2253 getEPRole2.setActive(true);
2254 applicationRoles.add(getEPRole);
2255 applicationRoles.add(getEPRole2);
2256 final Map<String, Long> appParams = new HashMap<>();
2257 appParams.put("appId", app.getId());
2258 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
2259 .thenReturn(applicationRoles);
2260 final Map<String, Long> params = new HashMap<>();
2261 params.put("roleId", getEPRole.getId());
2262 List<BulkUploadRoleFunction> appRoleFunc = new ArrayList<>();
2263 BulkUploadRoleFunction bulkUploadRoleFunction = new BulkUploadRoleFunction();
2264 bulkUploadRoleFunction.setFunctionCd("testcode");
2265 bulkUploadRoleFunction.setFunctionName("test_name");
2266 BulkUploadRoleFunction bulkUploadRoleFunction2 = new BulkUploadRoleFunction();
2267 bulkUploadRoleFunction2.setFunctionCd("menu_testcode2");
2268 bulkUploadRoleFunction2.setFunctionName("test_name2");
2269 appRoleFunc.add(bulkUploadRoleFunction);
2270 appRoleFunc.add(bulkUploadRoleFunction2);
2271 Mockito.when(dataAccessService.executeNamedQuery("uploadAllRoleFunctions", params, null))
2272 .thenReturn(appRoleFunc);
2273 final Map<String, Long> params2 = new HashMap<>();
2274 params2.put("roleId", getEPRole2.getId());
2275 List<BulkUploadRoleFunction> appRoleFunc2 = new ArrayList<>();
2276 appRoleFunc2.add(bulkUploadRoleFunction);
2277 appRoleFunc2.add(bulkUploadRoleFunction2);
2278 Mockito.when(dataAccessService.executeNamedQuery("uploadAllRoleFunctions", params2, null))
2279 .thenReturn(appRoleFunc2);
2280 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.CREATED);
2281 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2282 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2283 Integer actual = externalAccessRolesServiceImpl.bulkUploadRolesFunctions(app.getUebKey());
2284 Integer expected = 4;
2285 assertEquals(actual, expected);
2289 public void bulkUploadPartnerRoleFunctionsTest() throws Exception {
2290 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2291 PowerMockito.mockStatic(EcompPortalUtils.class);
2292 PowerMockito.mockStatic(SystemProperties.class);
2293 EPApp app = mockApp();
2294 List<EPApp> appList = new ArrayList<>();
2295 final Map<String, String> appUebkeyParams = new HashMap<>();
2297 appUebkeyParams.put("appKey", app.getUebKey());
2298 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2299 .thenReturn(appList);
2300 List<EPRole> applicationRoles = new ArrayList<>();
2301 EPRole getEPRole = new EPRole();
2302 getEPRole.setName("Test");
2303 getEPRole.setId(2l);
2304 getEPRole.setActive(true);
2305 EPRole getEPRole2 = new EPRole();
2306 getEPRole2.setName("Test2");
2307 getEPRole2.setId(3l);
2308 getEPRole2.setActive(true);
2309 applicationRoles.add(getEPRole);
2310 applicationRoles.add(getEPRole2);
2311 final Map<String, Long> paramsRoles = new HashMap<>();
2312 paramsRoles.put("appId", app.getId());
2313 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", paramsRoles, null))
2314 .thenReturn(applicationRoles);
2315 final Map<String, Long> params = new HashMap<>();
2316 params.put("roleId", getEPRole.getId());
2317 List<BulkUploadRoleFunction> appRoleFunc = new ArrayList<>();
2318 BulkUploadRoleFunction bulkUploadRoleFunction = new BulkUploadRoleFunction();
2319 bulkUploadRoleFunction.setFunctionCd("testcode");
2320 bulkUploadRoleFunction.setFunctionName("test_name");
2321 BulkUploadRoleFunction bulkUploadRoleFunction2 = new BulkUploadRoleFunction();
2322 bulkUploadRoleFunction2.setFunctionCd("menu_testcode2");
2323 bulkUploadRoleFunction2.setFunctionName("test_name2");
2324 appRoleFunc.add(bulkUploadRoleFunction);
2325 appRoleFunc.add(bulkUploadRoleFunction2);
2326 Mockito.when(dataAccessService.executeNamedQuery("uploadPartnerRoleFunctions", params, null))
2327 .thenReturn(appRoleFunc);
2328 final Map<String, Long> params2 = new HashMap<>();
2329 params2.put("roleId", getEPRole2.getId());
2330 List<BulkUploadRoleFunction> appRoleFunc2 = new ArrayList<>();
2331 appRoleFunc2.add(bulkUploadRoleFunction);
2332 appRoleFunc2.add(bulkUploadRoleFunction2);
2333 Mockito.when(dataAccessService.executeNamedQuery("uploadPartnerRoleFunctions", params2, null))
2334 .thenReturn(appRoleFunc2);
2335 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
2336 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
2337 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2338 // GlobalRoleFunctionsTest
2339 final Map<String, Long> partnerAppParams = new HashMap<>();
2340 partnerAppParams.put("appId", app.getId());
2341 Mockito.when(epAppCommonServiceImpl.getApp(1l)).thenReturn(app);
2342 List<GlobalRoleWithApplicationRoleFunction> globalRoleFuncsList = new ArrayList<>();
2343 GlobalRoleWithApplicationRoleFunction globalRoleFunc = new GlobalRoleWithApplicationRoleFunction();
2344 globalRoleFunc.setActive(true);
2345 globalRoleFunc.setAppId(10l);
2346 globalRoleFunc.setFunctionCd("test|test|test");
2347 globalRoleFunc.setRoleId(2l);
2348 globalRoleFunc.setFunctionName("test");
2349 globalRoleFunc.setRoleName("global_test");
2350 globalRoleFuncsList.add(globalRoleFunc);
2351 Mockito.when(dataAccessService.executeNamedQuery("getBulkUploadPartnerGlobalRoleFunctions", partnerAppParams, null))
2352 .thenReturn(globalRoleFuncsList);
2353 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2354 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2355 Integer actual = externalAccessRolesServiceImpl.bulkUploadPartnerRoleFunctions(app.getUebKey());
2356 Integer expected = 5;
2357 assertEquals(expected, actual);
2361 public void getMenuFunctionsListTest() throws Exception {
2362 EPApp app = mockApp();
2363 List<EPApp> appList = new ArrayList<>();
2364 final Map<String, String> appUebkeyParams = new HashMap<>();
2366 appUebkeyParams.put("appKey", app.getUebKey());
2367 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2368 .thenReturn(appList);
2369 final Map<String, Long> appParams = new HashMap<>();
2370 appParams.put(APP_ID, app.getId());
2371 List<String> expected = new ArrayList<>();
2372 expected.add("test_menu1");
2373 expected.add("test_menu2");
2374 Mockito.when(dataAccessService.executeNamedQuery("getMenuFunctions", appParams, null)).thenReturn(expected);
2375 List<String> actual = externalAccessRolesServiceImpl.getMenuFunctionsList(app.getUebKey());
2376 assertEquals(expected, actual);
2380 public void getCentralizedAppsOfUserTest() {
2381 EPUser user = mockUser.mockEPUser();
2382 Map<String, String> params = new HashMap<>();
2383 params.put("userId", user.getOrgUserId());
2384 List<CentralizedApp> expected = new ArrayList<>();
2385 CentralizedApp centralizedApp = new CentralizedApp();
2386 centralizedApp.setAppId(2);
2387 centralizedApp.setAppName("testapp1");
2388 expected.add(centralizedApp);
2389 Mockito.when(dataAccessService.executeNamedQuery("getCentralizedAppsOfUser", params, null))
2390 .thenReturn(expected);
2391 List<CentralizedApp> actual = externalAccessRolesServiceImpl.getCentralizedAppsOfUser(user.getOrgUserId());
2392 assertEquals(expected, actual);
2396 public void ConvertCentralRoleToRoleTest() throws Exception {
2397 ObjectMapper mapper = new ObjectMapper();
2398 Role role = new Role();
2399 role.setName("Test");
2401 role.setActive(true);
2402 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
2403 RoleFunction roleFunc = new RoleFunction();
2404 roleFunc.setName("Test Name");
2405 roleFunc.setCode("testcode");
2406 RoleFunction roleFunc2 = new RoleFunction();
2407 roleFunc2.setName("Test Name3");
2408 roleFunc2.setCode("menu_testcode2");
2409 roleFuncSet.add(roleFunc);
2410 roleFuncSet.add(roleFunc2);
2411 role.setRoleFunctions(roleFuncSet);
2412 String roleInfo = mapper.writeValueAsString(role);
2413 Role actual = externalAccessRolesServiceImpl.ConvertCentralRoleToRole(roleInfo);
2414 assertNotNull(actual);
2418 public void convertV2CentralRoleListToOldVerisonCentralRoleListTest() {
2419 List<CentralV2Role> v2CenRoleList = new ArrayList<>();
2420 CentralV2Role cenV2Role = new CentralV2Role(2l, "test1");
2421 CentralV2RoleFunction CentralV2Role = new CentralV2RoleFunction("testcode", "test_name");
2422 SortedSet<CentralV2RoleFunction> setV2RoleFuncs = new TreeSet<>();
2423 setV2RoleFuncs.add(CentralV2Role);
2424 cenV2Role.setRoleFunctions(setV2RoleFuncs);
2425 v2CenRoleList.add(cenV2Role);
2426 List<CentralRole> actual = externalAccessRolesServiceImpl.convertV2CentralRoleListToOldVerisonCentralRoleList(v2CenRoleList);
2427 assertEquals(1, actual.size());
2431 public void bulkUploadRoleFuncTest() throws Exception {
2432 PowerMockito.mockStatic(EcompPortalUtils.class);
2433 EPApp app = mockApp();
2434 UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
2435 data.setRoleName("test");
2436 data.setType("test");
2437 data.setInstance("test");
2438 data.setIsGlobalRolePartnerFunc(false);
2439 data.setAction("test");
2440 data.setName("test");
2441 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
2442 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2443 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2444 externalAccessRolesServiceImpl.bulkUploadRoleFunc(data, app);
2448 public void bulkUploadGlobalRoleFuncTest() throws Exception {
2449 PowerMockito.mockStatic(EcompPortalUtils.class);
2450 EPApp app = mockApp();
2451 EPApp portalApp = mockApp();
2452 portalApp.setId(1L);
2453 Mockito.when(epAppCommonServiceImpl.getApp(PortalConstants.PORTAL_APP_ID)).thenReturn(portalApp);
2454 UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
2455 data.setRoleName("test");
2456 data.setType("test");
2457 data.setInstance("test");
2458 data.setIsGlobalRolePartnerFunc(true);
2459 data.setAction("test");
2460 data.setName("test");
2461 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
2462 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2463 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2464 externalAccessRolesServiceImpl.bulkUploadRoleFunc(data, app);
2467 @Test(expected = HttpClientErrorException.class)
2468 public void bulkUploadRoleFuncExcpetionTest() throws Exception {
2469 PowerMockito.mockStatic(EcompPortalUtils.class);
2470 UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
2471 data.setRoleName("test");
2472 data.setType("test");
2473 data.setInstance("test");
2474 data.setAction("test");
2475 data.setName("test");
2476 data.setInstance("test");
2477 EPApp app = mockApp();
2478 Mockito.doThrow(new HttpClientErrorException(HttpStatus.CONFLICT)).when(template).exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2479 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class));
2480 externalAccessRolesServiceImpl.bulkUploadRoleFunc(data, app);
2484 public void syncApplicationUserRolesFromExtAuthSystemTest() throws Exception {
2485 PowerMockito.mockStatic(EcompPortalUtils.class);
2486 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2487 PowerMockito.mockStatic(PortalConstants.class);
2488 PowerMockito.mockStatic(SystemProperties.class);
2489 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(new HttpHeaders());
2490 Mockito.when(EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN)).thenReturn(true);
2491 JSONObject mockJsonObjectRole = new JSONObject();
2492 JSONObject mockJsonObjectRole2 = new JSONObject();
2493 JSONObject mockJsonObjectRole3 = new JSONObject();
2494 mockJsonObjectRole.put("name", "com.test.app.test_role");
2495 mockJsonObjectRole2.put("name", "com.test.app2.test_role");
2496 mockJsonObjectRole3.put("name", "com.test.app2.Account_Administrator");
2497 List<JSONObject> userRolesList = new ArrayList<>();
2498 JSONObject mockJsonObjectFinalUserRole = new JSONObject();
2499 userRolesList.add(mockJsonObjectRole);
2500 userRolesList.add(mockJsonObjectRole2);
2501 userRolesList.add(mockJsonObjectRole3);
2502 mockJsonObjectFinalUserRole.put("role", userRolesList);
2503 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(),HttpStatus.OK);
2504 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
2505 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2506 List<EPUser> users = new ArrayList<>();
2507 EPUser user = mockUser.mockEPUser();
2508 user.setOrgUserId("test");
2510 List<EPApp> apps = new ArrayList<>();
2511 EPApp app = mockApp();
2512 app.setNameSpace("com.test.app");
2514 EPApp app2 = mockApp();
2515 app2.setNameSpace("com.test.app2");
2519 Mockito.when(dataAccessService
2520 .executeNamedQuery("getCentralizedApps", null, null)).thenReturn(apps);
2521 HashMap<String, String> userParams = new HashMap<>();
2522 userParams.put("org_user_id", "test");
2523 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null)).thenReturn(users);
2524 List<CentralizedAppRoles> currentUserAppRoles = new ArrayList<>();
2525 CentralizedAppRoles currentUserAppRole = new CentralizedAppRoles();
2526 currentUserAppRole.setAppId(1l);
2527 currentUserAppRole.setAppNameSpace("com.test.app");
2528 currentUserAppRole.setRoleId(2l);
2529 currentUserAppRole.setRoleName("test role");
2530 currentUserAppRoles.add(currentUserAppRole);
2531 HashMap<String, String> userParams2 = new HashMap<>();
2532 userParams2.put("orgUserId", user.getOrgUserId());
2533 Mockito.when(dataAccessService
2534 .executeNamedQuery("getUserCentralizedAppRoles", userParams2, null)).thenReturn(currentUserAppRoles);
2535 List<CentralizedAppRoles> centralizedAppRoles = new ArrayList<>();
2536 CentralizedAppRoles centralizedAppRole = new CentralizedAppRoles();
2537 centralizedAppRole.setAppId(1l);
2538 centralizedAppRole.setAppNameSpace("com.test.app");
2539 centralizedAppRole.setRoleId(2l);
2540 centralizedAppRole.setRoleName("test role");
2541 CentralizedAppRoles centralizedAppRole2 = new CentralizedAppRoles();
2542 centralizedAppRole2.setAppId(1l);
2543 centralizedAppRole2.setAppNameSpace("com.test.app2");
2544 centralizedAppRole2.setRoleId(2l);
2545 centralizedAppRole2.setRoleName("test role");
2546 centralizedAppRoles.add(centralizedAppRole);
2547 centralizedAppRoles.add(centralizedAppRole2);
2548 Mockito.when(dataAccessService
2549 .executeNamedQuery("getAllCentralizedAppsRoles", null, null)).thenReturn(centralizedAppRoles);
2550 externalAccessRolesServiceImpl.syncApplicationUserRolesFromExtAuthSystem(user.getOrgUserId());