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 CentralV2RoleFunction expected = new CentralV2RoleFunction(null, "type_code", "test_name", null, "test_type",
525 Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code");
526 Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
527 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
528 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
529 CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
530 getRoleFuncList.add(getCenRole);
531 final Map<String, String> params = new HashMap<>();
532 params.put(FUNCTION_CODE_PARAMS, "test_type|type_code|*");
533 params.put(APP_ID, String.valueOf(app.getId()));
534 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null))
535 .thenReturn(getRoleFuncList);
536 CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
538 assertEquals(expected.getCode(), actual.getCode());
542 public void getRoleFunctionMutilpleFilterTest() throws Exception {
543 PowerMockito.mockStatic(EcompPortalUtils.class);
544 PowerMockito.mockStatic(EPCommonSystemProperties.class);
545 PowerMockito.mockStatic(SystemProperties.class);
546 EPApp app = mockApp();
547 List<EPApp> appList = new ArrayList<>();
549 final Map<String, String> appUebkeyParams = new HashMap<>();
550 appUebkeyParams.put("appKey", app.getUebKey());
551 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
552 .thenReturn(appList);
553 CentralV2RoleFunction expected = new CentralV2RoleFunction(null, "type_code", "test_name", null, "test_type",
555 Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code");
556 Mockito.when(EcompPortalUtils.getFunctionCode("test_type_1|type_code_1|*")).thenReturn("type_code_1");
557 Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type");
558 Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*");
559 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
560 CentralV2RoleFunction getCenRole = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
561 CentralV2RoleFunction getCenRole2 = new CentralV2RoleFunction("test_type_1|type_code_1|*", "test_name_1");
562 getRoleFuncList.add(getCenRole);
563 getRoleFuncList.add(getCenRole2);
564 final Map<String, String> params = new HashMap<>();
565 params.put(FUNCTION_CODE_PARAMS, "test_type|type_code|*");
566 params.put(APP_ID, String.valueOf(app.getId()));
567 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, params, null))
568 .thenReturn(getRoleFuncList);
569 CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*",
571 assertEquals(expected.getCode(), actual.getCode());
575 public void getUserTest() throws InvalidUserException {
576 List<EPUser> userList = new ArrayList<>();
577 EPUser user = mockUser.mockEPUser();
579 final Map<String, String> userParams = new HashMap<>();
580 userParams.put("org_user_id", "guestT");
581 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
582 .thenReturn(userList);
583 List<EPUser> expectedUserList = externalAccessRolesServiceImpl.getUser("guestT");
584 assertEquals(expectedUserList, userList);
588 public void getV2UserWithRolesTest() throws Exception {
589 EPApp app = mockApp();
591 EPUser user = mockUser.mockEPUser();
592 List<EPApp> appList = new ArrayList<>();
594 final Map<String, String> appUebkeyParams = new HashMap<>();
595 appUebkeyParams.put("appKey", app.getUebKey());
596 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
597 .thenReturn(appList);
598 final Map<String, String> userParams = new HashMap<>();
599 userParams.put("org_user_id", user.getOrgUserId());
600 List<EPUser> userList = new ArrayList<>();
601 Set<EPUserApp> userAppSet = user.getEPUserApps();
602 EPUserApp epUserApp = new EPUserApp();
603 EPRole epRole = new EPRole();
604 epRole.setName("test");
606 epRole.setActive(true);
607 epRole.setAppRoleId(11l);
608 epUserApp.setApp(app);
609 epUserApp.setUserId(user.getId());
610 epUserApp.setRole(epRole);
611 userAppSet.add(epUserApp);
612 user.setUserApps(userAppSet);
614 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
615 .thenReturn(userList);
616 final Map<String, Long> params = new HashMap<>();
617 List<CentralV2RoleFunction> appRoleFunctionList = new ArrayList<>();
618 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
619 centralV2RoleFunction.setCode("test_type|test_code|*");
620 centralV2RoleFunction.setName("test name");
621 centralV2RoleFunction.setAppId(app.getId());
622 appRoleFunctionList.add(centralV2RoleFunction);
623 params.put("roleId", epUserApp.getRole().getId());
624 params.put(APP_ID, epUserApp.getApp().getId());
625 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
626 .thenReturn(appRoleFunctionList);
627 String actual = externalAccessRolesServiceImpl.getV2UserWithRoles(user.getOrgUserId(), app.getUebKey());
628 String notExpected = "";
629 assertNotEquals(actual, notExpected);
633 public void saveCentralRoleFunctionNewTestForV2() throws Exception {
634 PowerMockito.mockStatic(EcompPortalUtils.class);
635 EPApp app = mockApp();
637 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
638 centralV2RoleFunction.setCode("test_code");
639 centralV2RoleFunction.setName("test name");
640 centralV2RoleFunction.setAppId(app.getId());
641 centralV2RoleFunction.setAction("*");
642 centralV2RoleFunction.setType("test_type");
643 final Map<String, String> params = new HashMap<>();
644 params.put("appId", String.valueOf(1));
646 List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
647 appRoleFunc.add(centralV2RoleFunction);
648 params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
649 + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
650 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
651 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
652 HttpHeaders headers = new HttpHeaders();
653 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
654 JSONObject mockJsonObjectPerm = new JSONObject();
655 JSONObject mockJsonObjectFinalPerm = new JSONObject();
656 mockJsonObjectPerm.put("type", "com.test.app.test_type");
657 mockJsonObjectPerm.put("instance", "com.test.app.test_code");
658 mockJsonObjectPerm.put("action", "*");
659 mockJsonObjectPerm.put("description", "test name");
660 List<JSONObject> mockJson = new ArrayList<>();
661 mockJson.add(mockJsonObjectPerm);
662 mockJsonObjectFinalPerm.put("perm", mockJson);
663 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
664 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
665 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
666 ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
667 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
668 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
669 Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
670 assertEquals(true, actual);
674 public void saveCentralRoleFunctionUpdateForV2Test() throws Exception {
675 PowerMockito.mockStatic(EcompPortalUtils.class);
676 EPApp app = mockApp();
678 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
679 centralV2RoleFunction.setCode("test_code");
680 centralV2RoleFunction.setName("test name2");
681 centralV2RoleFunction.setAppId(app.getId());
682 centralV2RoleFunction.setAction("*");
683 centralV2RoleFunction.setType("test_type");
684 CentralV2RoleFunction centralV2RoleFunctionExisting = new CentralV2RoleFunction();
685 centralV2RoleFunctionExisting.setCode("test_code");
686 centralV2RoleFunctionExisting.setName("test name");
687 centralV2RoleFunctionExisting.setAppId(app.getId());
688 centralV2RoleFunctionExisting.setAction("*");
689 centralV2RoleFunctionExisting.setType("test_type");
690 final Map<String, String> params = new HashMap<>();
691 params.put("appId", String.valueOf(1));
692 List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
693 appRoleFunc.add(centralV2RoleFunctionExisting);
694 params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
695 + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
696 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
697 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
698 HttpHeaders headers = new HttpHeaders();
699 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
700 JSONObject mockJsonObjectPerm = new JSONObject();
701 JSONObject mockJsonObjectFinalPerm = new JSONObject();
702 mockJsonObjectPerm.put("type", "com.test.app.test_type");
703 mockJsonObjectPerm.put("instance", "test_code");
704 mockJsonObjectPerm.put("action", "*");
705 mockJsonObjectPerm.put("description", "test name");
706 List<JSONObject> mockJson = new ArrayList<>();
707 mockJson.add(mockJsonObjectPerm);
708 mockJsonObjectFinalPerm.put("perm", mockJson);
709 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
710 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
711 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
712 ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
713 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
714 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
715 Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
716 assertEquals(true, actual);
719 @SuppressWarnings("deprecation")
721 public void getAllAppUsersTest() throws Exception {
722 EPApp app = new EPApp();
723 app.setEnabled(true);
724 app.setId((long) 10);
725 List<EPApp> appList = new ArrayList<>();
726 final Map<String, String> appUebkeyParams = new HashMap<>();
728 appUebkeyParams.put("appKey", app.getUebKey());
729 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
730 .thenReturn(appList);
731 List<EPRole> applicationRoles = new ArrayList<>();
732 Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
733 Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
734 .thenReturn(appList);
735 final Map<String, Long> appParams = new HashMap<>();
736 appParams.put("appId", app.getId());
737 List<EcompUserRoles> userList = new ArrayList<>();
738 EcompUserRoles ecompUserRoles = new EcompUserRoles();
739 ecompUserRoles.setOrgUserId("guestT");
740 ecompUserRoles.setRoleId((long) 1);
741 ecompUserRoles.setRoleName("test");
742 EcompUserRoles ecompUserRoles2 = new EcompUserRoles();
743 ecompUserRoles2.setOrgUserId("guestT");
744 ecompUserRoles2.setRoleId((long) 2);
745 ecompUserRoles2.setRoleName("test new");
746 userList.add(ecompUserRoles);
747 userList.add(ecompUserRoles2);
748 Mockito.when(dataAccessService.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
749 List<EcompUser> usersfinalList = externalAccessRolesServiceImpl.getAllAppUsers(app.getUebKey());
750 assertEquals(usersfinalList.get(0).getRoles().size(), 2);
754 public void getGlobalRolesOfPortalTest() {
755 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(null);
756 assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), null);
760 public void getGlobalRolesOfPortalExceptionTest() {
761 List<EPRole> globalRoles = new ArrayList<>();
762 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null))
763 .thenThrow(nullPointerException);
764 assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), globalRoles);
768 public void getRolesForAppTest() throws Exception {
769 EPApp app = mockApp();
771 List<EPApp> appList = new ArrayList<>();
772 final Map<String, String> appUebkeyParams = new HashMap<>();
774 appUebkeyParams.put("appKey", app.getUebKey());
775 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
776 .thenReturn(appList);
777 List<EPRole> applicationRoles = new ArrayList<>();
778 EPRole appRole = new EPRole();
779 appRole.setActive(true);
780 appRole.setAppId(app.getId());
781 appRole.setAppRoleId(100l);
783 appRole.setName("test");
784 applicationRoles.add(appRole);
785 final Map<String, Long> appParams = new HashMap<>();
786 appParams.put("appId", app.getId());
787 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
788 .thenReturn(applicationRoles);
789 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
790 CentralV2RoleFunction v2RoleFunction = new CentralV2RoleFunction();
791 v2RoleFunction.setAppId(app.getId());
792 v2RoleFunction.setCode("test_type|test_code|*");
793 v2RoleFunction.setName("test name");
794 cenRoleFuncList.add(v2RoleFunction);
795 final Map<String, Long> params = new HashMap<>();
796 params.put("roleId", appRole.getId());
797 params.put(APP_ID, appList.get(0).getId());
798 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
799 .thenReturn(cenRoleFuncList);
800 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
801 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
802 mockGlobalRole.setActive(true);
803 mockGlobalRole.setAppId(app.getId());
804 mockGlobalRole.setRoleId(1111l);
805 mockGlobalRole.setRoleName("global_test");
806 mockGlobalRole.setFunctionCd("test_type|test_code|*");
807 mockGlobalRole.setFunctionName("test name");
808 mockGlobalRoles.add(mockGlobalRole);
809 Map<String, Long> params2 = new HashMap<>();
810 params2.put("appId", app.getId());
811 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params2, null))
812 .thenReturn(mockGlobalRoles);
813 List<EPRole> globalRoles = new ArrayList<>();
814 EPRole globalRole = new EPRole();
815 globalRole.setName("global_test");
816 globalRole.setId(1111l);
817 globalRole.setActive(true);
818 globalRoles.add(globalRole);
819 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
820 List<CentralV2Role> expected = new ArrayList<>();
821 CentralV2Role cenV2Role = new CentralV2Role();
822 CentralV2Role cenV2Role2 = new CentralV2Role();
823 expected.add(cenV2Role);
824 expected.add(cenV2Role2);
825 List<CentralV2Role> actual = externalAccessRolesServiceImpl.getRolesForApp(app.getUebKey());
826 assertEquals(expected.size(), actual.size());
830 public void getRoleFuncListTest() throws Exception {
831 EPApp app = mockApp();
832 List<EPApp> appList = new ArrayList<>();
833 final Map<String, String> appUebkeyParams = new HashMap<>();
835 appUebkeyParams.put("appKey", app.getUebKey());
836 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
837 .thenReturn(appList);
838 final Map<String, Long> params = new HashMap<>();
839 params.put(APP_ID, app.getId());
840 List<CentralV2RoleFunction> expected = new ArrayList<>();
841 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
842 expected.add(centralV2RoleFunction);
843 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(expected);
844 List<CentralV2RoleFunction> actual = externalAccessRolesServiceImpl.getRoleFuncList(app.getUebKey());
845 assertEquals(expected, actual);
849 public void getRoleInfoTest() throws Exception {
850 EPApp app = mockApp();
852 List<EPApp> appList = new ArrayList<>();
853 final Map<String, String> appUebkeyParams = new HashMap<>();
855 appUebkeyParams.put("appKey", app.getUebKey());
856 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
857 .thenReturn(appList);
858 List<EPRole> globalRoles = new ArrayList<>();
859 EPRole globalRole = new EPRole();
860 globalRole.setName("global_test");
861 globalRole.setId(2l);
862 globalRole.setActive(true);
863 globalRoles.add(globalRole);
864 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
865 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
866 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
867 mockGlobalRole.setActive(true);
868 mockGlobalRole.setAppId(app.getId());
869 mockGlobalRole.setRoleId(2l);
870 mockGlobalRole.setRoleName("global_test");
871 mockGlobalRole.setFunctionCd("test_type|test_code|*");
872 mockGlobalRole.setFunctionName("test name");
873 mockGlobalRoles.add(mockGlobalRole);
874 Map<String, Long> params = new HashMap<>();
875 params.put("roleId", 2l);
876 params.put("requestedAppId", 2l);
877 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", params, null))
878 .thenReturn(mockGlobalRoles);
879 CentralV2Role actual = externalAccessRolesServiceImpl.getRoleInfo(2l, app.getUebKey());
880 assertNotEquals(null, actual);
884 public void getPartnerRoleInfoTest() throws Exception {
885 EPApp app = mockApp();
887 List<EPApp> appList = new ArrayList<>();
888 final Map<String, String> appUebkeyParams = new HashMap<>();
890 appUebkeyParams.put("appKey", app.getUebKey());
891 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
892 .thenReturn(appList);
893 List<EPRole> applicationRoles = new ArrayList<>();
894 EPRole appRole = new EPRole();
895 appRole.setActive(true);
896 appRole.setAppId(app.getId());
897 appRole.setAppRoleId(100l);
899 appRole.setName("test");
900 applicationRoles.add(appRole);
901 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
902 getPartnerAppRoleParams.put("appRoleId", 10l);
903 getPartnerAppRoleParams.put("appId", app.getId());
904 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
905 .thenReturn(applicationRoles);
906 final Map<String, Long> params = new HashMap<>();
907 params.put("roleId", appRole.getId());
908 params.put(APP_ID, app.getId());
909 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
910 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|type_code|*", "test_name");
911 cenRoleFuncList.add(centralV2RoleFunction);
912 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
913 .thenReturn(cenRoleFuncList);
914 CentralV2Role actual = externalAccessRolesServiceImpl.getRoleInfo(10l, app.getUebKey());
915 assertNotEquals(null, actual);
919 public void saveRoleForPortalApplicationNewTest() throws Exception {
920 PowerMockito.mockStatic(EcompPortalUtils.class);
921 EPApp app = mockApp();
923 Role addRoleTest = new Role();
924 addRoleTest.setActive(true);
925 addRoleTest.setName("Test");
926 List<EPApp> appList = new ArrayList<>();
927 final Map<String, String> appUebkeyParams = new HashMap<>();
929 appUebkeyParams.put("appKey", app.getUebKey());
930 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
931 .thenReturn(appList);
932 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
933 HttpHeaders headers = new HttpHeaders();
934 JSONObject mockJsonObjectRole = new JSONObject();
935 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
936 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectRole.toString(), HttpStatus.OK);
937 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
938 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
939 final Map<String, String> epAppPortalRoleParams = new HashMap<>();
940 epAppPortalRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
941 List<EPRole> getRoleCreated = new ArrayList<>();
942 EPRole roleCreate = new EPRole();
943 roleCreate.setActive(true);
944 roleCreate.setId(10l);
945 roleCreate.setName("test");
946 getRoleCreated.add(roleCreate);
947 Mockito.when(dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, epAppPortalRoleParams, null))
948 .thenReturn(getRoleCreated);
949 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
950 ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
951 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
952 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
953 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
955 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
956 assertEquals(expected, actual);
960 public void saveRoleForPortalApplicationUpdateTest() throws Exception {
961 PowerMockito.mockStatic(EPCommonSystemProperties.class);
962 PowerMockito.mockStatic(EcompPortalUtils.class);
963 PowerMockito.mockStatic(SystemProperties.class);
964 EPApp app = mockApp();
966 Role addRoleTest = new Role();
967 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
968 RoleFunction roleFunc = new RoleFunction();
969 roleFunc.setName("Test Name");
970 roleFunc.setCode("test_type|test_instance|*");
971 RoleFunction roleFunc2 = new RoleFunction();
972 roleFunc2.setName("Test Name3");
973 roleFunc2.setCode("test_type3|test_instance3|*");
974 roleFuncSet.add(roleFunc);
975 roleFuncSet.add(roleFunc2);
976 addRoleTest.setActive(true);
977 addRoleTest.setName("Test2");
978 addRoleTest.setId(2l);
979 addRoleTest.setRoleFunctions(roleFuncSet);
980 List<EPApp> appList = new ArrayList<>();
981 final Map<String, String> appUebkeyParams = new HashMap<>();
983 appUebkeyParams.put("appKey", app.getUebKey());
984 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
985 .thenReturn(appList);
986 List<EPRole> globalRoles = new ArrayList<>();
987 EPRole globalRole = new EPRole();
988 globalRole.setName("global_test");
989 globalRole.setId(1111l);
990 globalRole.setActive(true);
991 globalRoles.add(globalRole);
992 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
993 List<EPRole> epRoleList = new ArrayList<>();
994 EPRole getEPRole = new EPRole();
995 getEPRole.setName("Test");
997 getEPRole.setActive(true);
998 epRoleList.add(getEPRole);
999 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1000 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1001 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1002 .thenReturn(epRoleList);
1003 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1004 HttpHeaders headers = new HttpHeaders();
1005 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1006 JSONObject mockJsonObjectRole = new JSONObject();
1007 JSONObject mockJsonObjectFinalRole = new JSONObject();
1008 JSONObject mockJsonObjectPerm1 = new JSONObject();
1009 JSONObject mockJsonObjectPerm2 = new JSONObject();
1010 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1011 mockJsonObjectPerm1.put("instance", "test_instance");
1012 mockJsonObjectPerm1.put("action", "*");
1013 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1014 mockJsonObjectPerm2.put("instance", "test_instance2");
1015 mockJsonObjectPerm2.put("action", "*");
1016 List<JSONObject> permsList = new ArrayList<>();
1017 permsList.add(mockJsonObjectPerm1);
1018 permsList.add(mockJsonObjectPerm2);
1019 mockJsonObjectRole.put("name", "com.test.app.Test");
1020 mockJsonObjectRole.put("perms", permsList);
1021 mockJsonObjectRole.put("description",
1022 "{\"id\":\"2\",\"name\":\"Test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
1023 List<JSONObject> roleList = new ArrayList<>();
1024 roleList.add(mockJsonObjectRole);
1025 mockJsonObjectFinalRole.put("role", roleList);
1026 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1027 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1028 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1029 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1030 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1031 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1032 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1033 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1034 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1035 final Map<String, String> params = new HashMap<>();
1036 params.put("uebKey", app.getUebKey());
1037 params.put("roleId", String.valueOf(getEPRole.getId()));
1038 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1039 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1040 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1041 bulkUploadUserRoles.setOrgUserId("guestT");
1042 bulkUploadUserRoles.setRoleName("Test2");
1043 userRolesList.add(bulkUploadUserRoles);
1044 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1045 .thenReturn(userRolesList);
1047 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1049 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1050 .thenReturn("@test.com");
1051 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1052 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1053 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1054 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1055 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1056 appRoleFuncsParams.put("appId", app.getId());
1057 appRoleFuncsParams.put("roleId", getEPRole.getId());
1059 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1060 .thenReturn(appRoleFunctionList);
1061 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1062 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1063 final Map<String, String> getAppFunctionParams = new HashMap<>();
1064 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1065 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1066 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1067 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1068 v2RoleFunction.add(v2RoleFunction1);
1069 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1070 .thenReturn(v2RoleFunction);
1071 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1072 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1073 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1074 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1075 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1076 v2RoleFunction2.add(v2RoleFunction3);
1077 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1078 .thenReturn(v2RoleFunction2);
1079 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1081 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1082 assertEquals(expected, actual);
1086 public void saveRoleExitsInDbButNotInExtAuthSystemTest() throws Exception {
1087 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1088 PowerMockito.mockStatic(EcompPortalUtils.class);
1089 PowerMockito.mockStatic(SystemProperties.class);
1090 EPApp app = mockApp();
1092 Role addRoleTest = new Role();
1093 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1094 RoleFunction roleFunc = new RoleFunction();
1095 roleFunc.setName("Test Name");
1096 roleFunc.setCode("test_type|test_instance|*");
1097 RoleFunction roleFunc2 = new RoleFunction();
1098 roleFunc2.setName("Test Name3");
1099 roleFunc2.setCode("test_type3|test_instance3|*");
1100 roleFuncSet.add(roleFunc);
1101 roleFuncSet.add(roleFunc2);
1102 addRoleTest.setActive(true);
1103 addRoleTest.setName("Test2");
1104 addRoleTest.setId(2l);
1105 addRoleTest.setRoleFunctions(roleFuncSet);
1106 List<EPApp> appList = new ArrayList<>();
1107 final Map<String, String> appUebkeyParams = new HashMap<>();
1109 appUebkeyParams.put("appKey", app.getUebKey());
1110 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1111 .thenReturn(appList);
1112 List<EPRole> globalRoles = new ArrayList<>();
1113 EPRole globalRole = new EPRole();
1114 globalRole.setName("global_test");
1115 globalRole.setId(1111l);
1116 globalRole.setActive(true);
1117 globalRoles.add(globalRole);
1118 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1119 List<EPRole> epRoleList = new ArrayList<>();
1120 EPRole getEPRole = new EPRole();
1121 getEPRole.setName("Test");
1122 getEPRole.setId(2l);
1123 getEPRole.setActive(true);
1124 epRoleList.add(getEPRole);
1125 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1126 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1127 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1128 .thenReturn(epRoleList);
1129 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1130 HttpHeaders headers = new HttpHeaders();
1131 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1132 JSONObject mockJsonObjectFinalRole = new JSONObject();
1133 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1134 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1135 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1136 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1137 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1138 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1139 final Map<String, String> params = new HashMap<>();
1140 params.put("uebKey", app.getUebKey());
1141 params.put("roleId", String.valueOf(getEPRole.getId()));
1142 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1143 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1144 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1145 bulkUploadUserRoles.setOrgUserId("guestT");
1146 bulkUploadUserRoles.setRoleName("Test2");
1147 userRolesList.add(bulkUploadUserRoles);
1148 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1149 .thenReturn(userRolesList);
1151 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1153 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1154 .thenReturn("@test.com");
1155 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1156 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1157 appRoleFuncsParams.put("appId", app.getId());
1158 appRoleFuncsParams.put("roleId", getEPRole.getId());
1160 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1161 .thenReturn(appRoleFunctionList);
1162 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1163 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1164 final Map<String, String> getAppFunctionParams = new HashMap<>();
1165 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1166 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1167 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1168 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1169 v2RoleFunction.add(v2RoleFunction1);
1170 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1171 .thenReturn(v2RoleFunction);
1172 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1173 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1174 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1175 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1176 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1177 v2RoleFunction2.add(v2RoleFunction3);
1178 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1179 .thenReturn(v2RoleFunction2);
1180 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1182 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1183 assertEquals(expected, actual);
1187 public void saveGlobalRoleForPortalApplicationUpdateTest() throws Exception {
1188 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1189 PowerMockito.mockStatic(EcompPortalUtils.class);
1190 PowerMockito.mockStatic(SystemProperties.class);
1191 EPApp app = mockApp();
1193 Role addRoleTest = new Role();
1194 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1195 RoleFunction roleFunc = new RoleFunction();
1196 roleFunc.setName("Test Name");
1197 roleFunc.setCode("test_type|test_instance|*");
1198 RoleFunction roleFunc2 = new RoleFunction();
1199 roleFunc2.setName("Test Name3");
1200 roleFunc2.setCode("test_type3|test_instance3|*");
1201 roleFuncSet.add(roleFunc);
1202 roleFuncSet.add(roleFunc2);
1203 addRoleTest.setActive(true);
1204 addRoleTest.setName("global_test2");
1205 addRoleTest.setId(1111l);
1206 addRoleTest.setRoleFunctions(roleFuncSet);
1207 List<EPApp> appList = new ArrayList<>();
1208 final Map<String, String> appUebkeyParams = new HashMap<>();
1210 appUebkeyParams.put("appKey", app.getUebKey());
1211 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1212 .thenReturn(appList);
1213 List<EPRole> globalRoles = new ArrayList<>();
1214 EPRole globalRole = new EPRole();
1215 globalRole.setName("global_test");
1216 globalRole.setId(1111l);
1217 globalRole.setActive(true);
1218 globalRoles.add(globalRole);
1219 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1220 List<EPRole> epRoleList = new ArrayList<>();
1221 EPRole getEPRole = new EPRole();
1222 getEPRole.setName("global_test");
1223 getEPRole.setId(1111l);
1224 getEPRole.setActive(true);
1225 epRoleList.add(getEPRole);
1226 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1227 getPortalAppRoleParams.put("roleId", addRoleTest.getId());
1228 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1229 .thenReturn(epRoleList);
1230 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1231 HttpHeaders headers = new HttpHeaders();
1232 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1233 JSONObject mockJsonObjectRole = new JSONObject();
1234 JSONObject mockJsonObjectFinalRole = new JSONObject();
1235 JSONObject mockJsonObjectPerm1 = new JSONObject();
1236 JSONObject mockJsonObjectPerm2 = new JSONObject();
1237 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1238 mockJsonObjectPerm1.put("instance", "test_instance");
1239 mockJsonObjectPerm1.put("action", "*");
1240 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1241 mockJsonObjectPerm2.put("instance", "test_instance2");
1242 mockJsonObjectPerm2.put("action", "*");
1243 List<JSONObject> permsList = new ArrayList<>();
1244 permsList.add(mockJsonObjectPerm1);
1245 permsList.add(mockJsonObjectPerm2);
1246 mockJsonObjectRole.put("name", "com.test.app.global_test");
1247 mockJsonObjectRole.put("perms", permsList);
1248 mockJsonObjectRole.put("description",
1249 "{\"id\":\"1111\",\"name\":\"global_test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
1250 List<JSONObject> roleList = new ArrayList<>();
1251 roleList.add(mockJsonObjectRole);
1252 mockJsonObjectFinalRole.put("role", roleList);
1253 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1254 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1255 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1256 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1257 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1258 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1259 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1260 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1261 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1262 final Map<String, String> params = new HashMap<>();
1263 params.put("uebKey", app.getUebKey());
1264 params.put("roleId", String.valueOf(getEPRole.getId()));
1265 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1266 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1267 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1268 bulkUploadUserRoles.setOrgUserId("guestT");
1269 bulkUploadUserRoles.setRoleName("Test2");
1270 userRolesList.add(bulkUploadUserRoles);
1271 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1272 .thenReturn(userRolesList);
1274 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1276 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1277 .thenReturn("@test.com");
1278 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1279 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1280 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1281 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1282 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1283 appRoleFuncsParams.put("appId", app.getId());
1284 appRoleFuncsParams.put("roleId", getEPRole.getId());
1286 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1287 .thenReturn(appRoleFunctionList);
1288 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1289 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1290 final Map<String, String> getAppFunctionParams = new HashMap<>();
1291 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1292 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1293 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1294 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1295 v2RoleFunction.add(v2RoleFunction1);
1296 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1297 .thenReturn(v2RoleFunction);
1298 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1299 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1300 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1301 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1302 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1303 v2RoleFunction2.add(v2RoleFunction3);
1304 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1305 .thenReturn(v2RoleFunction2);
1306 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1308 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1309 assertEquals(expected, actual);
1313 public void saveRoleForPartnerApplicationUpdateTest() throws Exception {
1314 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1315 PowerMockito.mockStatic(EcompPortalUtils.class);
1316 PowerMockito.mockStatic(SystemProperties.class);
1317 EPApp app = mockApp();
1319 Role addRoleTest = new Role();
1320 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1321 RoleFunction roleFunc = new RoleFunction();
1322 roleFunc.setName("Test Name");
1323 roleFunc.setCode("test_type|test_instance|*");
1324 RoleFunction roleFunc2 = new RoleFunction();
1325 roleFunc2.setName("Test Name3");
1326 roleFunc2.setCode("test_type3|test_instance3|*");
1327 roleFuncSet.add(roleFunc);
1328 roleFuncSet.add(roleFunc2);
1329 addRoleTest.setActive(false);
1330 addRoleTest.setName("Test2");
1331 addRoleTest.setId(22l);
1332 addRoleTest.setRoleFunctions(roleFuncSet);
1333 List<EPApp> appList = new ArrayList<>();
1334 final Map<String, String> appUebkeyParams = new HashMap<>();
1336 appUebkeyParams.put("appKey", app.getUebKey());
1337 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1338 .thenReturn(appList);
1339 List<EPRole> globalRoles = new ArrayList<>();
1340 EPRole globalRole = new EPRole();
1341 globalRole.setName("global_test");
1342 globalRole.setId(1111l);
1343 globalRole.setActive(true);
1344 globalRoles.add(globalRole);
1345 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1346 List<EPRole> epRoleList = new ArrayList<>();
1347 EPRole getEPRole = new EPRole();
1348 getEPRole.setName("Test2");
1349 getEPRole.setId(2l);
1350 getEPRole.setActive(true);
1351 getEPRole.setAppRoleId(22l);
1352 epRoleList.add(getEPRole);
1353 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1354 getPortalAppRoleParams.put("appRoleId", addRoleTest.getId());
1355 getPortalAppRoleParams.put("appId", app.getId());
1356 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPortalAppRoleParams, null))
1357 .thenReturn(epRoleList);
1358 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1359 HttpHeaders headers = new HttpHeaders();
1360 Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
1361 JSONObject mockJsonObjectRole = new JSONObject();
1362 JSONObject mockJsonObjectFinalRole = new JSONObject();
1363 JSONObject mockJsonObjectPerm1 = new JSONObject();
1364 JSONObject mockJsonObjectPerm2 = new JSONObject();
1365 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1366 mockJsonObjectPerm1.put("instance", "test_instance");
1367 mockJsonObjectPerm1.put("action", "*");
1368 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1369 mockJsonObjectPerm2.put("instance", "test_instance2");
1370 mockJsonObjectPerm2.put("action", "*");
1371 List<JSONObject> permsList = new ArrayList<>();
1372 permsList.add(mockJsonObjectPerm1);
1373 permsList.add(mockJsonObjectPerm2);
1374 mockJsonObjectRole.put("name", "com.test.app.Test");
1375 mockJsonObjectRole.put("perms", permsList);
1376 mockJsonObjectRole.put("description",
1377 "{\"id\":\"2\",\"name\":\"Test2\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"22\"}");
1378 List<JSONObject> roleList = new ArrayList<>();
1379 roleList.add(mockJsonObjectRole);
1380 mockJsonObjectFinalRole.put("role", roleList);
1381 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1382 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1383 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1384 ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
1385 final Map<String, String> getPartnerAppRoleParams = new HashMap<>();
1386 getPartnerAppRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
1387 getPartnerAppRoleParams.put("appId", String.valueOf(app.getId()));
1388 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1389 getPartnerAppRoleParams, null)).thenReturn(epRoleList);
1390 ResponseEntity<String> updateRoleResponse = new ResponseEntity<>(HttpStatus.OK);
1391 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
1392 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateRoleResponse);
1393 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1394 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1395 ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
1396 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1397 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
1398 final Map<String, String> params = new HashMap<>();
1399 params.put("uebKey", app.getUebKey());
1400 params.put("roleId", String.valueOf(getEPRole.getId()));
1401 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
1402 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
1403 bulkUploadUserRoles.setAppNameSpace("com.test.app");
1404 bulkUploadUserRoles.setOrgUserId("guestT");
1405 bulkUploadUserRoles.setRoleName("Test2");
1406 userRolesList.add(bulkUploadUserRoles);
1407 Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
1408 .thenReturn(userRolesList);
1410 EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1412 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
1413 .thenReturn("@test.com");
1414 ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
1415 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1416 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
1417 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1418 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1419 appRoleFuncsParams.put("appId", app.getId());
1420 appRoleFuncsParams.put("roleId", getEPRole.getId());
1422 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1423 .thenReturn(appRoleFunctionList);
1424 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1425 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1426 final Map<String, String> getAppFunctionParams = new HashMap<>();
1427 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1428 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1429 List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
1430 CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
1431 v2RoleFunction.add(v2RoleFunction1);
1432 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1433 .thenReturn(v2RoleFunction);
1434 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1435 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1436 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1437 List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
1438 CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
1439 v2RoleFunction2.add(v2RoleFunction3);
1440 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1441 .thenReturn(v2RoleFunction2);
1442 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1444 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1445 assertEquals(expected, actual);
1449 public void saveGlobalRoleFunctionsForPartnerApplicationUpdateTest() throws Exception {
1450 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1451 PowerMockito.mockStatic(EcompPortalUtils.class);
1452 PowerMockito.mockStatic(SystemProperties.class);
1453 EPApp app = mockApp();
1455 Role addRoleTest = new Role();
1456 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
1457 RoleFunction roleFunc = new RoleFunction();
1458 roleFunc.setName("Test Name");
1459 roleFunc.setCode("test_type|test_instance|*");
1460 RoleFunction roleFunc2 = new RoleFunction();
1461 roleFunc2.setName("Test Name3");
1462 roleFunc2.setCode("test_type3|test_instance3|*");
1463 roleFuncSet.add(roleFunc);
1464 roleFuncSet.add(roleFunc2);
1465 addRoleTest.setActive(true);
1466 addRoleTest.setName("global_test");
1467 addRoleTest.setId(1111l);
1468 addRoleTest.setRoleFunctions(roleFuncSet);
1469 List<EPApp> appList = new ArrayList<>();
1470 final Map<String, String> appUebkeyParams = new HashMap<>();
1472 appUebkeyParams.put("appKey", app.getUebKey());
1473 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1474 .thenReturn(appList);
1475 List<EPRole> globalRoles = new ArrayList<>();
1476 EPRole globalRole = new EPRole();
1477 globalRole.setName("global_test");
1478 globalRole.setId(1111l);
1479 globalRole.setActive(true);
1480 EPRole globalRole2 = new EPRole();
1481 globalRole2.setName("global_test2");
1482 globalRole2.setId(2222l);
1483 globalRole2.setActive(true);
1484 globalRoles.add(globalRole);
1485 globalRoles.add(globalRole2);
1486 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1487 List<EPRole> getGlobalRoles = new ArrayList<>();
1488 EPRole getEPGlobalRole = new EPRole();
1489 getEPGlobalRole.setName("global_test");
1490 getEPGlobalRole.setId(1111l);
1491 getEPGlobalRole.setActive(true);
1492 getGlobalRoles.add(getEPGlobalRole);
1493 final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
1494 getPortalAppRoleParams.put("roleId", globalRole.getId());
1495 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
1496 .thenReturn(getGlobalRoles);
1497 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1498 Mockito.when(epAppCommonServiceImpl.getApp(PortalConstants.PORTAL_APP_ID)).thenReturn(app);
1499 JSONObject mockJsonObjectPerm = new JSONObject();
1500 JSONObject mockJsonObjectPerm2 = new JSONObject();
1501 JSONObject mockJsonObjectPerm3 = new JSONObject();
1502 JSONObject mockJsonObjectPerm4 = new JSONObject();
1503 JSONObject mockJsonObjectFinalPerm = new JSONObject();
1504 mockJsonObjectPerm.put("type", "com.test.app.test_type");
1505 mockJsonObjectPerm.put("instance", "test_instance");
1506 mockJsonObjectPerm.put("action", "*");
1507 mockJsonObjectPerm.put("description", "Test Name");
1508 mockJsonObjectPerm2.put("type", "com.test.app.access");
1509 mockJsonObjectPerm2.put("instance", "test_instance2");
1510 mockJsonObjectPerm2.put("action", "*");
1511 mockJsonObjectPerm2.put("description", "Test Name2");
1512 mockJsonObjectPerm3.put("type", "com.test.app.test_type3");
1513 mockJsonObjectPerm3.put("instance", "test_instance3");
1514 mockJsonObjectPerm3.put("action", "*");
1515 mockJsonObjectPerm3.put("description", "Test Name3");
1516 mockJsonObjectPerm4.put("type", "com.test.app.test_type4");
1517 mockJsonObjectPerm4.put("instance", "test_instance4");
1518 mockJsonObjectPerm4.put("action", "*");
1519 mockJsonObjectPerm4.put("description", "Test Name4");
1520 List<JSONObject> mockJson = new ArrayList<>();
1521 mockJson.add(mockJsonObjectPerm);
1522 mockJson.add(mockJsonObjectPerm2);
1523 mockJson.add(mockJsonObjectPerm3);
1524 mockJson.add(mockJsonObjectPerm4);
1525 mockJsonObjectFinalPerm.put("perm", mockJson);
1526 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
1527 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1528 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1529 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1530 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
1531 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
1532 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
1533 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1534 final Map<String, Long> epAppRoleFuncParams = new HashMap<>();
1535 epAppRoleFuncParams.put("requestedAppId", app.getId());
1536 epAppRoleFuncParams.put("roleId", globalRole.getId());
1537 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
1538 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
1539 mockGlobalRole.setActive(true);
1540 mockGlobalRole.setAppId(app.getId());
1541 mockGlobalRole.setRoleId(1111l);
1542 mockGlobalRole.setRoleName("global_test");
1543 mockGlobalRole.setFunctionCd("test_type4|test_instance4|*");
1544 mockGlobalRole.setFunctionName("test name");
1545 mockGlobalRoles.add(mockGlobalRole);
1546 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", epAppRoleFuncParams, null))
1547 .thenReturn(mockGlobalRoles);
1548 ResponseEntity<String> delResponse = new ResponseEntity<>(HttpStatus.OK);
1549 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1550 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
1551 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1552 appRoleFuncsParams.put("appId", app.getId());
1553 appRoleFuncsParams.put("roleId", globalRole.getId());
1554 List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
1555 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
1556 epAppRoleFunction.setAppId(app.getId());
1557 epAppRoleFunction.setRoleAppId("1");
1558 epAppRoleFunction.setCode("test");
1559 epAppRoleFunction.setRoleId(1111l);
1560 appRoleFunctionList.add(epAppRoleFunction);
1562 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1563 .thenReturn(appRoleFunctionList);
1564 final Map<String, String> getAppFunctionParams = new HashMap<>();
1565 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
1566 Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
1567 Mockito.when(EcompPortalUtils.getFunctionCode("test_type4|test_instance4|*")).thenReturn("test_instance4");
1568 getAppFunctionParams.put("appId", String.valueOf(app.getId()));
1569 getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
1570 List<CentralV2RoleFunction> roleFunction = new ArrayList<>();
1571 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, roleFunc.getCode(),
1572 roleFunc.getName(), app.getId(), null);
1573 roleFunction.add(centralV2RoleFunction);
1574 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null))
1575 .thenReturn(roleFunction);
1576 final Map<String, String> getAppFunctionParams2 = new HashMap<>();
1577 getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
1578 getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
1579 List<CentralV2RoleFunction> roleFunction2 = new ArrayList<>();
1580 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, roleFunc2.getCode(),
1581 roleFunc2.getName(), app.getId(), null);
1582 roleFunction2.add(centralV2RoleFunction2);
1583 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null))
1584 .thenReturn(roleFunction2);
1585 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
1587 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1588 assertEquals(expected, actual);
1592 public void syncRoleFunctionFromExternalAccessSystemTest() {
1593 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1594 PowerMockito.mockStatic(EcompPortalUtils.class);
1595 PowerMockito.mockStatic(SystemProperties.class);
1596 EPApp app = mockApp();
1598 JSONObject mockJsonObjectFinalPerm = new JSONObject();
1599 JSONObject mockJsonObjectPerm = new JSONObject();
1600 JSONObject mockJsonObjectPerm2 = new JSONObject();
1601 JSONObject mockJsonObjectPerm3 = new JSONObject();
1602 mockJsonObjectPerm.put("type", "com.test.app.test_type");
1603 mockJsonObjectPerm.put("instance", "test_instance");
1604 mockJsonObjectPerm.put("action", "*");
1605 mockJsonObjectPerm.put("description", "test_name");
1606 List<String> rolePermList = new ArrayList<>();
1607 rolePermList.add("com.test.app|test1");
1608 mockJsonObjectPerm.put("roles", rolePermList);
1609 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1610 mockJsonObjectPerm2.put("instance", "test_instance2");
1611 List<String> rolePermList2 = new ArrayList<>();
1612 rolePermList2.add("com.test.app|test1");
1613 rolePermList2.add("com.test.app|test2");
1614 rolePermList2.add("com.test.app|test6");
1615 rolePermList2.add("com.test.app.new|global_test");
1616 mockJsonObjectPerm2.put("action", "*");
1617 mockJsonObjectPerm2.put("roles", rolePermList2);
1618 mockJsonObjectPerm2.put("description", "test_name2");
1619 mockJsonObjectPerm3.put("type", "com.test.app.access");
1620 mockJsonObjectPerm3.put("instance", "test_instance3");
1621 mockJsonObjectPerm3.put("action", "*");
1622 mockJsonObjectPerm3.put("description", "test_name3");
1623 List<JSONObject> permsList = new ArrayList<>();
1624 permsList.add(mockJsonObjectPerm);
1625 permsList.add(mockJsonObjectPerm2);
1626 permsList.add(mockJsonObjectPerm3);
1627 mockJsonObjectFinalPerm.put("perm", permsList);
1628 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
1629 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1630 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1631 final Map<String, Long> params = new HashMap<>();
1632 params.put(APP_ID, app.getId());
1633 List<CentralV2RoleFunction> appFunctions = new ArrayList<>();
1634 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*",
1635 "test_name", app.getId(), null);
1636 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_instance2", "test_name2",
1638 CentralV2RoleFunction centralV2RoleFunction3 = new CentralV2RoleFunction(null, "test_instance5", "test_name5",
1640 appFunctions.add(centralV2RoleFunction);
1641 appFunctions.add(centralV2RoleFunction2);
1642 appFunctions.add(centralV2RoleFunction3);
1643 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(appFunctions);
1644 List<EPRole> globalRoles = new ArrayList<>();
1645 EPRole globalRole = new EPRole();
1646 globalRole.setName("global_test");
1647 globalRole.setId(1111l);
1648 globalRole.setActive(true);
1649 globalRoles.add(globalRole);
1650 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
1651 List<EPRole> getCurrentRoleList = new ArrayList<>();
1652 EPRole getEPRole = new EPRole();
1653 getEPRole.setName("test1");
1654 getEPRole.setId(2l);
1655 getEPRole.setActive(true);
1656 EPRole getEPRole2 = new EPRole();
1657 getEPRole2.setName("global_test");
1658 getEPRole2.setId(1111l);
1659 getEPRole2.setActive(true);
1660 EPRole getEPRole3 = new EPRole();
1661 getEPRole3.setName("test2");
1662 getEPRole3.setId(4l);
1663 getEPRole3.setActive(true);
1664 getCurrentRoleList.add(getEPRole);
1665 getCurrentRoleList.add(getEPRole2);
1666 getCurrentRoleList.add(getEPRole3);
1667 final Map<String, Long> appParams = new HashMap<>();
1668 appParams.put("appId", app.getId());
1669 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
1670 .thenReturn(getCurrentRoleList);
1671 final Map<String, String> appSyncFuncsParams = new HashMap<>();
1672 appSyncFuncsParams.put("appId", String.valueOf(app.getId()));
1673 appSyncFuncsParams.put("functionCd", "");
1674 List<CentralV2RoleFunction> roleFunctionList = new ArrayList<>();
1675 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1676 .thenReturn(roleFunctionList);
1677 String code = centralV2RoleFunction.getCode();
1678 appSyncFuncsParams.put("functionCd", code);
1679 CentralV2RoleFunction getCentralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*",
1680 "test_name", app.getId(), null);
1681 roleFunctionList.add(getCentralV2RoleFunction);
1682 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1683 .thenReturn(roleFunctionList);
1684 List<LocalRole> localRoles = new ArrayList<>();
1685 LocalRole localRole = new LocalRole();
1686 localRole.setRoleId(2);
1687 localRole.setRolename("test1");
1688 LocalRole localRole2 = new LocalRole();
1689 localRole2.setRoleId(3);
1690 localRole2.setRolename("test3");
1691 localRoles.add(localRole);
1692 localRoles.add(localRole2);
1693 final Map<String, String> appRoleFuncParams = new HashMap<>();
1694 appRoleFuncParams.put("functionCd", "test_type2|test_instance2|*");
1695 appRoleFuncParams.put("appId", String.valueOf(app.getId()));
1696 Mockito.when(dataAccessService.executeNamedQuery("getCurrentAppRoleFunctions", appRoleFuncParams, null))
1697 .thenReturn(localRoles);
1698 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app", app.getNameSpace())).thenReturn(true);
1699 Mockito.when(EcompPortalUtils.getFunctionCode("test_type2|test_instance2|*")).thenReturn("test_instance2");
1700 appSyncFuncsParams.put("functionCd", "test_instance2");
1701 List<CentralV2RoleFunction> roleFunctionList2 = new ArrayList<>();
1702 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1703 .thenReturn(roleFunctionList2);
1704 String code2 = "test_type2|test_instance2|*";
1705 appSyncFuncsParams.put("functionCd", code2);
1706 CentralV2RoleFunction getCentralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_type2|test_instance2|*",
1707 "test_name2", app.getId(), null);
1708 roleFunctionList2.add(getCentralV2RoleFunction2);
1709 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams, null))
1710 .thenReturn(roleFunctionList2);
1711 final Map<String, Long> params3 = new HashMap<>();
1712 params3.put("appId", app.getId());
1713 params3.put("roleId", getEPRole2.getId());
1714 List<EPAppRoleFunction> currentGlobalRoleFunctionsList = new ArrayList<>();
1715 EPAppRoleFunction addGlobalRoleFunction = new EPAppRoleFunction();
1716 addGlobalRoleFunction.setAppId(app.getId());
1717 addGlobalRoleFunction.setCode("test_type|test_instance|*");
1718 addGlobalRoleFunction.setRoleId(1111l);
1719 currentGlobalRoleFunctionsList.add(addGlobalRoleFunction);
1720 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", params3, null))
1721 .thenReturn(currentGlobalRoleFunctionsList);
1722 final Map<String, String> roleParams = new HashMap<>();
1723 roleParams.put(APP_ROLE_NAME_PARAM, "test6");
1724 roleParams.put("appId", String.valueOf(app.getId()));
1725 List<EPRole> roleCreated = new ArrayList<>();
1726 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null))
1727 .thenReturn(roleCreated);
1728 final Map<String, String> getRoleByNameParams = new HashMap<>();
1729 getRoleByNameParams.put(APP_ROLE_NAME_PARAM, "test6");
1730 getRoleByNameParams.put("appId", String.valueOf(app.getId()));
1731 EPRole getNewEPRole = new EPRole();
1732 getNewEPRole.setName("test6");
1733 getNewEPRole.setId(8l);
1734 getNewEPRole.setActive(true);
1735 List<EPRole> roleCreated2 = new ArrayList<>();
1736 roleCreated2.add(getNewEPRole);
1737 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1738 getRoleByNameParams, null)).thenReturn(roleCreated2);
1739 EPRole getNewEPRoleFinal = new EPRole();
1740 getNewEPRoleFinal.setName("test6");
1741 getNewEPRoleFinal.setId(8l);
1742 getNewEPRoleFinal.setActive(true);
1743 getNewEPRoleFinal.setAppRoleId(8l);
1744 final Map<String, String> getRoleByNameParams2 = new HashMap<>();
1745 getRoleByNameParams2.put(APP_ROLE_NAME_PARAM, "test6");
1746 getRoleByNameParams2.put("appId", String.valueOf(app.getId()));
1747 List<EPRole> roleCreated3 = new ArrayList<>();
1748 roleCreated3.add(getNewEPRole);
1749 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM,
1750 getRoleByNameParams2, null)).thenReturn(roleCreated3);
1751 List<EPRole> roleInfo = new ArrayList<>();
1752 roleInfo.add(getNewEPRoleFinal);
1753 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1754 getPartnerAppRoleParams.put("appRoleId", getNewEPRoleFinal.getId());
1755 getPartnerAppRoleParams.put("appId", app.getId());
1756 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
1757 .thenReturn(roleInfo);
1758 externalAccessRolesServiceImpl.syncRoleFunctionFromExternalAccessSystem(app);
1762 public void syncApplicationRolesWithEcompDBTest() {
1763 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1764 PowerMockito.mockStatic(EcompPortalUtils.class);
1765 PowerMockito.mockStatic(SystemProperties.class);
1766 EPApp app = mockApp();
1768 JSONObject mockJsonObjectRole = new JSONObject();
1769 JSONObject mockJsonObjectRole2 = new JSONObject();
1770 JSONObject mockJsonObjectFinalRole = new JSONObject();
1771 JSONObject mockJsonObjectPerm1 = new JSONObject();
1772 JSONObject mockJsonObjectPerm2 = new JSONObject();
1773 mockJsonObjectPerm1.put("type", "com.test.app.test_type");
1774 mockJsonObjectPerm1.put("instance", "test_instance");
1775 mockJsonObjectPerm1.put("action", "*");
1776 mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
1777 mockJsonObjectPerm2.put("instance", "test_instance2");
1778 mockJsonObjectPerm2.put("action", "*");
1779 List<JSONObject> permsList = new ArrayList<>();
1780 permsList.add(mockJsonObjectPerm1);
1781 permsList.add(mockJsonObjectPerm2);
1782 mockJsonObjectRole.put("name", "com.test.app.Test");
1783 mockJsonObjectRole.put("perms", permsList);
1784 mockJsonObjectRole.put("description",
1785 "{\"id\":\"2\",\"name\":\"test1\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"2\"}");
1786 mockJsonObjectRole2.put("name", "com.test.app.Test2");
1787 List<JSONObject> permsList2 = new ArrayList<>();
1788 permsList2.add(mockJsonObjectPerm1);
1789 mockJsonObjectRole2.put("perms", permsList2);
1790 List<JSONObject> roleList = new ArrayList<>();
1791 roleList.add(mockJsonObjectRole);
1792 roleList.add(mockJsonObjectRole2);
1793 mockJsonObjectFinalRole.put("role", roleList);
1794 ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
1795 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1796 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1797 List<EPRole> getCurrentRoleList = new ArrayList<>();
1798 EPRole getEPRole = new EPRole();
1799 getEPRole.setName("Test");
1800 getEPRole.setId(2l);
1801 getEPRole.setAppId(app.getId());
1802 getEPRole.setAppRoleId(2l);
1803 getEPRole.setActive(true);
1804 EPRole getEPRole2 = new EPRole();
1805 getEPRole2.setName("Test3");
1806 getEPRole2.setId(3l);
1807 getEPRole.setAppId(app.getId());
1808 getEPRole.setAppRoleId(3l);
1809 getEPRole2.setActive(true);
1810 getCurrentRoleList.add(getEPRole);
1811 getCurrentRoleList.add(getEPRole2);
1812 final Map<String, Long> appParams = new HashMap<>();
1813 appParams.put("appId", app.getId());
1814 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
1815 .thenReturn(getCurrentRoleList);
1816 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type", app.getNameSpace()))
1818 Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type2", app.getNameSpace()))
1820 List<EPAppRoleFunction> appRoleFunctions = new ArrayList<>();
1821 EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
1822 epAppRoleFunction.setAppId(app.getId());
1823 epAppRoleFunction.setCode("test_type|test_instance|*");
1824 epAppRoleFunction.setRoleId(getEPRole.getId());
1825 appRoleFunctions.add(epAppRoleFunction);
1826 final Map<String, Long> appRoleFuncsParams = new HashMap<>();
1827 appRoleFuncsParams.put("appId", app.getId());
1828 appRoleFuncsParams.put("roleId", Long.valueOf(getEPRole.getId()));
1830 dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null))
1831 .thenReturn(appRoleFunctions);
1832 List<CentralV2RoleFunction> getV2RoleFunction = new ArrayList<>();
1833 final Map<String, String> appFuncsParams = new HashMap<>();
1834 appFuncsParams.put("appId", String.valueOf(app.getId()));
1835 appFuncsParams.put("functionCd", "test_instance2");
1836 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null))
1837 .thenReturn(getV2RoleFunction);
1838 appFuncsParams.put("functionCd", "test_type2|test_instance2|*");
1839 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
1840 centralV2RoleFunction.setAppId(app.getId());
1841 centralV2RoleFunction.setCode("test_type2|test_instance2|*");
1842 centralV2RoleFunction.setName("test_name2");
1843 getV2RoleFunction.add(centralV2RoleFunction);
1844 final Map<String, String> extRoleParams = new HashMap<>();
1845 List<EPRole> roleListDeactivate = new ArrayList<>();
1846 extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3");
1847 extRoleParams.put(APP_ID, app.getId().toString());
1848 EPRole getEPRoleDeactivate = new EPRole();
1849 getEPRoleDeactivate.setName("Test3");
1850 getEPRoleDeactivate.setId(3l);
1851 getEPRoleDeactivate.setAppId(app.getId());
1852 getEPRoleDeactivate.setAppRoleId(3l);
1853 roleListDeactivate.add(getEPRoleDeactivate);
1855 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, extRoleParams, null))
1856 .thenReturn(roleListDeactivate);
1857 Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null))
1858 .thenReturn(getV2RoleFunction);
1859 List<EPRole> updateLocalFromExtAuth = new ArrayList<>();
1860 updateLocalFromExtAuth.add(getEPRole);
1861 final Map<String, String> roleParams = new HashMap<>();
1862 roleParams.put(APP_ROLE_NAME_PARAM, getEPRole.getName());
1863 roleParams.put(APP_ID, app.getId().toString());
1864 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null))
1865 .thenReturn(updateLocalFromExtAuth);
1866 roleParams.put(APP_ROLE_NAME_PARAM, getEPRole2.getName());
1867 List<EPRole> updateLocalFromExtAuth2 = new ArrayList<>();
1868 updateLocalFromExtAuth.add(getEPRole);
1869 Mockito.when(dataAccessService.executeNamedQuery("getRoletoUpdateInExternalAuthSystem", roleParams, null))
1870 .thenReturn(updateLocalFromExtAuth2);
1871 final Map<String, String> globalRoleParams = new HashMap<>();
1872 globalRoleParams.put("appId", String.valueOf(app.getId()));
1873 globalRoleParams.put("appRoleName", "Test2");
1874 List<EPRole> addNewRoleList = new ArrayList<>();
1875 EPRole addRoleInLocal = new EPRole();
1876 addRoleInLocal.setName("Test2");
1877 addRoleInLocal.setId(4l);
1878 addRoleInLocal.setAppId(app.getId());
1879 addRoleInLocal.setActive(true);
1880 addNewRoleList.add(addRoleInLocal);
1882 dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, globalRoleParams, null))
1883 .thenReturn(addNewRoleList);
1884 final Map<String, String> params = new HashMap<>();
1885 params.put(APP_ROLE_NAME_PARAM, "Test2");
1886 params.put(APP_ID, app.getId().toString());
1887 addRoleInLocal.setAppRoleId(4l);
1888 addNewRoleList.add(addRoleInLocal);
1889 Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, params, null))
1890 .thenReturn(addNewRoleList);
1891 externalAccessRolesServiceImpl.syncApplicationRolesWithEcompDB(app);
1895 public void deleteDependencyRoleRecord() throws Exception {
1896 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1897 PowerMockito.mockStatic(EcompPortalUtils.class);
1898 PowerMockito.mockStatic(SystemProperties.class);
1899 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
1900 EPApp app = mockApp();
1902 EPUser user = mockUser.mockEPUser();
1903 List<EPApp> appList = new ArrayList<>();
1904 final Map<String, String> appUebkeyParams = new HashMap<>();
1906 appUebkeyParams.put("appKey", app.getUebKey());
1907 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1908 .thenReturn(appList);
1909 List<EPRole> epRoleList = new ArrayList<>();
1910 EPRole getEPRole = new EPRole();
1911 getEPRole.setName("Test");
1912 getEPRole.setId(2l);
1913 getEPRole.setAppRoleId(2l);
1914 getEPRole.setActive(true);
1915 epRoleList.add(getEPRole);
1916 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1917 getPartnerAppRoleParams.put("appRoleId", getEPRole.getId());
1918 getPartnerAppRoleParams.put("appId", app.getId());
1919 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
1920 .thenReturn(epRoleList);
1921 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1922 JSONObject getUser = new JSONObject();
1923 getUser.put("name", "com.test.app.test1");
1924 ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
1925 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1926 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1927 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
1928 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1929 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
1930 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
1931 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l,
1932 app.getUebKey(), user.getOrgUserId());
1933 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1934 assertEquals(expected, actual);
1938 public void deleteDependencyRoleRecordForPortal() throws Exception {
1939 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1940 PowerMockito.mockStatic(EcompPortalUtils.class);
1941 PowerMockito.mockStatic(SystemProperties.class);
1942 SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
1943 EPApp app = mockApp();
1945 EPUser user = mockUser.mockEPUser();
1946 List<EPApp> appList = new ArrayList<>();
1947 final Map<String, String> appUebkeyParams = new HashMap<>();
1949 appUebkeyParams.put("appKey", app.getUebKey());
1950 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1951 .thenReturn(appList);
1952 List<EPRole> epRoleList = new ArrayList<>();
1953 EPRole getEPRole = new EPRole();
1954 getEPRole.setName("Test");
1955 getEPRole.setId(2l);
1956 getEPRole.setAppRoleId(2l);
1957 getEPRole.setActive(true);
1958 epRoleList.add(getEPRole);
1959 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
1960 getPartnerAppRoleParams.put("roleId", getEPRole.getId());
1961 Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPartnerAppRoleParams, null))
1962 .thenReturn(epRoleList);
1963 Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
1964 JSONObject getUser = new JSONObject();
1965 getUser.put("name", "com.test.app.test1");
1966 ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
1967 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
1968 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
1969 ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
1970 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
1971 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
1972 Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
1973 ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l,
1974 app.getUebKey(), user.getOrgUserId());
1975 ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
1976 assertEquals(expected, actual);
1980 public void bulkUploadFunctionsTest() throws Exception {
1981 PowerMockito.mockStatic(EPCommonSystemProperties.class);
1982 PowerMockito.mockStatic(EcompPortalUtils.class);
1983 PowerMockito.mockStatic(SystemProperties.class);
1984 EPApp app = mockApp();
1986 List<EPApp> appList = new ArrayList<>();
1987 final Map<String, String> appUebkeyParams = new HashMap<>();
1989 appUebkeyParams.put("appKey", app.getUebKey());
1990 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
1991 .thenReturn(appList);
1992 List<RoleFunction> roleFuncList = new ArrayList<>();
1993 RoleFunction roleFunc = new RoleFunction();
1994 roleFunc.setCode("test_code");
1995 roleFunc.setName("test_name");
1996 RoleFunction roleFunc2 = new RoleFunction();
1997 roleFunc2.setCode("test_code2");
1998 roleFunc2.setName("test_name2");
1999 roleFuncList.add(roleFunc);
2000 roleFuncList.add(roleFunc2);
2001 Mockito.when(dataAccessService.executeNamedQuery("getAllFunctions", null, null)).thenReturn(roleFuncList);
2002 JSONObject perm = new JSONObject();
2003 JSONObject permList = new JSONObject();
2004 perm.put("type", app.getNameSpace() + ".access");
2005 perm.put("instance", "type_instance");
2006 perm.put("action", "*");
2007 List<JSONObject> addPerms = new ArrayList<>();
2009 permList.put("perm", addPerms);
2010 ResponseEntity<String> getResponse = new ResponseEntity<>(permList.toString(), HttpStatus.OK);
2011 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
2012 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2013 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2014 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2015 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2016 Integer actual = externalAccessRolesServiceImpl.bulkUploadFunctions(app.getUebKey());
2017 Integer expected = 2;
2018 assertEquals(expected, actual);
2022 public void bulkUploadRolesTest() throws Exception {
2023 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2024 PowerMockito.mockStatic(EcompPortalUtils.class);
2025 PowerMockito.mockStatic(SystemProperties.class);
2026 EPApp app = mockApp();
2028 List<EPApp> appList = new ArrayList<>();
2029 final Map<String, String> appUebkeyParams = new HashMap<>();
2031 appUebkeyParams.put("appKey", app.getUebKey());
2032 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2033 .thenReturn(appList);
2034 List<EPRole> epRoleList = new ArrayList<>();
2035 EPRole getEPRole = new EPRole();
2036 getEPRole.setName("Test");
2037 getEPRole.setId(2l);
2038 getEPRole.setAppRoleId(2l);
2039 getEPRole.setActive(true);
2040 EPRole getEPRole2 = new EPRole();
2041 getEPRole2.setName("Test2");
2042 getEPRole2.setId(3l);
2043 getEPRole2.setAppRoleId(3l);
2044 getEPRole2.setActive(true);
2045 epRoleList.add(getEPRole);
2046 epRoleList.add(getEPRole2);
2047 final Map<String, Long> appParams = new HashMap<>();
2048 appParams.put("appId", app.getId());
2049 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
2050 .thenReturn(epRoleList);
2051 List<EPRole> epRoleList1 = new ArrayList<>();
2052 EPRole ePRole = new EPRole();
2053 ePRole.setName("Test");
2055 ePRole.setAppRoleId(2l);
2056 ePRole.setActive(true);
2057 epRoleList1.add(ePRole);
2058 final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
2059 getPartnerAppRoleParams.put("appRoleId", ePRole.getId());
2060 getPartnerAppRoleParams.put("appId", app.getId());
2061 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
2062 .thenReturn(epRoleList1);
2063 List<EPRole> epRoleList2 = new ArrayList<>();
2064 EPRole ePRole2 = new EPRole();
2065 ePRole2.setName("Test2");
2067 ePRole2.setAppRoleId(3l);
2068 ePRole2.setActive(true);
2069 epRoleList2.add(ePRole2);
2070 final Map<String, Long> getPartnerAppRoleParams2 = new HashMap<>();
2071 getPartnerAppRoleParams2.put("appRoleId", ePRole2.getId());
2072 getPartnerAppRoleParams2.put("appId", app.getId());
2073 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams2, null))
2074 .thenReturn(epRoleList2);
2075 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2076 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2077 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2078 Integer actual = externalAccessRolesServiceImpl.bulkUploadRoles(app.getUebKey());
2079 Integer expected = 2;
2080 assertEquals(expected, actual);
2084 public void bulkUploadUserRolesTest() throws Exception {
2085 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2086 PowerMockito.mockStatic(EcompPortalUtils.class);
2087 PowerMockito.mockStatic(SystemProperties.class);
2088 EPApp app = mockApp();
2090 EPUser user = mockUser.mockEPUser();
2091 List<EPApp> appList = new ArrayList<>();
2092 final Map<String, String> appUebkeyParams = new HashMap<>();
2094 appUebkeyParams.put("appKey", app.getUebKey());
2095 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2096 .thenReturn(appList);
2097 List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
2098 BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
2099 bulkUploadUserRoles.setAppNameSpace(app.getName());
2100 bulkUploadUserRoles.setOrgUserId(user.getOrgUserId());
2101 bulkUploadUserRoles.setRoleName("Test1");
2102 BulkUploadUserRoles bulkUploadUserRoles2 = new BulkUploadUserRoles();
2103 bulkUploadUserRoles2.setAppNameSpace(app.getName());
2104 bulkUploadUserRoles2.setOrgUserId(user.getOrgUserId());
2105 bulkUploadUserRoles2.setRoleName("Test2");
2106 userRolesList.add(bulkUploadUserRoles);
2107 userRolesList.add(bulkUploadUserRoles2);
2108 final Map<String, String> appParams = new HashMap<>();
2109 appParams.put("uebKey", app.getUebKey());
2110 Mockito.when(dataAccessService.executeNamedQuery("getBulkUserRoles", appParams, null))
2111 .thenReturn(userRolesList);
2112 ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
2113 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2114 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
2115 Integer actual = externalAccessRolesServiceImpl.bulkUploadUserRoles(app.getUebKey());
2116 Integer expected = 2;
2117 assertEquals(expected, actual);
2121 public void getUserRolesTest() throws Exception {
2122 EPApp app = mockApp();
2123 EPUser user = mockUser.mockEPUser();
2124 List<EPApp> appList = new ArrayList<>();
2125 final Map<String, String> appUebkeyParams = new HashMap<>();
2127 appUebkeyParams.put("appKey", app.getUebKey());
2128 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2129 .thenReturn(appList);
2130 final Map<String, String> userParams = new HashMap<>();
2131 userParams.put("org_user_id", user.getOrgUserId());
2132 List<EPUser> userList = new ArrayList<>();
2133 Set<EPUserApp> userAppSet = user.getEPUserApps();
2134 EPUserApp epUserApp = new EPUserApp();
2135 EPRole epRole = new EPRole();
2136 epRole.setName("test");
2138 epRole.setActive(true);
2139 epRole.setAppRoleId(11l);
2140 epUserApp.setApp(app);
2141 epUserApp.setUserId(user.getId());
2142 epUserApp.setRole(epRole);
2143 userAppSet.add(epUserApp);
2144 user.setUserApps(userAppSet);
2146 Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
2147 .thenReturn(userList);
2148 CentralUser actual = externalAccessRolesServiceImpl.getUserRoles(user.getOrgUserId(), app.getUebKey());
2149 assertNotNull(actual);
2152 @SuppressWarnings("unchecked")
2154 public void getActiveRolesTest() throws Exception {
2155 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2156 PowerMockito.mockStatic(EcompPortalUtils.class);
2157 PowerMockito.mockStatic(SystemProperties.class);
2158 PowerMockito.mockStatic(EPUserUtils.class);
2159 PowerMockito.mockStatic(Restrictions.class);
2160 PowerMockito.mockStatic(Criterion.class);
2161 EPApp app = mockApp();
2163 List<EPApp> appList = new ArrayList<>();
2164 final Map<String, String> appUebkeyParams = new HashMap<>();
2166 appUebkeyParams.put("appKey", app.getUebKey());
2167 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2168 .thenReturn(appList);
2169 List<EPRole> epRoles = new ArrayList<>();
2170 EPRole getEPRole = new EPRole();
2171 getEPRole.setName("Test");
2172 getEPRole.setId(2l);
2173 getEPRole.setActive(true);
2174 EPRole getEPRole2 = new EPRole();
2175 getEPRole2.setName("Test2");
2176 getEPRole2.setId(3l);
2177 getEPRole2.setActive(true);
2178 epRoles.add(getEPRole);
2179 epRoles.add(getEPRole2);
2180 List<Criterion> restrictionsList = new ArrayList<Criterion>();
2181 Criterion active_ynCrt = Restrictions.eq("active", Boolean.TRUE);
2182 Criterion appIdCrt = Restrictions.isNull("appId");
2183 Criterion andCrit = Restrictions.and(active_ynCrt, appIdCrt);
2184 restrictionsList.add(andCrit);
2185 Mockito.when((List<EPRole>) dataAccessService.getList(EPRole.class, null, restrictionsList, null))
2186 .thenReturn(epRoles);
2187 final Map<String, Long> params = new HashMap<>();
2188 params.put("roleId", getEPRole.getId());
2189 params.put(APP_ID, app.getId());
2190 List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
2191 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction("test_type|test_instance|*",
2193 CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction("test_instance2", "test_name2");
2194 cenRoleFuncList.add(centralV2RoleFunction);
2195 cenRoleFuncList.add(centralV2RoleFunction2);
2196 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
2197 .thenReturn(cenRoleFuncList);
2198 final Map<String, Long> params2 = new HashMap<>();
2199 params2.put("roleId", getEPRole2.getId());
2200 params2.put(APP_ID, app.getId());
2201 Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params2, null))
2202 .thenReturn(cenRoleFuncList);
2203 List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
2204 GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
2205 mockGlobalRole.setActive(true);
2206 mockGlobalRole.setAppId(app.getId());
2207 mockGlobalRole.setRoleId(1111l);
2208 mockGlobalRole.setRoleName("global_test");
2209 mockGlobalRole.setFunctionCd("test_type|test_code|*");
2210 mockGlobalRole.setFunctionName("test name");
2211 mockGlobalRoles.add(mockGlobalRole);
2212 Map<String, Long> params3 = new HashMap<>();
2213 params3.put("appId", app.getId());
2214 Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params3, null))
2215 .thenReturn(mockGlobalRoles);
2216 Mockito.when(EcompPortalUtils.getFunctionCode(centralV2RoleFunction.getCode())).thenReturn("test_instance");
2217 Mockito.when(EcompPortalUtils.getFunctionCode(centralV2RoleFunction2.getCode())).thenReturn("test_instance2");
2218 List<CentralV2Role> actual = externalAccessRolesServiceImpl.getActiveRoles(app.getUebKey());
2219 assertEquals(actual.size(), 3);
2223 public void bulkUploadRolesFunctionsTest() throws Exception {
2224 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2225 PowerMockito.mockStatic(EcompPortalUtils.class);
2226 PowerMockito.mockStatic(SystemProperties.class);
2227 EPApp app = mockApp();
2228 List<EPApp> appList = new ArrayList<>();
2229 final Map<String, String> appUebkeyParams = new HashMap<>();
2231 appUebkeyParams.put("appKey", app.getUebKey());
2232 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2233 .thenReturn(appList);
2234 List<EPRole> applicationRoles = new ArrayList<>();
2235 EPRole getEPRole = new EPRole();
2236 getEPRole.setName("Test");
2237 getEPRole.setId(2l);
2238 getEPRole.setActive(true);
2239 EPRole getEPRole2 = new EPRole();
2240 getEPRole2.setName("Test2");
2241 getEPRole2.setId(3l);
2242 getEPRole2.setActive(true);
2243 applicationRoles.add(getEPRole);
2244 applicationRoles.add(getEPRole2);
2245 final Map<String, Long> appParams = new HashMap<>();
2246 appParams.put("appId", app.getId());
2247 Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
2248 .thenReturn(applicationRoles);
2249 final Map<String, Long> params = new HashMap<>();
2250 params.put("roleId", getEPRole.getId());
2251 List<BulkUploadRoleFunction> appRoleFunc = new ArrayList<>();
2252 BulkUploadRoleFunction bulkUploadRoleFunction = new BulkUploadRoleFunction();
2253 bulkUploadRoleFunction.setFunctionCd("testcode");
2254 bulkUploadRoleFunction.setFunctionName("test_name");
2255 BulkUploadRoleFunction bulkUploadRoleFunction2 = new BulkUploadRoleFunction();
2256 bulkUploadRoleFunction2.setFunctionCd("menu_testcode2");
2257 bulkUploadRoleFunction2.setFunctionName("test_name2");
2258 appRoleFunc.add(bulkUploadRoleFunction);
2259 appRoleFunc.add(bulkUploadRoleFunction2);
2260 Mockito.when(dataAccessService.executeNamedQuery("uploadAllRoleFunctions", params, null))
2261 .thenReturn(appRoleFunc);
2262 final Map<String, Long> params2 = new HashMap<>();
2263 params2.put("roleId", getEPRole2.getId());
2264 List<BulkUploadRoleFunction> appRoleFunc2 = new ArrayList<>();
2265 appRoleFunc2.add(bulkUploadRoleFunction);
2266 appRoleFunc2.add(bulkUploadRoleFunction2);
2267 Mockito.when(dataAccessService.executeNamedQuery("uploadAllRoleFunctions", params2, null))
2268 .thenReturn(appRoleFunc2);
2269 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.CREATED);
2270 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
2271 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2272 Integer actual = externalAccessRolesServiceImpl.bulkUploadRolesFunctions(app.getUebKey());
2273 Integer expected = 4;
2274 assertEquals(actual, expected);
2278 public void bulkUploadPartnerRoleFunctionsTest() throws Exception {
2279 PowerMockito.mockStatic(EPCommonSystemProperties.class);
2280 PowerMockito.mockStatic(EcompPortalUtils.class);
2281 PowerMockito.mockStatic(SystemProperties.class);
2282 EPApp app = mockApp();
2283 List<EPApp> appList = new ArrayList<>();
2284 final Map<String, String> appUebkeyParams = new HashMap<>();
2286 appUebkeyParams.put("appKey", app.getUebKey());
2287 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2288 .thenReturn(appList);
2289 List<Role> roles = new ArrayList<>();
2290 Role role = new Role();
2291 role.setName("Test");
2293 role.setActive(true);
2294 Role role2 = new Role();
2295 role2.setName("Test2");
2297 role2.setActive(true);
2300 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
2301 RoleFunction roleFunc = new RoleFunction();
2302 roleFunc.setName("Test Name");
2303 roleFunc.setCode("testcode");
2304 RoleFunction roleFunc2 = new RoleFunction();
2305 roleFunc2.setName("Test Name3");
2306 roleFunc2.setCode("menu_testcode2");
2307 roleFuncSet.add(roleFunc);
2308 roleFuncSet.add(roleFunc2);
2309 role.setRoleFunctions(roleFuncSet);
2310 role2.setRoleFunctions(roleFuncSet);
2311 ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
2312 Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
2313 Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
2314 externalAccessRolesServiceImpl.bulkUploadPartnerRoleFunctions(app.getUebKey(), roles);
2318 public void getMenuFunctionsListTest() throws Exception {
2319 EPApp app = mockApp();
2320 List<EPApp> appList = new ArrayList<>();
2321 final Map<String, String> appUebkeyParams = new HashMap<>();
2323 appUebkeyParams.put("appKey", app.getUebKey());
2324 Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
2325 .thenReturn(appList);
2326 final Map<String, Long> appParams = new HashMap<>();
2327 appParams.put(APP_ID, app.getId());
2328 List<String> expected = new ArrayList<>();
2329 expected.add("test_menu1");
2330 expected.add("test_menu2");
2331 Mockito.when(dataAccessService.executeNamedQuery("getMenuFunctions", appParams, null)).thenReturn(expected);
2332 List<String> actual = externalAccessRolesServiceImpl.getMenuFunctionsList(app.getUebKey());
2333 assertEquals(expected, actual);
2337 public void getCentralizedAppsOfUserTest() {
2338 EPUser user = mockUser.mockEPUser();
2339 Map<String, String> params = new HashMap<>();
2340 params.put("userId", user.getOrgUserId());
2341 List<CentralizedApp> expected = new ArrayList<>();
2342 CentralizedApp centralizedApp = new CentralizedApp();
2343 centralizedApp.setAppId(2);
2344 centralizedApp.setAppName("testapp1");
2345 expected.add(centralizedApp);
2346 Mockito.when(dataAccessService.executeNamedQuery("getCentralizedAppsOfUser", params, null))
2347 .thenReturn(expected);
2348 List<CentralizedApp> actual = externalAccessRolesServiceImpl.getCentralizedAppsOfUser(user.getOrgUserId());
2349 assertEquals(expected, actual);
2353 public void ConvertCentralRoleToRoleTest() throws Exception {
2354 ObjectMapper mapper = new ObjectMapper();
2355 Role role = new Role();
2356 role.setName("Test");
2358 role.setActive(true);
2359 SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
2360 RoleFunction roleFunc = new RoleFunction();
2361 roleFunc.setName("Test Name");
2362 roleFunc.setCode("testcode");
2363 RoleFunction roleFunc2 = new RoleFunction();
2364 roleFunc2.setName("Test Name3");
2365 roleFunc2.setCode("menu_testcode2");
2366 roleFuncSet.add(roleFunc);
2367 roleFuncSet.add(roleFunc2);
2368 role.setRoleFunctions(roleFuncSet);
2369 String roleInfo = mapper.writeValueAsString(role);
2370 Role actual = externalAccessRolesServiceImpl.ConvertCentralRoleToRole(roleInfo);
2371 assertNotNull(actual);
2375 public void convertV2CentralRoleListToOldVerisonCentralRoleListTest() {
2376 List<CentralV2Role> v2CenRoleList = new ArrayList<>();
2377 CentralV2Role cenV2Role = new CentralV2Role(2l, "test1");
2378 CentralV2RoleFunction CentralV2Role = new CentralV2RoleFunction("testcode", "test_name");
2379 SortedSet<CentralV2RoleFunction> setV2RoleFuncs = new TreeSet<>();
2380 setV2RoleFuncs.add(CentralV2Role);
2381 cenV2Role.setRoleFunctions(setV2RoleFuncs);
2382 v2CenRoleList.add(cenV2Role);
2383 List<CentralRole> actual = externalAccessRolesServiceImpl.convertV2CentralRoleListToOldVerisonCentralRoleList(v2CenRoleList);
2384 assertEquals(1, actual.size());