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