OIDCUtil { public String getUserName(String email){ ResponseEntity<DirectoryObjects> responseEntity = directoryService.searchByUPN(email); String userName = ""; Object[] results = responseEntity.getBody().getData().getValues(); for (Object tp : results) { userName = ((DirectoryUser) tp).getUserName(); } return userName; } OIDCUtil(); String fetchMountAccessorForOidc(String token); OIDCEntityResponse getEntityLookUpResponse(String authMountResponse); Response updateGroupPolicies(String token, String groupName, List<String> policies,
			List<String> currentPolicies, String id); Response deleteGroupByName(String token, String name); OIDCGroup getIdentityGroupDetails(String groupName, String token); String getSSOToken(); String getGroupObjectResponse(String ssoToken, String groupName); String updateIdentityGroupByName(String token, OIDCIdentityGroupRequest oidcIdentityGroupRequest); Response createGroupAlias(String token, GroupAliasRequest groupAliasRequest); ResponseEntity<OIDCEntityResponse> oidcFetchEntityDetails(String token, String username, UserDetails userDetails); ResponseEntity<OIDCEntityResponse> entityLookUp(String token,
			OIDCLookupEntityRequest oidcLookupEntityRequest); Response deleteGroupAliasByID(String token, String id); Response updateOIDCEntity(List<String> policies, String entityName); Response updateEntityByName(String token, OIDCEntityRequest oidcEntityRequest); void renewUserToken(String token); List<String> getPoliciedFromTokenLookUp(String authMountResponse); List<String> tokenLookUp(String token); Response createEntityAlias(String token, OidcEntityAliasRequest oidcEntityAliasRequest); String getUserName(String email); List<DirectoryGroup> getGroupsFromAAD(String ssoToken, String groupName); String getIdOfTheUser(String accessToken, String userEmail); List<String> getSelfServiceGroupsFromAADById(String accessToken, String userAADId, String userName); static final Logger log; }
@Test public void getUserName_Success(){ String username = "testuser"; String email = "testUser@t-mobile.com"; Response responsemock = getMockResponse(HttpStatus.OK, true, username); DirectoryUser directoryUser = new DirectoryUser(); directoryUser.setDisplayName("testUser"); directoryUser.setGivenName("testUser"); directoryUser.setUserEmail("testUser@t-mobile.com"); directoryUser.setUserId("testuser01"); directoryUser.setUserName("testuser"); List<DirectoryUser> persons = new ArrayList<>(); persons.add(directoryUser); DirectoryObjects users = new DirectoryObjects(); DirectoryObjectsList usersList = new DirectoryObjectsList(); usersList.setValues(persons.toArray(new DirectoryUser[persons.size()])); users.setData(usersList); ResponseEntity<DirectoryObjects> responseEntity1 = ResponseEntity.status(HttpStatus.OK).body(users); when(directoryService.searchByUPN(directoryUser.getUserEmail())).thenReturn(responseEntity1); String originalUserName = oidcUtil.getUserName(email); assertEquals(originalUserName, responsemock.getResponse().toString()); }