+
+ @Test
+ public void bulkUploadRoleFuncTest() throws Exception {
+ EPApp app = mockApp();
+ UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
+ data.setRoleName("test");
+ data.setType("test");
+ data.setInstance("test");
+ data.setIsGlobalRolePartnerFunc(false);
+ data.setAction("test");
+ data.setName("test");
+ ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ externalAccessRolesServiceImpl.bulkUploadRoleFunc(data, app);
+ }
+
+ @Test
+ public void bulkUploadGlobalRoleFuncTest() throws Exception {
+ EPApp app = mockApp();
+ EPApp portalApp = mockApp();
+ portalApp.setId(1L);
+ Mockito.when(epAppCommonServiceImpl.getApp(PortalConstants.PORTAL_APP_ID)).thenReturn(portalApp);
+ UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
+ data.setRoleName("test");
+ data.setType("test");
+ data.setInstance("test");
+ data.setIsGlobalRolePartnerFunc(true);
+ data.setAction("test");
+ data.setName("test");
+ ResponseEntity<String> getResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ externalAccessRolesServiceImpl.bulkUploadRoleFunc(data, app);
+ }
+
+ @Test(expected = HttpClientErrorException.class)
+ public void bulkUploadRoleFuncExcpetionTest() throws Exception {
+ UploadRoleFunctionExtSystem data = new UploadRoleFunctionExtSystem();
+ data.setRoleName("test");
+ data.setType("test");
+ data.setInstance("test");
+ data.setAction("test");
+ data.setName("test");
+ data.setInstance("test");
+ EPApp app = mockApp();
+ Mockito.doThrow(new HttpClientErrorException(HttpStatus.CONFLICT)).when(template).exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class));
+ externalAccessRolesServiceImpl.bulkUploadRoleFunc(data, app);
+ }
+
+ @Test
+ public void syncApplicationUserRolesFromExtAuthSystemTest() throws Exception {
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(new HttpHeaders());
+ Mockito.when(EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN)).thenReturn(true);
+ JSONObject mockJsonObjectRole = new JSONObject();
+ JSONObject mockJsonObjectRole2 = new JSONObject();
+ JSONObject mockJsonObjectRole3 = new JSONObject();
+ mockJsonObjectRole.put("name", "com.test.app.test_role");
+ mockJsonObjectRole2.put("name", "com.test.app2.test_role");
+ mockJsonObjectRole3.put("name", "com.test.app2.Account_Administrator");
+ List<JSONObject> userRolesList = new ArrayList<>();
+ JSONObject mockJsonObjectFinalUserRole = new JSONObject();
+ userRolesList.add(mockJsonObjectRole);
+ userRolesList.add(mockJsonObjectRole2);
+ userRolesList.add(mockJsonObjectRole3);
+ mockJsonObjectFinalUserRole.put("role", userRolesList);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(),HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ List<EPUser> users = new ArrayList<>();
+ EPUser user = mockUser.mockEPUser();
+ user.setOrgUserId("test");
+ users.add(user);
+ List<EPApp> apps = new ArrayList<>();
+ EPApp app = mockApp();
+ app.setNameSpace("com.test.app");
+ app.setId(1l);
+ EPApp app2 = mockApp();
+ app2.setNameSpace("com.test.app2");
+ app2.setId(2l);
+ apps.add(app);
+ apps.add(app2);
+ Mockito.when(dataAccessService
+ .executeNamedQuery("getCentralizedApps", null, null)).thenReturn(apps);
+ HashMap<String, String> userParams = new HashMap<>();
+ userParams.put("org_user_id", "test");
+ Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null)).thenReturn(users);
+ List<CentralizedAppRoles> currentUserAppRoles = new ArrayList<>();
+ CentralizedAppRoles currentUserAppRole = new CentralizedAppRoles();
+ currentUserAppRole.setAppId(1l);
+ currentUserAppRole.setAppNameSpace("com.test.app");
+ currentUserAppRole.setRoleId(2l);
+ currentUserAppRole.setRoleName("test role");
+ currentUserAppRoles.add(currentUserAppRole);
+ HashMap<String, String> userParams2 = new HashMap<>();
+ userParams2.put("orgUserId", user.getOrgUserId());
+ Mockito.when(dataAccessService
+ .executeNamedQuery("getUserCentralizedAppRoles", userParams2, null)).thenReturn(currentUserAppRoles);
+ List<CentralizedAppRoles> centralizedAppRoles = new ArrayList<>();
+ CentralizedAppRoles centralizedAppRole = new CentralizedAppRoles();
+ centralizedAppRole.setAppId(1l);
+ centralizedAppRole.setAppNameSpace("com.test.app");
+ centralizedAppRole.setRoleId(2l);
+ centralizedAppRole.setRoleName("test role");
+ CentralizedAppRoles centralizedAppRole2 = new CentralizedAppRoles();
+ centralizedAppRole2.setAppId(1l);
+ centralizedAppRole2.setAppNameSpace("com.test.app2");
+ centralizedAppRole2.setRoleId(2l);
+ centralizedAppRole2.setRoleName("test role");
+ centralizedAppRoles.add(centralizedAppRole);
+ centralizedAppRoles.add(centralizedAppRole2);
+ Mockito.when(dataAccessService
+ .executeNamedQuery("getAllCentralizedAppsRoles", null, null)).thenReturn(centralizedAppRoles);
+ externalAccessRolesServiceImpl.syncApplicationUserRolesFromExtAuthSystem(user.getOrgUserId());
+ }
+
+ @Test
+ public void updateAppRoleDescriptionTest() {
+ EPApp app = mockUpdateAppRoleDescription();
+ ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
+ Integer actual = externalAccessRolesServiceImpl.updateAppRoleDescription(app.getUebKey());
+ Integer expected = 1;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateAppRoleDescriptionExceptionTest() {
+ EPApp app = mockUpdateAppRoleDescription();
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_ACCEPTABLE));
+ Integer actual = externalAccessRolesServiceImpl.updateAppRoleDescription(app.getUebKey());
+ Integer expected = 0;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateAppRoleDescriptionExceptionTest2() throws Exception {
+ EPApp app = mockUpdateAppRoleDescription();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenThrow(new NullPointerException());
+ Integer actual = externalAccessRolesServiceImpl.updateAppRoleDescription(app.getUebKey());
+ Integer expected = 0;
+ assertEquals(expected, actual);
+ }
+
+ private EPApp mockUpdateAppRoleDescription() {
+ EPApp app = mockApp();
+ app.setId(2l);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> epRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setAppRoleId(2l);
+ getEPRole.setActive(true);
+ epRoleList.add(getEPRole);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
+ .thenReturn(epRoleList);
+ return app;
+ }
+