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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
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.exceptions.InactiveApplicationException;
82 import org.onap.portalapp.portal.exceptions.InvalidUserException;
83 import org.onap.portalapp.portal.framework.MockitoTestSuite;
84 import org.onap.portalapp.portal.transport.BulkUploadRoleFunction;
85 import org.onap.portalapp.portal.transport.BulkUploadUserRoles;
86 import org.onap.portalapp.portal.transport.CentralRole;
87 import org.onap.portalapp.portal.transport.CentralUser;
88 import org.onap.portalapp.portal.transport.CentralV2Role;
89 import org.onap.portalapp.portal.transport.EcompUserRoles;
90 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
91 import org.onap.portalapp.portal.transport.GlobalRoleWithApplicationRoleFunction;
92 import org.onap.portalapp.portal.transport.LocalRole;
93 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
94 import org.onap.portalapp.portal.utils.EcompPortalUtils;
95 import org.onap.portalapp.portal.utils.PortalConstants;
96 import org.onap.portalapp.util.EPUserUtils;
97 import org.onap.portalsdk.core.domain.Role;
98 import org.onap.portalsdk.core.domain.RoleFunction;
99 import org.onap.portalsdk.core.restful.domain.EcompUser;
100 import org.onap.portalsdk.core.service.DataAccessService;
101 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
102 import org.onap.portalsdk.core.util.SystemProperties;
103 import org.powermock.api.mockito.PowerMockito;
104 import org.powermock.core.classloader.annotations.PrepareForTest;
105 import org.powermock.modules.junit4.PowerMockRunner;
106 import org.springframework.http.HttpEntity;
107 import org.springframework.http.HttpHeaders;
108 import org.springframework.http.HttpMethod;
109 import org.springframework.http.HttpStatus;
110 import org.springframework.http.ResponseEntity;
111 import org.springframework.web.client.HttpClientErrorException;
112 import org.springframework.web.client.RestTemplate;
114 import com.fasterxml.jackson.databind.ObjectMapper;
116 @RunWith(PowerMockRunner.class)
117 @PrepareForTest({ EcompPortalUtils.class, Criterion.class, Restrictions.class, SystemProperties.class,
118 EPCommonSystemProperties.class })
119 public class ExternalAccessRolesServiceImplTest {
121 DataAccessService dataAccessService = new DataAccessServiceImpl();
124 RestTemplate template = new RestTemplate();
127 ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl();
130 EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
133 SessionFactory sessionFactory;
139 Transaction transaction;
142 public void setup() {
143 MockitoAnnotations.initMocks(this);
144 Mockito.when(sessionFactory.openSession()).thenReturn(session);
145 Mockito.when(session.beginTransaction()).thenReturn(transaction);
149 public void after() {
153 private static final String APP_ROLE_NAME_PARAM = "appRoleName";
155 private static final String GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM = "getRoletoUpdateInExternalAuthSystem";
157 private static final String GET_PORTAL_APP_ROLES_QUERY = "getPortalAppRoles";
159 private static final String GET_ROLE_FUNCTION_QUERY = "getRoleFunction";
161 private static final String FUNCTION_CODE_PARAMS = "functionCode";
163 private static final String FUNCTION_PIPE = "|";
165 private static final String APP_ID = "appId";
167 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
169 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
170 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
171 NullPointerException nullPointerException = new NullPointerException();
172 MockEPUser mockUser = new MockEPUser();
173 String uebKey = "test-ueb-key";
175 public EPApp mockApp() {
176 EPApp app = new EPApp();
178 app.setImageUrl("test");
179 app.setNameSpace("com.test.app");
180 app.setCentralAuth(true);
181 app.setDescription("test");
182 app.setNotes("test");
184 app.setId((long) 10);
185 app.setAppRestEndpoint("test");
186 app.setAlternateUrl("test");
188 app.setMlAppName("test");
189 app.setMlAppAdminId("test");
190 app.setUsername("test");
191 app.setAppPassword("test");
193 app.setEnabled(true);
194 app.setUebKey("test");
195 app.setUebSecret("test");
196 app.setUebTopicName("test");
201 @SuppressWarnings("deprecation")
203 public void getAppRolesIfAppIsPortalTest() throws Exception {
204 List<EPRole> applicationRoles = new ArrayList<>();
205 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
206 List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 1);
207 assertEquals(expectedApplicationRoles, applicationRoles);
210 @SuppressWarnings("deprecation")
212 public void getAppRolesTest() throws Exception {
213 List<EPRole> applicationRoles = new ArrayList<>();
214 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
215 List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 10);
216 assertEquals(expectedApplicationRoles, applicationRoles);
219 @SuppressWarnings("deprecation")
221 public void getAppExceptionTest() throws Exception {
222 List<EPApp> app = new ArrayList<>();
223 Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
225 List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey);
226 assertEquals(app, expectedapp);
229 @Test(expected = InactiveApplicationException.class)
230 public void getAppErrorTest() throws Exception {
231 List<EPApp> appList = new ArrayList<>();
232 EPApp app = mockApp();
233 app.setEnabled(false);
235 final Map<String, String> appUebkeyParams = new HashMap<>();
236 appUebkeyParams.put("appKey", "test-ueb-key");
237 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
238 .thenReturn(appList);
239 externalAccessRolesServiceImpl.getApp(uebKey);
243 public void getAppTest() throws Exception {
244 List<EPApp> appList = new ArrayList<>();
245 EPApp app = mockApp();
248 final Map<String, String> appUebkeyParams = new HashMap<>();
249 appUebkeyParams.put("appKey", "test-ueb-key");
250 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
251 .thenReturn(appList);
252 List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey);
253 assertEquals(appList, expectedapp);
257 public void addRoleTest() throws Exception {
258 HttpHeaders headers = new HttpHeaders();
259 PowerMockito.mockStatic(EcompPortalUtils.class);
260 PowerMockito.mockStatic(SystemProperties.class);
261 PowerMockito.mockStatic(EPCommonSystemProperties.class);
262 String uebKey = "test-ueb-key";
263 Role role = new Role();
264 role.setId((long) 25);
265 EPApp app = mockApp();
266 app.setEnabled(true);
267 app.setId((long) 10);
268 app.setNameSpace("test_namesapce");
269 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
270 List<EPApp> appList = new ArrayList<>();
272 List<EPRole> roleList = new ArrayList<>();
273 EPRole ePRole = new EPRole();
274 role.setName("Test Role");
275 roleList.add(ePRole);
276 final Map<String, String> appUebkeyParams = new HashMap<>();
277 appUebkeyParams.put("appKey", "test-ueb-key");
278 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
279 .thenReturn(appList);
280 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
281 getPartnerAppRoleParams.put("appRoleId", role.getId());
282 getPartnerAppRoleParams.put("appId", app.getId());
283 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
284 .thenReturn(roleList);
285 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL))
286 .thenReturn("Testurl");
287 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
288 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
289 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
291 assertTrue(externalAccessRolesServiceImpl.addRole(role, uebKey));
295 public void addRoleMethodNotAllowedTest() throws Exception {
296 HttpHeaders headers = new HttpHeaders();
297 PowerMockito.mockStatic(EcompPortalUtils.class);
298 PowerMockito.mockStatic(SystemProperties.class);
299 PowerMockito.mockStatic(EPCommonSystemProperties.class);
300 Role role = new Role();
301 role.setId((long) 25);
302 EPApp app = mockApp();
303 app.setEnabled(true);
304 app.setId((long) 10);
305 app.setNameSpace("test_namesapce");
306 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
307 List<EPApp> appList = new ArrayList<>();
309 List<EPRole> roleList = new ArrayList<>();
310 EPRole ePRole = new EPRole();
311 role.setName("Test Role");
312 roleList.add(ePRole);
313 final Map<String, String> appUebkeyParams = new HashMap<>();
314 appUebkeyParams.put("appKey", "test-ueb-key");
315 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
316 .thenReturn(appList);
317 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
318 getPartnerAppRoleParams.put("appRoleId", role.getId());
319 getPartnerAppRoleParams.put("appId", app.getId());
320 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
321 .thenReturn(roleList);
322 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL))
323 .thenReturn("Testurl");
324 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
325 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
326 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
327 assertFalse(externalAccessRolesServiceImpl.addRole(role, uebKey));
330 public EPApp getApp() {
331 EPApp app = new EPApp();
333 app.setImageUrl("test");
334 app.setDescription("test");
335 app.setNotes("test");
338 app.setAppRestEndpoint("test");
339 app.setAlternateUrl("test");
341 app.setMlAppName("test");
342 app.setMlAppAdminId("test");
343 app.setUsername("test");
344 app.setAppPassword("test");
346 app.setEnabled(false);
347 app.setUebKey("test");
348 app.setUebSecret("test");
349 app.setUebTopicName("test");
355 public void deleteCentralRoleFunctionTest() throws Exception {
356 PowerMockito.mockStatic(EcompPortalUtils.class);
357 PowerMockito.mockStatic(SystemProperties.class);
358 PowerMockito.mockStatic(EPCommonSystemProperties.class);
359 final Map<String, String> params = new HashMap<>();
360 EPApp app = mockApp();
361 params.put("functionCode", "menu_fun_code");
362 params.put("appId", String.valueOf(10));
363 List<CentralV2RoleFunction> centralRoleFunctionList = new ArrayList<>();
364 CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
365 domainCentralRoleFunction.setCode("menu_fun_code");
366 centralRoleFunctionList.add(domainCentralRoleFunction);
367 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null))
368 .thenReturn(centralRoleFunctionList);
369 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
370 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.OK);
371 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
372 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
373 HttpHeaders headers = new HttpHeaders();
374 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
375 Mockito.doNothing().when(dataAccessService).deleteDomainObjects(EPAppRoleFunction.class,
376 "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null);
377 assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app));
381 public void deleteRoleForApplicationTest() throws Exception {
382 EPApp app = mockApp();
384 List<EPApp> appList = new ArrayList<>();
386 final Map<String, String> appUebkeyParams = new HashMap<>();
387 appUebkeyParams.put("appKey", app.getUebKey());
388 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
389 .thenReturn(appList);
390 final Map<String, String> deleteRoleParams = new HashMap<>();
391 deleteRoleParams.put(APP_ROLE_NAME_PARAM, "test_delete");
392 deleteRoleParams.put(APP_ID, String.valueOf(app.getId()));
393 List<EPRole> epRoleList = new ArrayList<>();
394 EPRole epRole = new EPRole();
395 epRole.setName("test_delete");
397 epRole.setActive(true);
398 epRole.setAppRoleId(11l);
399 epRoleList.add(epRole);
401 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, deleteRoleParams, null))
402 .thenReturn(epRoleList);
403 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
404 appRoleFuncsParams.put("appId", app.getId());
405 appRoleFuncsParams.put("roleId", epRole.getId());
406 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
407 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
408 epAppRoleFunction.setCode("test_code");
409 epAppRoleFunction.setAppId(app.getId());
410 epAppRoleFunction.setRoleAppId(null);
411 appRoleFunctionList.add(epAppRoleFunction);
413 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
414 .thenReturn(appRoleFunctionList);
415 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
416 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
417 PowerMockito.mockStatic(EcompPortalUtils.class);
418 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
419 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
420 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
421 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
422 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
423 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
424 assertTrue(externalAccessRolesServiceImpl.deleteRoleForApplication(epRole.getName(), app.getUebKey()));
428 public void deleteRoleForPortalApplicationTest() throws Exception {
429 EPApp app = mockApp();
431 List<EPApp> appList = new ArrayList<>();
433 final Map<String, String> appUebkeyParams = new HashMap<>();
434 appUebkeyParams.put("appKey", app.getUebKey());
435 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
436 .thenReturn(appList);
437 final Map<String, String> deleteRoleParams2 = new HashMap<>();
438 deleteRoleParams2.put(APP_ROLE_NAME_PARAM, "test_delete");
439 List<EPRole> epRoleList2 = new ArrayList<>();
440 EPRole epRole = new EPRole();
441 epRole.setName("test_delete");
443 epRole.setActive(true);
444 epRoleList2.add(epRole);
445 Mockito.when(dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, deleteRoleParams2, null))
446 .thenReturn(epRoleList2);
447 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
448 appRoleFuncsParams.put("appId", app.getId());
449 appRoleFuncsParams.put("roleId", epRole.getId());
450 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
451 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
452 epAppRoleFunction.setCode("test_code");
453 epAppRoleFunction.setAppId(app.getId());
454 epAppRoleFunction.setRoleAppId(null);
455 appRoleFunctionList.add(epAppRoleFunction);
457 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
458 .thenReturn(appRoleFunctionList);
459 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
460 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
461 PowerMockito.mockStatic(EcompPortalUtils.class);
462 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
463 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
464 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
465 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
466 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
467 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
468 assertTrue(externalAccessRolesServiceImpl.deleteRoleForApplication(epRole.getName(), app.getUebKey()));
472 public void deleteCentralRoleFunctionFailTest() throws Exception {
473 final Map<String, String> params = new HashMap<>();
474 EPApp app = mockApp();
475 params.put("functionCode", "menu_fun_code");
476 params.put("appId", String.valueOf(10));
477 List<CentralV2RoleFunction> centralRoleFunctionList = new ArrayList<>();
478 CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
479 domainCentralRoleFunction.setCode("menu_fun_code");
480 centralRoleFunctionList.add(domainCentralRoleFunction);
481 HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.NOT_FOUND);
482 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null))
483 .thenReturn(centralRoleFunctionList);
484 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
485 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(httpClientErrorException);
486 HttpHeaders headers = new HttpHeaders();
487 PowerMockito.mockStatic(EcompPortalUtils.class);
488 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
489 Mockito.doNothing().when(dataAccessService).deleteDomainObjects(EPAppRoleFunction.class,
490 "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null);
492 boolean returnedValue = externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app);
493 assertTrue(returnedValue);
497 public void deleteCentralRoleFunctionExceptionTest() {
498 final Map<String, String> params = new HashMap<>();
499 EPApp app = mockApp();
500 params.put("functionCd", "menu_fun_code");
501 params.put("appId", String.valueOf(10));
502 List<CentralV2RoleFunction> centralRoleFunctionList = new ArrayList<>();
503 CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
504 domainCentralRoleFunction.setCode("menu_fun_code");
505 centralRoleFunctionList.add(domainCentralRoleFunction);
506 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionDetails", params, null))
507 .thenThrow(nullPointerException);
508 assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app));
512 public void getRoleFunctionTest() throws Exception {
513 PowerMockito.mockStatic(EcompPortalUtils.class);
514 PowerMockito.mockStatic(EPCommonSystemProperties.class);
515 PowerMockito.mockStatic(SystemProperties.class);
516 EPApp app = mockApp();
517 List<EPApp> appList = new ArrayList<>();
519 final Map<String, String> appUebkeyParams = new HashMap<>();
520 appUebkeyParams.put("appKey", app.getUebKey());
521 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
522 .thenReturn(appList);
523 Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code");
524 Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
525 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
526 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
527 CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
528 getRoleFuncList.add(getCenRole);
529 final Map<String, String> params = new HashMap<>();
530 params.put(FUNCTION_CODE_PARAMS, "test_type|type_code|*");
531 params.put(APP_ID, String.valueOf(app.getId()));
532 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null))
533 .thenReturn(getRoleFuncList);
534 CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
536 assertEquals(getCenRole.getCode(), actual.getCode());
540 public void getRoleFunctionMutilpleFilterTest() throws Exception {
541 PowerMockito.mockStatic(EcompPortalUtils.class);
542 PowerMockito.mockStatic(EPCommonSystemProperties.class);
543 PowerMockito.mockStatic(SystemProperties.class);
544 EPApp app = mockApp();
545 List<EPApp> appList = new ArrayList<>();
547 final Map<String, String> appUebkeyParams = new HashMap<>();
548 appUebkeyParams.put("appKey", app.getUebKey());
549 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
550 .thenReturn(appList);
551 CentralV2RoleFunction expected = new CentralV2RoleFunction(null, "type_code", "test_name", null, "test_type",
553 Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code");
554 Mockito.when(EcompPortalUtils.getFunctionCode("test_type_1|type_code_1|*")).thenReturn("type_code_1");
555 Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
556 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
557 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
558 CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
559 CentralV2RoleFunction getCenRole2 = new CentralV2RoleFunction("test_type_1|type_code_1|*", "test_name_1");
560 getRoleFuncList.add(getCenRole);
561 getRoleFuncList.add(getCenRole2);
562 final Map<String, String> params = new HashMap<>();
563 params.put(FUNCTION_CODE_PARAMS, "test_type|type_code|*");
564 params.put(APP_ID, String.valueOf(app.getId()));
565 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null))
566 .thenReturn(getRoleFuncList);
567 CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
569 assertEquals(expected.getCode(), actual.getCode());
573 public void getUserTest() throws InvalidUserException {
574 List<EPUser> userList = new ArrayList<>();
575 EPUser user = mockUser.mockEPUser();
577 final Map<String, String> userParams = new HashMap<>();
578 userParams.put("org_user_id", "guestT");
579 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
580 .thenReturn(userList);
581 List<EPUser> expectedUserList = externalAccessRolesServiceImpl.getUser("guestT");
582 assertEquals(expectedUserList, userList);
586 public void getV2UserWithRolesTest() throws Exception {
587 EPApp app = mockApp();
589 EPUser user = mockUser.mockEPUser();
590 List<EPApp> appList = new ArrayList<>();
592 final Map<String, String> appUebkeyParams = new HashMap<>();
593 appUebkeyParams.put("appKey", app.getUebKey());
594 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
595 .thenReturn(appList);
596 final Map<String, String> userParams = new HashMap<>();
597 userParams.put("org_user_id", user.getOrgUserId());
598 List<EPUser> userList = new ArrayList<>();
599 Set<EPUserApp> userAppSet = user.getEPUserApps();
600 EPUserApp epUserApp = new EPUserApp();
601 EPRole epRole = new EPRole();
602 epRole.setName("test");
604 epRole.setActive(true);
605 epRole.setAppRoleId(11l);
606 epUserApp.setApp(app);
607 epUserApp.setUserId(user.getId());
608 epUserApp.setRole(epRole);
609 userAppSet.add(epUserApp);
610 user.setUserApps(userAppSet);
612 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
613 .thenReturn(userList);
614 final Map<String, Long> params = new HashMap<>();
615 List<CentralV2RoleFunction> appRoleFunctionList = new ArrayList<>();
616 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
617 centralV2RoleFunction.setCode("test_type|test_code|*");
618 centralV2RoleFunction.setName("test name");
619 centralV2RoleFunction.setAppId(app.getId());
620 appRoleFunctionList.add(centralV2RoleFunction);
621 params.put("roleId", epUserApp.getRole().getId());
622 params.put(APP_ID, epUserApp.getApp().getId());
623 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
624 .thenReturn(appRoleFunctionList);
625 String actual = externalAccessRolesServiceImpl.getV2UserWithRoles(user.getOrgUserId(), app.getUebKey());
626 String notExpected = "";
627 assertNotEquals(actual, notExpected);
631 public void saveCentralRoleFunctionNewTestForV2() throws Exception {
632 PowerMockito.mockStatic(EcompPortalUtils.class);
633 EPApp app = mockApp();
635 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
636 centralV2RoleFunction.setCode("test_code");
637 centralV2RoleFunction.setName("test name");
638 centralV2RoleFunction.setAppId(app.getId());
639 centralV2RoleFunction.setAction("*");
640 centralV2RoleFunction.setType("test_type");
641 final Map<String, String> params = new HashMap<>();
642 params.put("appId", String.valueOf(1));
644 List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
645 appRoleFunc.add(centralV2RoleFunction);
646 params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
647 + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
648 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
649 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
650 HttpHeaders headers = new HttpHeaders();
651 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
652 JSONObject mockJsonObjectPerm = new JSONObject();
653 JSONObject mockJsonObjectFinalPerm = new JSONObject();
654 mockJsonObjectPerm.put("type", "com.test.app.test_type");
655 mockJsonObjectPerm.put("instance", "com.test.app.test_code");
656 mockJsonObjectPerm.put("action", "*");
657 mockJsonObjectPerm.put("description", "test name");
658 List<JSONObject> mockJson = new ArrayList<>();
659 mockJson.add(mockJsonObjectPerm);
660 mockJsonObjectFinalPerm.put("perm", mockJson);
661 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
662 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
663 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
664 ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
665 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
666 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
667 Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
668 assertEquals(true, actual);
672 public void saveCentralRoleFunctionUpdateForV2Test() throws Exception {
673 PowerMockito.mockStatic(EcompPortalUtils.class);
674 EPApp app = mockApp();
676 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
677 centralV2RoleFunction.setCode("test_code");
678 centralV2RoleFunction.setName("test name2");
679 centralV2RoleFunction.setAppId(app.getId());
680 centralV2RoleFunction.setAction("*");
681 centralV2RoleFunction.setType("test_type");
682 CentralV2RoleFunction centralV2RoleFunctionExisting = new CentralV2RoleFunction();
683 centralV2RoleFunctionExisting.setCode("test_code");
684 centralV2RoleFunctionExisting.setName("test name");
685 centralV2RoleFunctionExisting.setAppId(app.getId());
686 centralV2RoleFunctionExisting.setAction("*");
687 centralV2RoleFunctionExisting.setType("test_type");
688 final Map<String, String> params = new HashMap<>();
689 params.put("appId", String.valueOf(1));
690 List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
691 appRoleFunc.add(centralV2RoleFunctionExisting);
692 params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
693 + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
694 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
695 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
696 HttpHeaders headers = new HttpHeaders();
697 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
698 JSONObject mockJsonObjectPerm = new JSONObject();
699 JSONObject mockJsonObjectFinalPerm = new JSONObject();
700 mockJsonObjectPerm.put("type", "com.test.app.test_type");
701 mockJsonObjectPerm.put("instance", "test_code");
702 mockJsonObjectPerm.put("action", "*");
703 mockJsonObjectPerm.put("description", "test name");
704 List<JSONObject> mockJson = new ArrayList<>();
705 mockJson.add(mockJsonObjectPerm);
706 mockJsonObjectFinalPerm.put("perm", mockJson);
707 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
708 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
709 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
710 ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
711 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
712 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
713 Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
714 assertEquals(true, actual);
717 @SuppressWarnings("deprecation")
719 public void getAllAppUsersTest() throws Exception {
720 EPApp app = new EPApp();
721 app.setEnabled(true);
722 app.setId((long) 10);
723 List<EPApp> appList = new ArrayList<>();
724 final Map<String, String> appUebkeyParams = new HashMap<>();
726 appUebkeyParams.put("appKey", app.getUebKey());
727 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
728 .thenReturn(appList);
729 List<EPRole> applicationRoles = new ArrayList<>();
730 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
731 Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
732 .thenReturn(appList);
733 final Map<String, Long> appParams = new HashMap<>();
734 appParams.put("appId", app.getId());
735 List<EcompUserRoles> userList = new ArrayList<>();
736 EcompUserRoles ecompUserRoles = new EcompUserRoles();
737 ecompUserRoles.setOrgUserId("guestT");
738 ecompUserRoles.setRoleId((long) 1);
739 ecompUserRoles.setRoleName("test");
740 EcompUserRoles ecompUserRoles2 = new EcompUserRoles();
741 ecompUserRoles2.setOrgUserId("guestT");
742 ecompUserRoles2.setRoleId((long) 2);
743 ecompUserRoles2.setRoleName("test new");
744 userList.add(ecompUserRoles);
745 userList.add(ecompUserRoles2);
746 Mockito.when(dataAccessService.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
747 List<EcompUser> usersfinalList = externalAccessRolesServiceImpl.getAllAppUsers(app.getUebKey());
748 assertEquals(usersfinalList.get(0).getRoles().size(), 2);
752 public void getGlobalRolesOfPortalTest() {
753 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(null);
754 assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), null);
758 public void getGlobalRolesOfPortalExceptionTest() {
759 List<EPRole> globalRoles = new ArrayList<>();
760 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null))
761 .thenThrow(nullPointerException);
762 assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), globalRoles);
766 public void getRolesForAppTest() throws Exception {
767 EPApp app = mockApp();
769 List<EPApp> appList = new ArrayList<>();
770 final Map<String, String> appUebkeyParams = new HashMap<>();
772 appUebkeyParams.put("appKey", app.getUebKey());
773 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
774 .thenReturn(appList);
775 List<EPRole> applicationRoles = new ArrayList<>();
776 EPRole appRole = new EPRole();
777 appRole.setActive(true);
778 appRole.setAppId(app.getId());
779 appRole.setAppRoleId(100l);
781 appRole.setName("test");
782 applicationRoles.add(appRole);
783 final Map<String, Long> appParams = new HashMap<>();
784 appParams.put("appId", app.getId());
785 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
786 .thenReturn(applicationRoles);
787 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
788 CentralV2RoleFunction v2RoleFunction = new CentralV2RoleFunction();
789 v2RoleFunction.setAppId(app.getId());
790 v2RoleFunction.setCode("test_type|test_code|*");
791 v2RoleFunction.setName("test name");
792 cenRoleFuncList.add(v2RoleFunction);
793 final Map<String, Long> params = new HashMap<>();
794 params.put("roleId", appRole.getId());
795 params.put(APP_ID, appList.get(0).getId());
796 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
797 .thenReturn(cenRoleFuncList);
798 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
799 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
800 mockGlobalRole.setActive(true);
801 mockGlobalRole.setAppId(app.getId());
802 mockGlobalRole.setRoleId(1111l);
803 mockGlobalRole.setRoleName("global_test");
804 mockGlobalRole.setFunctionCd("test_type|test_code|*");
805 mockGlobalRole.setFunctionName("test name");
806 mockGlobalRoles.add(mockGlobalRole);
807 Map<String, Long> params2 = new HashMap<>();
808 params2.put("appId", app.getId());
809 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params2, null))
810 .thenReturn(mockGlobalRoles);
811 List<EPRole> globalRoles = new ArrayList<>();
812 EPRole globalRole = new EPRole();
813 globalRole.setName("global_test");
814 globalRole.setId(1111l);
815 globalRole.setActive(true);
816 globalRoles.add(globalRole);
817 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
818 List<CentralV2Role> expected = new ArrayList<>();
819 CentralV2Role cenV2Role = new CentralV2Role();
820 CentralV2Role cenV2Role2 = new CentralV2Role();
821 expected.add(cenV2Role);
822 expected.add(cenV2Role2);
823 List<CentralV2Role> actual = externalAccessRolesServiceImpl.getRolesForApp(app.getUebKey());
824 assertEquals(expected.size(), actual.size());
828 public void getRoleFuncListTest() throws Exception {
829 EPApp app = mockApp();
830 List<EPApp> appList = new ArrayList<>();
831 final Map<String, String> appUebkeyParams = new HashMap<>();
833 appUebkeyParams.put("appKey", app.getUebKey());
834 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
835 .thenReturn(appList);
836 final Map<String, Long> params = new HashMap<>();
837 params.put(APP_ID, app.getId());
838 List<CentralV2RoleFunction> expected = new ArrayList<>();
839 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
840 expected.add(centralV2RoleFunction);
841 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(expected);
842 List<CentralV2RoleFunction> actual = externalAccessRolesServiceImpl.getRoleFuncList(app.getUebKey());
843 assertEquals(expected, actual);
847 public void getRoleInfoTest() throws Exception {
848 EPApp app = mockApp();
850 List<EPApp> appList = new ArrayList<>();
851 final Map<String, String> appUebkeyParams = new HashMap<>();
853 appUebkeyParams.put("appKey", app.getUebKey());
854 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
855 .thenReturn(appList);
856 List<EPRole> globalRoles = new ArrayList<>();
857 EPRole globalRole = new EPRole();
858 globalRole.setName("global_test");
859 globalRole.setId(2l);
860 globalRole.setActive(true);
861 globalRoles.add(globalRole);
862 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
863 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
864 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
865 mockGlobalRole.setActive(true);
866 mockGlobalRole.setAppId(app.getId());
867 mockGlobalRole.setRoleId(2l);
868 mockGlobalRole.setRoleName("global_test");
869 mockGlobalRole.setFunctionCd("test_type|test_code|*");
870 mockGlobalRole.setFunctionName("test name");
871 mockGlobalRoles.add(mockGlobalRole);
872 Map<String, Long> params = new HashMap<>();
873 params.put("roleId", 2l);
874 params.put("requestedAppId", 2l);
875 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", params, null))
876 .thenReturn(mockGlobalRoles);
877 CentralV2Role actual = externalAccessRolesServiceImpl.getRoleInfo(2l, app.getUebKey());
878 assertNotEquals(null, actual);
882 public void getPartnerRoleInfoTest() throws Exception {
883 EPApp app = mockApp();
885 List<EPApp> appList = new ArrayList<>();
886 final Map<String, String> appUebkeyParams = new HashMap<>();
888 appUebkeyParams.put("appKey", app.getUebKey());
889 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
890 .thenReturn(appList);
891 List<EPRole> applicationRoles = new ArrayList<>();
892 EPRole appRole = new EPRole();
893 appRole.setActive(true);
894 appRole.setAppId(app.getId());
895 appRole.setAppRoleId(100l);
897 appRole.setName("test");
898 applicationRoles.add(appRole);
899 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
900 getPartnerAppRoleParams.put("appRoleId", 10l);
901 getPartnerAppRoleParams.put("appId", app.getId());
902 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
903 .thenReturn(applicationRoles);
904 final Map<String, Long> params = new HashMap<>();
905 params.put("roleId", appRole.getId());
906 params.put(APP_ID, app.getId());
907 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
908 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
909 cenRoleFuncList.add(centralV2RoleFunction);
910 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
911 .thenReturn(cenRoleFuncList);
912 CentralV2Role actual = externalAccessRolesServiceImpl.getRoleInfo(10l, app.getUebKey());
913 assertNotEquals(null, actual);
917 public void saveRoleForPortalApplicationNewTest() throws Exception {
918 PowerMockito.mockStatic(EcompPortalUtils.class);
919 EPApp app = mockApp();
921 Role addRoleTest = new Role();
922 addRoleTest.setActive(true);
923 addRoleTest.setName("Test");
924 List<EPApp> appList = new ArrayList<>();
925 final Map<String, String> appUebkeyParams = new HashMap<>();
927 appUebkeyParams.put("appKey", app.getUebKey());
928 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
929 .thenReturn(appList);
930 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
931 HttpHeaders headers = new HttpHeaders();
932 JSONObject mockJsonObjectRole = new JSONObject();
933 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
934 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectRole.toString(), HttpStatus.OK);
935 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
936 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
937 final Map<String, String> epAppPortalRoleParams = new HashMap<>();
938 epAppPortalRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
939 List<EPRole> getRoleCreated = new ArrayList<>();
940 EPRole roleCreate = new EPRole();
941 roleCreate.setActive(true);
942 roleCreate.setId(10l);
943 roleCreate.setName("test");
944 getRoleCreated.add(roleCreate);
945 Mockito.when(dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, epAppPortalRoleParams, null))
946 .thenReturn(getRoleCreated);
947 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
948 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
949 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
950 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
951 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
953 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
954 assertEquals(expected, actual);
958 public void saveRoleForPortalApplicationUpdateTest() throws Exception {
959 PowerMockito.mockStatic(EPCommonSystemProperties.class);
960 PowerMockito.mockStatic(EcompPortalUtils.class);
961 PowerMockito.mockStatic(SystemProperties.class);
962 EPApp app = mockApp();
964 Role addRoleTest = new Role();
965 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
966 RoleFunction roleFunc = new RoleFunction();
967 roleFunc.setName("Test Name");
968 roleFunc.setCode("test_type|test_instance|*");
969 RoleFunction roleFunc2 = new RoleFunction();
970 roleFunc2.setName("Test Name3");
971 roleFunc2.setCode("test_type3|test_instance3|*");
972 roleFuncSet.add(roleFunc);
973 roleFuncSet.add(roleFunc2);
974 addRoleTest.setActive(true);
975 addRoleTest.setName("Test2");
976 addRoleTest.setId(2l);
977 addRoleTest.setRoleFunctions(roleFuncSet);
978 List<EPApp> appList = new ArrayList<>();
979 final Map<String, String> appUebkeyParams = new HashMap<>();
981 appUebkeyParams.put("appKey", app.getUebKey());
982 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
983 .thenReturn(appList);
984 List<EPRole> globalRoles = new ArrayList<>();
985 EPRole globalRole = new EPRole();
986 globalRole.setName("global_test");
987 globalRole.setId(1111l);
988 globalRole.setActive(true);
989 globalRoles.add(globalRole);
990 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
991 List<EPRole> epRoleList = new ArrayList<>();
992 EPRole getEPRole = new EPRole();
993 getEPRole.setName("Test");
995 getEPRole.setActive(true);
996 epRoleList.add(getEPRole);
997 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
998 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
999 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1000 .thenReturn(epRoleList);
1001 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1002 HttpHeaders headers = new HttpHeaders();
1003 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1004 JSONObject mockJsonObjectRole = new JSONObject();
1005 JSONObject mockJsonObjectFinalRole = new JSONObject();
1006 JSONObject mockJsonObjectPerm1 = new JSONObject();
1007 JSONObject mockJsonObjectPerm2 = new JSONObject();
1008 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1009 mockJsonObjectPerm1.put("instance", "test_instance");
1010 mockJsonObjectPerm1.put("action", "*");
1011 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1012 mockJsonObjectPerm2.put("instance", "test_instance2");
1013 mockJsonObjectPerm2.put("action", "*");
1014 List<JSONObject> permsList = new ArrayList<>();
1015 permsList.add(mockJsonObjectPerm1);
1016 permsList.add(mockJsonObjectPerm2);
1017 mockJsonObjectRole.put("name", "com.test.app.Test");
1018 mockJsonObjectRole.put("perms", permsList);
1019 mockJsonObjectRole.put("description",
1020 "{\"id\":\"2\",\"name\":\"Test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
1021 List<JSONObject> roleList = new ArrayList<>();
1022 roleList.add(mockJsonObjectRole);
1023 mockJsonObjectFinalRole.put("role", roleList);
1024 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1025 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1026 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1027 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1028 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1029 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1030 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1031 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1032 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1033 final Map<String, String> params = new HashMap<>();
1034 params.put("uebKey", app.getUebKey());
1035 params.put("roleId", String.valueOf(getEPRole.getId()));
1036 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1037 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1038 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1039 bulkUploadUserRoles.setOrgUserId("guestT");
1040 bulkUploadUserRoles.setRoleName("Test2");
1041 userRolesList.add(bulkUploadUserRoles);
1042 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1043 .thenReturn(userRolesList);
1045 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1047 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1048 .thenReturn("@test.com");
1049 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1050 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1051 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1052 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1053 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1054 appRoleFuncsParams.put("appId", app.getId());
1055 appRoleFuncsParams.put("roleId", getEPRole.getId());
1057 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1058 .thenReturn(appRoleFunctionList);
1059 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1060 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1061 final Map<String, String> getAppFunctionParams = new HashMap<>();
1062 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1063 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1064 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1065 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1066 v2RoleFunction.add(v2RoleFunction1);
1067 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1068 .thenReturn(v2RoleFunction);
1069 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1070 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1071 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1072 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1073 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1074 v2RoleFunction2.add(v2RoleFunction3);
1075 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1076 .thenReturn(v2RoleFunction2);
1077 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1079 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1080 assertEquals(expected, actual);
1084 public void saveRoleExitsInDbButNotInExtAuthSystemTest() throws Exception {
1085 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1086 PowerMockito.mockStatic(EcompPortalUtils.class);
1087 PowerMockito.mockStatic(SystemProperties.class);
1088 EPApp app = mockApp();
1090 Role addRoleTest = new Role();
1091 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1092 RoleFunction roleFunc = new RoleFunction();
1093 roleFunc.setName("Test Name");
1094 roleFunc.setCode("test_type|test_instance|*");
1095 RoleFunction roleFunc2 = new RoleFunction();
1096 roleFunc2.setName("Test Name3");
1097 roleFunc2.setCode("test_type3|test_instance3|*");
1098 roleFuncSet.add(roleFunc);
1099 roleFuncSet.add(roleFunc2);
1100 addRoleTest.setActive(true);
1101 addRoleTest.setName("Test2");
1102 addRoleTest.setId(2l);
1103 addRoleTest.setRoleFunctions(roleFuncSet);
1104 List<EPApp> appList = new ArrayList<>();
1105 final Map<String, String> appUebkeyParams = new HashMap<>();
1107 appUebkeyParams.put("appKey", app.getUebKey());
1108 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1109 .thenReturn(appList);
1110 List<EPRole> globalRoles = new ArrayList<>();
1111 EPRole globalRole = new EPRole();
1112 globalRole.setName("global_test");
1113 globalRole.setId(1111l);
1114 globalRole.setActive(true);
1115 globalRoles.add(globalRole);
1116 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1117 List<EPRole> epRoleList = new ArrayList<>();
1118 EPRole getEPRole = new EPRole();
1119 getEPRole.setName("Test");
1120 getEPRole.setId(2l);
1121 getEPRole.setActive(true);
1122 epRoleList.add(getEPRole);
1123 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1124 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1125 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1126 .thenReturn(epRoleList);
1127 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1128 HttpHeaders headers = new HttpHeaders();
1129 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1130 JSONObject mockJsonObjectFinalRole = new JSONObject();
1131 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1132 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1133 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1134 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1135 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1136 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1137 final Map<String, String> params = new HashMap<>();
1138 params.put("uebKey", app.getUebKey());
1139 params.put("roleId", String.valueOf(getEPRole.getId()));
1140 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1141 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1142 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1143 bulkUploadUserRoles.setOrgUserId("guestT");
1144 bulkUploadUserRoles.setRoleName("Test2");
1145 userRolesList.add(bulkUploadUserRoles);
1146 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1147 .thenReturn(userRolesList);
1149 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1151 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1152 .thenReturn("@test.com");
1153 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1154 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1155 appRoleFuncsParams.put("appId", app.getId());
1156 appRoleFuncsParams.put("roleId", getEPRole.getId());
1158 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1159 .thenReturn(appRoleFunctionList);
1160 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1161 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1162 final Map<String, String> getAppFunctionParams = new HashMap<>();
1163 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1164 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1165 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1166 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1167 v2RoleFunction.add(v2RoleFunction1);
1168 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1169 .thenReturn(v2RoleFunction);
1170 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1171 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1172 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1173 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1174 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1175 v2RoleFunction2.add(v2RoleFunction3);
1176 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1177 .thenReturn(v2RoleFunction2);
1178 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1180 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1181 assertEquals(expected, actual);
1185 public void saveGlobalRoleForPortalApplicationUpdateTest() throws Exception {
1186 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1187 PowerMockito.mockStatic(EcompPortalUtils.class);
1188 PowerMockito.mockStatic(SystemProperties.class);
1189 EPApp app = mockApp();
1191 Role addRoleTest = new Role();
1192 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1193 RoleFunction roleFunc = new RoleFunction();
1194 roleFunc.setName("Test Name");
1195 roleFunc.setCode("test_type|test_instance|*");
1196 RoleFunction roleFunc2 = new RoleFunction();
1197 roleFunc2.setName("Test Name3");
1198 roleFunc2.setCode("test_type3|test_instance3|*");
1199 roleFuncSet.add(roleFunc);
1200 roleFuncSet.add(roleFunc2);
1201 addRoleTest.setActive(true);
1202 addRoleTest.setName("global_test2");
1203 addRoleTest.setId(1111l);
1204 addRoleTest.setRoleFunctions(roleFuncSet);
1205 List<EPApp> appList = new ArrayList<>();
1206 final Map<String, String> appUebkeyParams = new HashMap<>();
1208 appUebkeyParams.put("appKey", app.getUebKey());
1209 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1210 .thenReturn(appList);
1211 List<EPRole> globalRoles = new ArrayList<>();
1212 EPRole globalRole = new EPRole();
1213 globalRole.setName("global_test");
1214 globalRole.setId(1111l);
1215 globalRole.setActive(true);
1216 globalRoles.add(globalRole);
1217 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1218 List<EPRole> epRoleList = new ArrayList<>();
1219 EPRole getEPRole = new EPRole();
1220 getEPRole.setName("global_test");
1221 getEPRole.setId(1111l);
1222 getEPRole.setActive(true);
1223 epRoleList.add(getEPRole);
1224 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1225 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1226 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1227 .thenReturn(epRoleList);
1228 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1229 HttpHeaders headers = new HttpHeaders();
1230 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1231 JSONObject mockJsonObjectRole = new JSONObject();
1232 JSONObject mockJsonObjectFinalRole = new JSONObject();
1233 JSONObject mockJsonObjectPerm1 = new JSONObject();
1234 JSONObject mockJsonObjectPerm2 = new JSONObject();
1235 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1236 mockJsonObjectPerm1.put("instance", "test_instance");
1237 mockJsonObjectPerm1.put("action", "*");
1238 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1239 mockJsonObjectPerm2.put("instance", "test_instance2");
1240 mockJsonObjectPerm2.put("action", "*");
1241 List<JSONObject> permsList = new ArrayList<>();
1242 permsList.add(mockJsonObjectPerm1);
1243 permsList.add(mockJsonObjectPerm2);
1244 mockJsonObjectRole.put("name", "com.test.app.global_test");
1245 mockJsonObjectRole.put("perms", permsList);
1246 mockJsonObjectRole.put("description",
1247 "{\"id\":\"1111\",\"name\":\"global_test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
1248 List<JSONObject> roleList = new ArrayList<>();
1249 roleList.add(mockJsonObjectRole);
1250 mockJsonObjectFinalRole.put("role", roleList);
1251 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1252 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1253 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1254 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1255 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1256 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1257 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1258 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1259 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1260 final Map<String, String> params = new HashMap<>();
1261 params.put("uebKey", app.getUebKey());
1262 params.put("roleId", String.valueOf(getEPRole.getId()));
1263 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1264 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1265 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1266 bulkUploadUserRoles.setOrgUserId("guestT");
1267 bulkUploadUserRoles.setRoleName("Test2");
1268 userRolesList.add(bulkUploadUserRoles);
1269 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1270 .thenReturn(userRolesList);
1272 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1274 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1275 .thenReturn("@test.com");
1276 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1277 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1278 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1279 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1280 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1281 appRoleFuncsParams.put("appId", app.getId());
1282 appRoleFuncsParams.put("roleId", getEPRole.getId());
1284 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1285 .thenReturn(appRoleFunctionList);
1286 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1287 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1288 final Map<String, String> getAppFunctionParams = new HashMap<>();
1289 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1290 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1291 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1292 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1293 v2RoleFunction.add(v2RoleFunction1);
1294 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1295 .thenReturn(v2RoleFunction);
1296 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1297 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1298 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1299 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1300 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1301 v2RoleFunction2.add(v2RoleFunction3);
1302 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1303 .thenReturn(v2RoleFunction2);
1304 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1306 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1307 assertEquals(expected, actual);
1311 public void saveRoleForPartnerApplicationUpdateTest() throws Exception {
1312 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1313 PowerMockito.mockStatic(EcompPortalUtils.class);
1314 PowerMockito.mockStatic(SystemProperties.class);
1315 EPApp app = mockApp();
1317 Role addRoleTest = new Role();
1318 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1319 RoleFunction roleFunc = new RoleFunction();
1320 roleFunc.setName("Test Name");
1321 roleFunc.setCode("test_type|test_instance|*");
1322 RoleFunction roleFunc2 = new RoleFunction();
1323 roleFunc2.setName("Test Name3");
1324 roleFunc2.setCode("test_type3|test_instance3|*");
1325 roleFuncSet.add(roleFunc);
1326 roleFuncSet.add(roleFunc2);
1327 addRoleTest.setActive(false);
1328 addRoleTest.setName("Test2");
1329 addRoleTest.setId(22l);
1330 addRoleTest.setRoleFunctions(roleFuncSet);
1331 List<EPApp> appList = new ArrayList<>();
1332 final Map<String, String> appUebkeyParams = new HashMap<>();
1334 appUebkeyParams.put("appKey", app.getUebKey());
1335 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1336 .thenReturn(appList);
1337 List<EPRole> globalRoles = new ArrayList<>();
1338 EPRole globalRole = new EPRole();
1339 globalRole.setName("global_test");
1340 globalRole.setId(1111l);
1341 globalRole.setActive(true);
1342 globalRoles.add(globalRole);
1343 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1344 List<EPRole> epRoleList = new ArrayList<>();
1345 EPRole getEPRole = new EPRole();
1346 getEPRole.setName("Test2");
1347 getEPRole.setId(2l);
1348 getEPRole.setActive(true);
1349 getEPRole.setAppRoleId(22l);
1350 epRoleList.add(getEPRole);
1351 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1352 getPortalAppRoleParams.put("appRoleId", addRoleTest.getId());
1353 getPortalAppRoleParams.put("appId", app.getId());
1354 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPortalAppRoleParams, null))
1355 .thenReturn(epRoleList);
1356 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1357 HttpHeaders headers = new HttpHeaders();
1358 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1359 JSONObject mockJsonObjectRole = new JSONObject();
1360 JSONObject mockJsonObjectFinalRole = new JSONObject();
1361 JSONObject mockJsonObjectPerm1 = new JSONObject();
1362 JSONObject mockJsonObjectPerm2 = new JSONObject();
1363 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1364 mockJsonObjectPerm1.put("instance", "test_instance");
1365 mockJsonObjectPerm1.put("action", "*");
1366 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1367 mockJsonObjectPerm2.put("instance", "test_instance2");
1368 mockJsonObjectPerm2.put("action", "*");
1369 List<JSONObject> permsList = new ArrayList<>();
1370 permsList.add(mockJsonObjectPerm1);
1371 permsList.add(mockJsonObjectPerm2);
1372 mockJsonObjectRole.put("name", "com.test.app.Test");
1373 mockJsonObjectRole.put("perms", permsList);
1374 mockJsonObjectRole.put("description",
1375 "{\"id\":\"2\",\"name\":\"Test2\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"22\"}");
1376 List<JSONObject> roleList = new ArrayList<>();
1377 roleList.add(mockJsonObjectRole);
1378 mockJsonObjectFinalRole.put("role", roleList);
1379 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1380 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1381 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1382 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1383 final Map<String, String> getPartnerAppRoleParams = new HashMap<>();
1384 getPartnerAppRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
1385 getPartnerAppRoleParams.put("appId", String.valueOf(app.getId()));
1386 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1387 getPartnerAppRoleParams, null)).thenReturn(epRoleList);
1388 ResponseEntity<String> updateRoleResponse = new ResponseEntity<>(HttpStatus.OK);
1389 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
1390 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateRoleResponse);
1391 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1392 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1393 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1394 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1395 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1396 final Map<String, String> params = new HashMap<>();
1397 params.put("uebKey", app.getUebKey());
1398 params.put("roleId", String.valueOf(getEPRole.getId()));
1399 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1400 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1401 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1402 bulkUploadUserRoles.setOrgUserId("guestT");
1403 bulkUploadUserRoles.setRoleName("Test2");
1404 userRolesList.add(bulkUploadUserRoles);
1405 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1406 .thenReturn(userRolesList);
1408 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1410 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1411 .thenReturn("@test.com");
1412 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1413 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1414 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1415 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1416 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1417 appRoleFuncsParams.put("appId", app.getId());
1418 appRoleFuncsParams.put("roleId", getEPRole.getId());
1420 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1421 .thenReturn(appRoleFunctionList);
1422 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1423 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1424 final Map<String, String> getAppFunctionParams = new HashMap<>();
1425 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1426 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1427 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1428 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1429 v2RoleFunction.add(v2RoleFunction1);
1430 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1431 .thenReturn(v2RoleFunction);
1432 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1433 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1434 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1435 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1436 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1437 v2RoleFunction2.add(v2RoleFunction3);
1438 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1439 .thenReturn(v2RoleFunction2);
1440 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1442 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1443 assertEquals(expected, actual);
1447 public void saveGlobalRoleFunctionsForPartnerApplicationUpdateTest() throws Exception {
1448 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1449 PowerMockito.mockStatic(EcompPortalUtils.class);
1450 PowerMockito.mockStatic(SystemProperties.class);
1451 EPApp app = mockApp();
1453 Role addRoleTest = new Role();
1454 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1455 RoleFunction roleFunc = new RoleFunction();
1456 roleFunc.setName("Test Name");
1457 roleFunc.setCode("test_type|test_instance|*");
1458 RoleFunction roleFunc2 = new RoleFunction();
1459 roleFunc2.setName("Test Name3");
1460 roleFunc2.setCode("test_type3|test_instance3|*");
1461 roleFuncSet.add(roleFunc);
1462 roleFuncSet.add(roleFunc2);
1463 addRoleTest.setActive(true);
1464 addRoleTest.setName("global_test");
1465 addRoleTest.setId(1111l);
1466 addRoleTest.setRoleFunctions(roleFuncSet);
1467 List<EPApp> appList = new ArrayList<>();
1468 final Map<String, String> appUebkeyParams = new HashMap<>();
1470 appUebkeyParams.put("appKey", app.getUebKey());
1471 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1472 .thenReturn(appList);
1473 List<EPRole> globalRoles = new ArrayList<>();
1474 EPRole globalRole = new EPRole();
1475 globalRole.setName("global_test");
1476 globalRole.setId(1111l);
1477 globalRole.setActive(true);
1478 EPRole globalRole2 = new EPRole();
1479 globalRole2.setName("global_test2");
1480 globalRole2.setId(2222l);
1481 globalRole2.setActive(true);
1482 globalRoles.add(globalRole);
1483 globalRoles.add(globalRole2);
1484 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1485 List<EPRole> getGlobalRoles = new ArrayList<>();
1486 EPRole getEPGlobalRole = new EPRole();
1487 getEPGlobalRole.setName("global_test");
1488 getEPGlobalRole.setId(1111l);
1489 getEPGlobalRole.setActive(true);
1490 getGlobalRoles.add(getEPGlobalRole);
1491 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1492 getPortalAppRoleParams.put("roleId", globalRole.getId());
1493 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1494 .thenReturn(getGlobalRoles);
1495 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1496 Mockito.when(epAppCommonServiceImpl.getApp(PortalConstants.PORTAL_APP_ID)).thenReturn(app);
1497 JSONObject mockJsonObjectPerm = new JSONObject();
1498 JSONObject mockJsonObjectPerm2 = new JSONObject();
1499 JSONObject mockJsonObjectPerm3 = new JSONObject();
1500 JSONObject mockJsonObjectPerm4 = new JSONObject();
1501 JSONObject mockJsonObjectFinalPerm = new JSONObject();
1502 mockJsonObjectPerm.put("type", "com.test.app.test_type");
1503 mockJsonObjectPerm.put("instance", "test_instance");
1504 mockJsonObjectPerm.put("action", "*");
1505 mockJsonObjectPerm.put("description", "Test Name");
1506 mockJsonObjectPerm2.put("type", "com.test.app.access");
1507 mockJsonObjectPerm2.put("instance", "test_instance2");
1508 mockJsonObjectPerm2.put("action", "*");
1509 mockJsonObjectPerm2.put("description", "Test Name2");
1510 mockJsonObjectPerm3.put("type", "com.test.app.test_type3");
1511 mockJsonObjectPerm3.put("instance", "test_instance3");
1512 mockJsonObjectPerm3.put("action", "*");
1513 mockJsonObjectPerm3.put("description", "Test Name3");
1514 mockJsonObjectPerm4.put("type", "com.test.app.test_type4");
1515 mockJsonObjectPerm4.put("instance", "test_instance4");
1516 mockJsonObjectPerm4.put("action", "*");
1517 mockJsonObjectPerm4.put("description", "Test Name4");
1518 List<JSONObject> mockJson = new ArrayList<>();
1519 mockJson.add(mockJsonObjectPerm);
1520 mockJson.add(mockJsonObjectPerm2);
1521 mockJson.add(mockJsonObjectPerm3);
1522 mockJson.add(mockJsonObjectPerm4);
1523 mockJsonObjectFinalPerm.put("perm", mockJson);
1524 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
1525 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1526 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1527 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1528 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
1529 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1530 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
1531 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1532 final Map<String, Long> epAppRoleFuncParams = new HashMap<>();
1533 epAppRoleFuncParams.put("requestedAppId", app.getId());
1534 epAppRoleFuncParams.put("roleId", globalRole.getId());
1535 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
1536 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
1537 mockGlobalRole.setActive(true);
1538 mockGlobalRole.setAppId(app.getId());
1539 mockGlobalRole.setRoleId(1111l);
1540 mockGlobalRole.setRoleName("global_test");
1541 mockGlobalRole.setFunctionCd("test_type4|test_instance4|*");
1542 mockGlobalRole.setFunctionName("test name");
1543 mockGlobalRoles.add(mockGlobalRole);
1544 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", epAppRoleFuncParams, null))
1545 .thenReturn(mockGlobalRoles);
1546 ResponseEntity<String> delResponse = new ResponseEntity<>(HttpStatus.OK);
1547 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1548 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1549 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1550 appRoleFuncsParams.put("appId", app.getId());
1551 appRoleFuncsParams.put("roleId", globalRole.getId());
1552 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1553 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
1554 epAppRoleFunction.setAppId(app.getId());
1555 epAppRoleFunction.setRoleAppId("1");
1556 epAppRoleFunction.setCode("test");
1557 epAppRoleFunction.setRoleId(1111l);
1558 appRoleFunctionList.add(epAppRoleFunction);
1560 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1561 .thenReturn(appRoleFunctionList);
1562 final Map<String, String> getAppFunctionParams = new HashMap<>();
1563 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1564 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1565 Mockito.when(EcompPortalUtils.getFunctionCode("test_type4|test_instance4|*")).thenReturn("test_instance4");
1566 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1567 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1568 List<CentralV2RoleFunction> roleFunction = new ArrayList<>();
1569 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, roleFunc.getCode(),
1570 roleFunc.getName(), app.getId(), null);
1571 roleFunction.add(centralV2RoleFunction);
1572 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1573 .thenReturn(roleFunction);
1574 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1575 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1576 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1577 List<CentralV2RoleFunction> roleFunction2 = new ArrayList<>();
1578 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, roleFunc2.getCode(),
1579 roleFunc2.getName(), app.getId(), null);
1580 roleFunction2.add(centralV2RoleFunction2);
1581 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1582 .thenReturn(roleFunction2);
1583 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1585 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1586 assertEquals(expected, actual);
1590 public void syncRoleFunctionFromExternalAccessSystemTest() {
1591 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1592 PowerMockito.mockStatic(EcompPortalUtils.class);
1593 PowerMockito.mockStatic(SystemProperties.class);
1594 EPApp app = mockApp();
1596 JSONObject mockJsonObjectFinalPerm = new JSONObject();
1597 JSONObject mockJsonObjectPerm = new JSONObject();
1598 JSONObject mockJsonObjectPerm2 = new JSONObject();
1599 JSONObject mockJsonObjectPerm3 = new JSONObject();
1600 mockJsonObjectPerm.put("type", "com.test.app.test_type");
1601 mockJsonObjectPerm.put("instance", "test_instance");
1602 mockJsonObjectPerm.put("action", "*");
1603 mockJsonObjectPerm.put("description", "test_name");
1604 List<String> rolePermList = new ArrayList<>();
1605 rolePermList.add("com.test.app|test1");
1606 mockJsonObjectPerm.put("roles", rolePermList);
1607 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1608 mockJsonObjectPerm2.put("instance", "test_instance2");
1609 List<String> rolePermList2 = new ArrayList<>();
1610 rolePermList2.add("com.test.app|test1");
1611 rolePermList2.add("com.test.app|test2");
1612 rolePermList2.add("com.test.app|test6");
1613 rolePermList2.add("com.test.app.new|global_test");
1614 mockJsonObjectPerm2.put("action", "*");
1615 mockJsonObjectPerm2.put("roles", rolePermList2);
1616 mockJsonObjectPerm2.put("description", "test_name2");
1617 mockJsonObjectPerm3.put("type", "com.test.app.access");
1618 mockJsonObjectPerm3.put("instance", "test_instance3");
1619 mockJsonObjectPerm3.put("action", "*");
1620 mockJsonObjectPerm3.put("description", "test_name3");
1621 List<JSONObject> permsList = new ArrayList<>();
1622 permsList.add(mockJsonObjectPerm);
1623 permsList.add(mockJsonObjectPerm2);
1624 permsList.add(mockJsonObjectPerm3);
1625 mockJsonObjectFinalPerm.put("perm", permsList);
1626 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
1627 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1628 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1629 final Map<String, Long> params = new HashMap<>();
1630 params.put(APP_ID, app.getId());
1631 List<CentralV2RoleFunction> appFunctions = new ArrayList<>();
1632 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*",
1633 "test_name", app.getId(), null);
1634 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_instance2", "test_name2",
1636 CentralV2RoleFunction centralV2RoleFunction3 = new CentralV2RoleFunction(null, "test_instance5", "test_name5",
1638 appFunctions.add(centralV2RoleFunction);
1639 appFunctions.add(centralV2RoleFunction2);
1640 appFunctions.add(centralV2RoleFunction3);
1641 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(appFunctions);
1642 List<EPRole> globalRoles = new ArrayList<>();
1643 EPRole globalRole = new EPRole();
1644 globalRole.setName("global_test");
1645 globalRole.setId(1111l);
1646 globalRole.setActive(true);
1647 globalRoles.add(globalRole);
1648 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1649 List<EPRole> getCurrentRoleList = new ArrayList<>();
1650 EPRole getEPRole = new EPRole();
1651 getEPRole.setName("test1");
1652 getEPRole.setId(2l);
1653 getEPRole.setActive(true);
1654 EPRole getEPRole2 = new EPRole();
1655 getEPRole2.setName("global_test");
1656 getEPRole2.setId(1111l);
1657 getEPRole2.setActive(true);
1658 EPRole getEPRole3 = new EPRole();
1659 getEPRole3.setName("test2");
1660 getEPRole3.setId(4l);
1661 getEPRole3.setActive(true);
1662 getCurrentRoleList.add(getEPRole);
1663 getCurrentRoleList.add(getEPRole2);
1664 getCurrentRoleList.add(getEPRole3);
1665 final Map<String, Long> appParams = new HashMap<>();
1666 appParams.put("appId", app.getId());
1667 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
1668 .thenReturn(getCurrentRoleList);
1669 final Map<String, String> appSyncFuncsParams = new HashMap<>();
1670 appSyncFuncsParams.put("appId", String.valueOf(app.getId()));
1671 appSyncFuncsParams.put("functionCd", "");
1672 List<CentralV2RoleFunction> roleFunctionList = new ArrayList<>();
1673 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1674 .thenReturn(roleFunctionList);
1675 String code = centralV2RoleFunction.getCode();
1676 appSyncFuncsParams.put("functionCd", code);
1677 CentralV2RoleFunction getCentralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*",
1678 "test_name", app.getId(), null);
1679 roleFunctionList.add(getCentralV2RoleFunction);
1680 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1681 .thenReturn(roleFunctionList);
1682 List<LocalRole> localRoles = new ArrayList<>();
1683 LocalRole localRole = new LocalRole();
1684 localRole.setRoleId(2);
1685 localRole.setRolename("test1");
1686 LocalRole localRole2 = new LocalRole();
1687 localRole2.setRoleId(3);
1688 localRole2.setRolename("test3");
1689 localRoles.add(localRole);
1690 localRoles.add(localRole2);
1691 final Map<String, String> appRoleFuncParams = new HashMap<>();
1692 appRoleFuncParams.put("functionCd", "test_type2|test_instance2|*");
1693 appRoleFuncParams.put("appId", String.valueOf(app.getId()));
1694 Mockito.when(dataAccessService.executeNamedQuery("getCurrentAppRoleFunctions", appRoleFuncParams, null))
1695 .thenReturn(localRoles);
1696 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app", app.getNameSpace())).thenReturn(true);
1697 Mockito.when(EcompPortalUtils.getFunctionCode("test_type2|test_instance2|*")).thenReturn("test_instance2");
1698 appSyncFuncsParams.put("functionCd", "test_instance2");
1699 List<CentralV2RoleFunction> roleFunctionList2 = new ArrayList<>();
1700 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1701 .thenReturn(roleFunctionList2);
1702 String code2 = "test_type2|test_instance2|*";
1703 appSyncFuncsParams.put("functionCd", code2);
1704 CentralV2RoleFunction getCentralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_type2|test_instance2|*",
1705 "test_name2", app.getId(), null);
1706 roleFunctionList2.add(getCentralV2RoleFunction2);
1707 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1708 .thenReturn(roleFunctionList2);
1709 final Map<String, Long> params3 = new HashMap<>();
1710 params3.put("appId", app.getId());
1711 params3.put("roleId", getEPRole2.getId());
1712 List<EPAppRoleFunction> currentGlobalRoleFunctionsList = new ArrayList<>();
1713 EPAppRoleFunction addGlobalRoleFunction = new EPAppRoleFunction();
1714 addGlobalRoleFunction.setAppId(app.getId());
1715 addGlobalRoleFunction.setCode("test_type|test_instance|*");
1716 addGlobalRoleFunction.setRoleId(1111l);
1717 currentGlobalRoleFunctionsList.add(addGlobalRoleFunction);
1718 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", params3, null))
1719 .thenReturn(currentGlobalRoleFunctionsList);
1720 final Map<String, String> roleParams = new HashMap<>();
1721 roleParams.put(APP_ROLE_NAME_PARAM, "test6");
1722 roleParams.put("appId", String.valueOf(app.getId()));
1723 List<EPRole> roleCreated = new ArrayList<>();
1724 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null))
1725 .thenReturn(roleCreated);
1726 final Map<String, String> getRoleByNameParams = new HashMap<>();
1727 getRoleByNameParams.put(APP_ROLE_NAME_PARAM, "test6");
1728 getRoleByNameParams.put("appId", String.valueOf(app.getId()));
1729 EPRole getNewEPRole = new EPRole();
1730 getNewEPRole.setName("test6");
1731 getNewEPRole.setId(8l);
1732 getNewEPRole.setActive(true);
1733 List<EPRole> roleCreated2 = new ArrayList<>();
1734 roleCreated2.add(getNewEPRole);
1735 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1736 getRoleByNameParams, null)).thenReturn(roleCreated2);
1737 EPRole getNewEPRoleFinal = new EPRole();
1738 getNewEPRoleFinal.setName("test6");
1739 getNewEPRoleFinal.setId(8l);
1740 getNewEPRoleFinal.setActive(true);
1741 getNewEPRoleFinal.setAppRoleId(8l);
1742 final Map<String, String> getRoleByNameParams2 = new HashMap<>();
1743 getRoleByNameParams2.put(APP_ROLE_NAME_PARAM, "test6");
1744 getRoleByNameParams2.put("appId", String.valueOf(app.getId()));
1745 List<EPRole> roleCreated3 = new ArrayList<>();
1746 roleCreated3.add(getNewEPRole);
1747 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1748 getRoleByNameParams2, null)).thenReturn(roleCreated3);
1749 List<EPRole> roleInfo = new ArrayList<>();
1750 roleInfo.add(getNewEPRoleFinal);
1751 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1752 getPartnerAppRoleParams.put("appRoleId", getNewEPRoleFinal.getId());
1753 getPartnerAppRoleParams.put("appId", app.getId());
1754 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
1755 .thenReturn(roleInfo);
1756 externalAccessRolesServiceImpl.syncRoleFunctionFromExternalAccessSystem(app);
1760 public void syncApplicationRolesWithEcompDBTest() {
1761 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1762 PowerMockito.mockStatic(EcompPortalUtils.class);
1763 PowerMockito.mockStatic(SystemProperties.class);
1764 EPApp app = mockApp();
1766 JSONObject mockJsonObjectRole = new JSONObject();
1767 JSONObject mockJsonObjectRole2 = new JSONObject();
1768 JSONObject mockJsonObjectFinalRole = new JSONObject();
1769 JSONObject mockJsonObjectPerm1 = new JSONObject();
1770 JSONObject mockJsonObjectPerm2 = new JSONObject();
1771 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1772 mockJsonObjectPerm1.put("instance", "test_instance");
1773 mockJsonObjectPerm1.put("action", "*");
1774 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1775 mockJsonObjectPerm2.put("instance", "test_instance2");
1776 mockJsonObjectPerm2.put("action", "*");
1777 List<JSONObject> permsList = new ArrayList<>();
1778 permsList.add(mockJsonObjectPerm1);
1779 permsList.add(mockJsonObjectPerm2);
1780 mockJsonObjectRole.put("name", "com.test.app.Test");
1781 mockJsonObjectRole.put("perms", permsList);
1782 mockJsonObjectRole.put("description",
1783 "{\"id\":\"2\",\"name\":\"test1\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"2\"}");
1784 mockJsonObjectRole2.put("name", "com.test.app.Test2");
1785 List<JSONObject> permsList2 = new ArrayList<>();
1786 permsList2.add(mockJsonObjectPerm1);
1787 mockJsonObjectRole2.put("perms", permsList2);
1788 List<JSONObject> roleList = new ArrayList<>();
1789 roleList.add(mockJsonObjectRole);
1790 roleList.add(mockJsonObjectRole2);
1791 mockJsonObjectFinalRole.put("role", roleList);
1792 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1793 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1794 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1795 List<EPRole> getCurrentRoleList = new ArrayList<>();
1796 EPRole getEPRole = new EPRole();
1797 getEPRole.setName("Test");
1798 getEPRole.setId(2l);
1799 getEPRole.setAppId(app.getId());
1800 getEPRole.setAppRoleId(2l);
1801 getEPRole.setActive(true);
1802 EPRole getEPRole2 = new EPRole();
1803 getEPRole2.setName("Test3");
1804 getEPRole2.setId(3l);
1805 getEPRole.setAppId(app.getId());
1806 getEPRole.setAppRoleId(3l);
1807 getEPRole2.setActive(true);
1808 getCurrentRoleList.add(getEPRole);
1809 getCurrentRoleList.add(getEPRole2);
1810 final Map<String, Long> appParams = new HashMap<>();
1811 appParams.put("appId", app.getId());
1812 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
1813 .thenReturn(getCurrentRoleList);
1814 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type", app.getNameSpace()))
1816 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type2", app.getNameSpace()))
1818 List<EPAppRoleFunction> appRoleFunctions = new ArrayList<>();
1819 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
1820 epAppRoleFunction.setAppId(app.getId());
1821 epAppRoleFunction.setCode("test_type|test_instance|*");
1822 epAppRoleFunction.setRoleId(getEPRole.getId());
1823 appRoleFunctions.add(epAppRoleFunction);
1824 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1825 appRoleFuncsParams.put("appId", app.getId());
1826 appRoleFuncsParams.put("roleId", Long.valueOf(getEPRole.getId()));
1828 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1829 .thenReturn(appRoleFunctions);
1830 List<CentralV2RoleFunction> getV2RoleFunction = new ArrayList<>();
1831 final Map<String, String> appFuncsParams = new HashMap<>();
1832 appFuncsParams.put("appId", String.valueOf(app.getId()));
1833 appFuncsParams.put("functionCd", "test_instance2");
1834 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null))
1835 .thenReturn(getV2RoleFunction);
1836 appFuncsParams.put("functionCd", "test_type2|test_instance2|*");
1837 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
1838 centralV2RoleFunction.setAppId(app.getId());
1839 centralV2RoleFunction.setCode("test_type2|test_instance2|*");
1840 centralV2RoleFunction.setName("test_name2");
1841 getV2RoleFunction.add(centralV2RoleFunction);
1842 final Map<String, String> extRoleParams = new HashMap<>();
1843 List<EPRole> roleListDeactivate = new ArrayList<>();
1844 extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3");
1845 extRoleParams.put(APP_ID, app.getId().toString());
1846 EPRole getEPRoleDeactivate = new EPRole();
1847 getEPRoleDeactivate.setName("Test3");
1848 getEPRoleDeactivate.setId(3l);
1849 getEPRoleDeactivate.setAppId(app.getId());
1850 getEPRoleDeactivate.setAppRoleId(3l);
1851 roleListDeactivate.add(getEPRoleDeactivate);
1853 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, extRoleParams, null))
1854 .thenReturn(roleListDeactivate);
1855 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null))
1856 .thenReturn(getV2RoleFunction);
1857 List<EPRole> updateLocalFromExtAuth = new ArrayList<>();
1858 updateLocalFromExtAuth.add(getEPRole);
1859 final Map<String, String> roleParams = new HashMap<>();
1860 roleParams.put(APP_ROLE_NAME_PARAM, getEPRole.getName());
1861 roleParams.put(APP_ID, app.getId().toString());
1862 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null))
1863 .thenReturn(updateLocalFromExtAuth);
1864 roleParams.put(APP_ROLE_NAME_PARAM, getEPRole2.getName());
1865 List<EPRole> updateLocalFromExtAuth2 = new ArrayList<>();
1866 updateLocalFromExtAuth.add(getEPRole);
1867 Mockito.when(dataAccessService.executeNamedQuery("getRoletoUpdateInExternalAuthSystem", roleParams, null))
1868 .thenReturn(updateLocalFromExtAuth2);
1869 final Map<String, String> globalRoleParams = new HashMap<>();
1870 globalRoleParams.put("appId", String.valueOf(app.getId()));
1871 globalRoleParams.put("appRoleName", "Test2");
1872 List<EPRole> addNewRoleList = new ArrayList<>();
1873 EPRole addRoleInLocal = new EPRole();
1874 addRoleInLocal.setName("Test2");
1875 addRoleInLocal.setId(4l);
1876 addRoleInLocal.setAppId(app.getId());
1877 addRoleInLocal.setActive(true);
1878 addNewRoleList.add(addRoleInLocal);
1880 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, globalRoleParams, null))
1881 .thenReturn(addNewRoleList);
1882 final Map<String, String> params = new HashMap<>();
1883 params.put(APP_ROLE_NAME_PARAM, "Test2");
1884 params.put(APP_ID, app.getId().toString());
1885 addRoleInLocal.setAppRoleId(4l);
1886 addNewRoleList.add(addRoleInLocal);
1887 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, params, null))
1888 .thenReturn(addNewRoleList);
1889 externalAccessRolesServiceImpl.syncApplicationRolesWithEcompDB(app);
1893 public void deleteDependencyRoleRecord() throws Exception {
1894 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1895 PowerMockito.mockStatic(EcompPortalUtils.class);
1896 PowerMockito.mockStatic(SystemProperties.class);
1897 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
1898 EPApp app = mockApp();
1900 EPUser user = mockUser.mockEPUser();
1901 List<EPApp> appList = new ArrayList<>();
1902 final Map<String, String> appUebkeyParams = new HashMap<>();
1904 appUebkeyParams.put("appKey", app.getUebKey());
1905 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1906 .thenReturn(appList);
1907 List<EPRole> epRoleList = new ArrayList<>();
1908 EPRole getEPRole = new EPRole();
1909 getEPRole.setName("Test");
1910 getEPRole.setId(2l);
1911 getEPRole.setAppRoleId(2l);
1912 getEPRole.setActive(true);
1913 epRoleList.add(getEPRole);
1914 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1915 getPartnerAppRoleParams.put("appRoleId", getEPRole.getId());
1916 getPartnerAppRoleParams.put("appId", app.getId());
1917 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
1918 .thenReturn(epRoleList);
1919 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1920 JSONObject getUser = new JSONObject();
1921 getUser.put("name", "com.test.app.test1");
1922 ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
1923 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1924 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1925 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
1926 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1927 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
1928 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
1929 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l,
1930 app.getUebKey(), user.getOrgUserId());
1931 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1932 assertEquals(expected, actual);
1936 public void deleteDependencyRoleRecordForPortal() throws Exception {
1937 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1938 PowerMockito.mockStatic(EcompPortalUtils.class);
1939 PowerMockito.mockStatic(SystemProperties.class);
1940 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
1941 EPApp app = mockApp();
1943 EPUser user = mockUser.mockEPUser();
1944 List<EPApp> appList = new ArrayList<>();
1945 final Map<String, String> appUebkeyParams = new HashMap<>();
1947 appUebkeyParams.put("appKey", app.getUebKey());
1948 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1949 .thenReturn(appList);
1950 List<EPRole> epRoleList = new ArrayList<>();
1951 EPRole getEPRole = new EPRole();
1952 getEPRole.setName("Test");
1953 getEPRole.setId(2l);
1954 getEPRole.setAppRoleId(2l);
1955 getEPRole.setActive(true);
1956 epRoleList.add(getEPRole);
1957 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1958 getPartnerAppRoleParams.put("roleId", getEPRole.getId());
1959 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPartnerAppRoleParams, null))
1960 .thenReturn(epRoleList);
1961 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1962 JSONObject getUser = new JSONObject();
1963 getUser.put("name", "com.test.app.test1");
1964 ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
1965 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1966 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1967 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
1968 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1969 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
1970 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
1971 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l,
1972 app.getUebKey(), user.getOrgUserId());
1973 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1974 assertEquals(expected, actual);
1978 public void bulkUploadFunctionsTest() throws Exception {
1979 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1980 PowerMockito.mockStatic(EcompPortalUtils.class);
1981 PowerMockito.mockStatic(SystemProperties.class);
1982 EPApp app = mockApp();
1984 List<EPApp> appList = new ArrayList<>();
1985 final Map<String, String> appUebkeyParams = new HashMap<>();
1987 appUebkeyParams.put("appKey", app.getUebKey());
1988 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1989 .thenReturn(appList);
1990 List<RoleFunction> roleFuncList = new ArrayList<>();
1991 RoleFunction roleFunc = new RoleFunction();
1992 roleFunc.setCode("test_code");
1993 roleFunc.setName("test_name");
1994 RoleFunction roleFunc2 = new RoleFunction();
1995 roleFunc2.setCode("test_code2");
1996 roleFunc2.setName("test_name2");
1997 roleFuncList.add(roleFunc);
1998 roleFuncList.add(roleFunc2);
1999 Mockito.when(dataAccessService.executeNamedQuery("getAllFunctions", null, null)).thenReturn(roleFuncList);
2000 JSONObject perm = new JSONObject();
2001 JSONObject permList = new JSONObject();
2002 perm.put("type", app.getNameSpace() + ".access");
2003 perm.put("instance", "type_instance");
2004 perm.put("action", "*");
2005 List<JSONObject> addPerms = new ArrayList<>();
2007 permList.put("perm", addPerms);
2008 ResponseEntity<String> getResponse = new ResponseEntity<>(permList.toString(), HttpStatus.OK);
2009 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
2010 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2011 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2012 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2013 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2014 Integer actual = externalAccessRolesServiceImpl.bulkUploadFunctions(app.getUebKey());
2015 Integer expected = 2;
2016 assertEquals(expected, actual);
2020 public void bulkUploadRolesTest() throws Exception {
2021 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2022 PowerMockito.mockStatic(EcompPortalUtils.class);
2023 PowerMockito.mockStatic(SystemProperties.class);
2024 EPApp app = mockApp();
2026 List<EPApp> appList = new ArrayList<>();
2027 final Map<String, String> appUebkeyParams = new HashMap<>();
2029 appUebkeyParams.put("appKey", app.getUebKey());
2030 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2031 .thenReturn(appList);
2032 List<EPRole> epRoleList = new ArrayList<>();
2033 EPRole getEPRole = new EPRole();
2034 getEPRole.setName("Test");
2035 getEPRole.setId(2l);
2036 getEPRole.setAppRoleId(2l);
2037 getEPRole.setActive(true);
2038 EPRole getEPRole2 = new EPRole();
2039 getEPRole2.setName("Test2");
2040 getEPRole2.setId(3l);
2041 getEPRole2.setAppRoleId(3l);
2042 getEPRole2.setActive(true);
2043 epRoleList.add(getEPRole);
2044 epRoleList.add(getEPRole2);
2045 final Map<String, Long> appParams = new HashMap<>();
2046 appParams.put("appId", app.getId());
2047 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
2048 .thenReturn(epRoleList);
2049 List<EPRole> epRoleList1 = new ArrayList<>();
2050 EPRole ePRole = new EPRole();
2051 ePRole.setName("Test");
2053 ePRole.setAppRoleId(2l);
2054 ePRole.setActive(true);
2055 epRoleList1.add(ePRole);
2056 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
2057 getPartnerAppRoleParams.put("appRoleId", ePRole.getId());
2058 getPartnerAppRoleParams.put("appId", app.getId());
2059 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
2060 .thenReturn(epRoleList1);
2061 List<EPRole> epRoleList2 = new ArrayList<>();
2062 EPRole ePRole2 = new EPRole();
2063 ePRole2.setName("Test2");
2065 ePRole2.setAppRoleId(3l);
2066 ePRole2.setActive(true);
2067 epRoleList2.add(ePRole2);
2068 final Map<String, Long> getPartnerAppRoleParams2 = new HashMap<>();
2069 getPartnerAppRoleParams2.put("appRoleId", ePRole2.getId());
2070 getPartnerAppRoleParams2.put("appId", app.getId());
2071 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams2, null))
2072 .thenReturn(epRoleList2);
2073 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2074 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2075 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2076 Integer actual = externalAccessRolesServiceImpl.bulkUploadRoles(app.getUebKey());
2077 Integer expected = 2;
2078 assertEquals(expected, actual);
2082 public void bulkUploadUserRolesTest() throws Exception {
2083 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2084 PowerMockito.mockStatic(EcompPortalUtils.class);
2085 PowerMockito.mockStatic(SystemProperties.class);
2086 EPApp app = mockApp();
2088 EPUser user = mockUser.mockEPUser();
2089 List<EPApp> appList = new ArrayList<>();
2090 final Map<String, String> appUebkeyParams = new HashMap<>();
2092 appUebkeyParams.put("appKey", app.getUebKey());
2093 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2094 .thenReturn(appList);
2095 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
2096 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
2097 bulkUploadUserRoles.setAppNameSpace(app.getName());
2098 bulkUploadUserRoles.setOrgUserId(user.getOrgUserId());
2099 bulkUploadUserRoles.setRoleName("Test1");
2100 BulkUploadUserRoles bulkUploadUserRoles2 = new BulkUploadUserRoles();
2101 bulkUploadUserRoles2.setAppNameSpace(app.getName());
2102 bulkUploadUserRoles2.setOrgUserId(user.getOrgUserId());
2103 bulkUploadUserRoles2.setRoleName("Test2");
2104 userRolesList.add(bulkUploadUserRoles);
2105 userRolesList.add(bulkUploadUserRoles2);
2106 final Map<String, String> appParams = new HashMap<>();
2107 appParams.put("uebKey", app.getUebKey());
2108 Mockito.when(dataAccessService.executeNamedQuery("getBulkUserRoles", appParams, null))
2109 .thenReturn(userRolesList);
2110 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2111 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2112 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2113 Integer actual = externalAccessRolesServiceImpl.bulkUploadUserRoles(app.getUebKey());
2114 Integer expected = 2;
2115 assertEquals(expected, actual);
2119 public void getUserRolesTest() throws Exception {
2120 EPApp app = mockApp();
2121 EPUser user = mockUser.mockEPUser();
2122 List<EPApp> appList = new ArrayList<>();
2123 final Map<String, String> appUebkeyParams = new HashMap<>();
2125 appUebkeyParams.put("appKey", app.getUebKey());
2126 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2127 .thenReturn(appList);
2128 final Map<String, String> userParams = new HashMap<>();
2129 userParams.put("org_user_id", user.getOrgUserId());
2130 List<EPUser> userList = new ArrayList<>();
2131 Set<EPUserApp> userAppSet = user.getEPUserApps();
2132 EPUserApp epUserApp = new EPUserApp();
2133 EPRole epRole = new EPRole();
2134 epRole.setName("test");
2136 epRole.setActive(true);
2137 epRole.setAppRoleId(11l);
2138 epUserApp.setApp(app);
2139 epUserApp.setUserId(user.getId());
2140 epUserApp.setRole(epRole);
2141 userAppSet.add(epUserApp);
2142 user.setUserApps(userAppSet);
2144 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
2145 .thenReturn(userList);
2146 CentralUser actual = externalAccessRolesServiceImpl.getUserRoles(user.getOrgUserId(), app.getUebKey());
2147 assertNotNull(actual);
2150 @SuppressWarnings("unchecked")
2152 public void getActiveRolesTest() throws Exception {
2153 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2154 PowerMockito.mockStatic(EcompPortalUtils.class);
2155 PowerMockito.mockStatic(SystemProperties.class);
2156 PowerMockito.mockStatic(EPUserUtils.class);
2157 PowerMockito.mockStatic(Restrictions.class);
2158 PowerMockito.mockStatic(Criterion.class);
2159 EPApp app = mockApp();
2161 List<EPApp> appList = new ArrayList<>();
2162 final Map<String, String> appUebkeyParams = new HashMap<>();
2164 appUebkeyParams.put("appKey", app.getUebKey());
2165 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2166 .thenReturn(appList);
2167 List<EPRole> epRoles = new ArrayList<>();
2168 EPRole getEPRole = new EPRole();
2169 getEPRole.setName("Test");
2170 getEPRole.setId(2l);
2171 getEPRole.setActive(true);
2172 EPRole getEPRole2 = new EPRole();
2173 getEPRole2.setName("Test2");
2174 getEPRole2.setId(3l);
2175 getEPRole2.setActive(true);
2176 epRoles.add(getEPRole);
2177 epRoles.add(getEPRole2);
2178 List<Criterion> restrictionsList = new ArrayList<Criterion>();
2179 Criterion active_ynCrt = Restrictions.eq("active", Boolean.TRUE);
2180 Criterion appIdCrt = Restrictions.isNull("appId");
2181 Criterion andCrit = Restrictions.and(active_ynCrt, appIdCrt);
2182 restrictionsList.add(andCrit);
2183 Mockito.when((List<EPRole>) dataAccessService.getList(EPRole.class, null, restrictionsList, null))
2184 .thenReturn(epRoles);
2185 final Map<String, Long> params = new HashMap<>();
2186 params.put("roleId", getEPRole.getId());
2187 params.put(APP_ID, app.getId());
2188 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
2189 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|test_instance|*",
2191 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction("test_instance2", "test_name2");
2192 cenRoleFuncList.add(centralV2RoleFunction);
2193 cenRoleFuncList.add(centralV2RoleFunction2);
2194 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
2195 .thenReturn(cenRoleFuncList);
2196 final Map<String, Long> params2 = new HashMap<>();
2197 params2.put("roleId", getEPRole2.getId());
2198 params2.put(APP_ID, app.getId());
2199 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params2, null))
2200 .thenReturn(cenRoleFuncList);
2201 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
2202 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
2203 mockGlobalRole.setActive(true);
2204 mockGlobalRole.setAppId(app.getId());
2205 mockGlobalRole.setRoleId(1111l);
2206 mockGlobalRole.setRoleName("global_test");
2207 mockGlobalRole.setFunctionCd("test_type|test_code|*");
2208 mockGlobalRole.setFunctionName("test name");
2209 mockGlobalRoles.add(mockGlobalRole);
2210 Map<String, Long> params3 = new HashMap<>();
2211 params3.put("appId", app.getId());
2212 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params3, null))
2213 .thenReturn(mockGlobalRoles);
2214 Mockito.when(EcompPortalUtils.getFunctionCode(centralV2RoleFunction.getCode())).thenReturn("test_instance");
2215 Mockito.when(EcompPortalUtils.getFunctionCode(centralV2RoleFunction2.getCode())).thenReturn("test_instance2");
2216 List<CentralV2Role> actual = externalAccessRolesServiceImpl.getActiveRoles(app.getUebKey());
2217 assertEquals(actual.size(), 3);
2221 public void bulkUploadRolesFunctionsTest() throws Exception {
2222 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2223 PowerMockito.mockStatic(EcompPortalUtils.class);
2224 PowerMockito.mockStatic(SystemProperties.class);
2225 EPApp app = mockApp();
2226 List<EPApp> appList = new ArrayList<>();
2227 final Map<String, String> appUebkeyParams = new HashMap<>();
2229 appUebkeyParams.put("appKey", app.getUebKey());
2230 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2231 .thenReturn(appList);
2232 List<EPRole> applicationRoles = new ArrayList<>();
2233 EPRole getEPRole = new EPRole();
2234 getEPRole.setName("Test");
2235 getEPRole.setId(2l);
2236 getEPRole.setActive(true);
2237 EPRole getEPRole2 = new EPRole();
2238 getEPRole2.setName("Test2");
2239 getEPRole2.setId(3l);
2240 getEPRole2.setActive(true);
2241 applicationRoles.add(getEPRole);
2242 applicationRoles.add(getEPRole2);
2243 final Map<String, Long> appParams = new HashMap<>();
2244 appParams.put("appId", app.getId());
2245 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
2246 .thenReturn(applicationRoles);
2247 final Map<String, Long> params = new HashMap<>();
2248 params.put("roleId", getEPRole.getId());
2249 List<BulkUploadRoleFunction> appRoleFunc = new ArrayList<>();
2250 BulkUploadRoleFunction bulkUploadRoleFunction = new BulkUploadRoleFunction();
2251 bulkUploadRoleFunction.setFunctionCd("testcode");
2252 bulkUploadRoleFunction.setFunctionName("test_name");
2253 BulkUploadRoleFunction bulkUploadRoleFunction2 = new BulkUploadRoleFunction();
2254 bulkUploadRoleFunction2.setFunctionCd("menu_testcode2");
2255 bulkUploadRoleFunction2.setFunctionName("test_name2");
2256 appRoleFunc.add(bulkUploadRoleFunction);
2257 appRoleFunc.add(bulkUploadRoleFunction2);
2258 Mockito.when(dataAccessService.executeNamedQuery("uploadAllRoleFunctions", params, null))
2259 .thenReturn(appRoleFunc);
2260 final Map<String, Long> params2 = new HashMap<>();
2261 params2.put("roleId", getEPRole2.getId());
2262 List<BulkUploadRoleFunction> appRoleFunc2 = new ArrayList<>();
2263 appRoleFunc2.add(bulkUploadRoleFunction);
2264 appRoleFunc2.add(bulkUploadRoleFunction2);
2265 Mockito.when(dataAccessService.executeNamedQuery("uploadAllRoleFunctions", params2, null))
2266 .thenReturn(appRoleFunc2);
2267 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.CREATED);
2268 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2269 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2270 Integer actual = externalAccessRolesServiceImpl.bulkUploadRolesFunctions(app.getUebKey());
2271 Integer expected = 4;
2272 assertEquals(actual, expected);
2276 public void bulkUploadPartnerRoleFunctionsTest() throws Exception {
2277 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2278 PowerMockito.mockStatic(EcompPortalUtils.class);
2279 PowerMockito.mockStatic(SystemProperties.class);
2280 EPApp app = mockApp();
2281 List<EPApp> appList = new ArrayList<>();
2282 final Map<String, String> appUebkeyParams = new HashMap<>();
2284 appUebkeyParams.put("appKey", app.getUebKey());
2285 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2286 .thenReturn(appList);
2287 List<Role> roles = new ArrayList<>();
2288 Role role = new Role();
2289 role.setName("Test");
2291 role.setActive(true);
2292 Role role2 = new Role();
2293 role2.setName("Test2");
2295 role2.setActive(true);
2298 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
2299 RoleFunction roleFunc = new RoleFunction();
2300 roleFunc.setName("Test Name");
2301 roleFunc.setCode("testcode");
2302 RoleFunction roleFunc2 = new RoleFunction();
2303 roleFunc2.setName("Test Name3");
2304 roleFunc2.setCode("menu_testcode2");
2305 roleFuncSet.add(roleFunc);
2306 roleFuncSet.add(roleFunc2);
2307 role.setRoleFunctions(roleFuncSet);
2308 role2.setRoleFunctions(roleFuncSet);
2309 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
2310 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
2311 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2312 externalAccessRolesServiceImpl.bulkUploadPartnerRoleFunctions(app.getUebKey(), roles);
2316 public void getMenuFunctionsListTest() throws Exception {
2317 EPApp app = mockApp();
2318 List<EPApp> appList = new ArrayList<>();
2319 final Map<String, String> appUebkeyParams = new HashMap<>();
2321 appUebkeyParams.put("appKey", app.getUebKey());
2322 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2323 .thenReturn(appList);
2324 final Map<String, Long> appParams = new HashMap<>();
2325 appParams.put(APP_ID, app.getId());
2326 List<String> expected = new ArrayList<>();
2327 expected.add("test_menu1");
2328 expected.add("test_menu2");
2329 Mockito.when(dataAccessService.executeNamedQuery("getMenuFunctions", appParams, null)).thenReturn(expected);
2330 List<String> actual = externalAccessRolesServiceImpl.getMenuFunctionsList(app.getUebKey());
2331 assertEquals(expected, actual);
2335 public void getCentralizedAppsOfUserTest() {
2336 EPUser user = mockUser.mockEPUser();
2337 Map<String, String> params = new HashMap<>();
2338 params.put("userId", user.getOrgUserId());
2339 List<CentralizedApp> expected = new ArrayList<>();
2340 CentralizedApp centralizedApp = new CentralizedApp();
2341 centralizedApp.setAppId(2);
2342 centralizedApp.setAppName("testapp1");
2343 expected.add(centralizedApp);
2344 Mockito.when(dataAccessService.executeNamedQuery("getCentralizedAppsOfUser", params, null))
2345 .thenReturn(expected);
2346 List<CentralizedApp> actual = externalAccessRolesServiceImpl.getCentralizedAppsOfUser(user.getOrgUserId());
2347 assertEquals(expected, actual);
2351 public void ConvertCentralRoleToRoleTest() throws Exception {
2352 ObjectMapper mapper = new ObjectMapper();
2353 Role role = new Role();
2354 role.setName("Test");
2356 role.setActive(true);
2357 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
2358 RoleFunction roleFunc = new RoleFunction();
2359 roleFunc.setName("Test Name");
2360 roleFunc.setCode("testcode");
2361 RoleFunction roleFunc2 = new RoleFunction();
2362 roleFunc2.setName("Test Name3");
2363 roleFunc2.setCode("menu_testcode2");
2364 roleFuncSet.add(roleFunc);
2365 roleFuncSet.add(roleFunc2);
2366 role.setRoleFunctions(roleFuncSet);
2367 String roleInfo = mapper.writeValueAsString(role);
2368 Role actual = externalAccessRolesServiceImpl.ConvertCentralRoleToRole(roleInfo);
2369 assertNotNull(actual);
2373 public void convertV2CentralRoleListToOldVerisonCentralRoleListTest() {
2374 List<CentralV2Role> v2CenRoleList = new ArrayList<>();
2375 CentralV2Role cenV2Role = new CentralV2Role(2l, "test1");
2376 CentralV2RoleFunction CentralV2Role = new CentralV2RoleFunction("testcode", "test_name");
2377 SortedSet<CentralV2RoleFunction> setV2RoleFuncs = new TreeSet<>();
2378 setV2RoleFuncs.add(CentralV2Role);
2379 cenV2Role.setRoleFunctions(setV2RoleFuncs);
2380 v2CenRoleList.add(cenV2Role);
2381 List<CentralRole> actual = externalAccessRolesServiceImpl.convertV2CentralRoleListToOldVerisonCentralRoleList(v2CenRoleList);
2382 assertEquals(1, actual.size());