DirectoryService { public ResponseEntity<DirectoryObjects> searchByUPN(String UserPrincipalName) { AndFilter andFilter = new AndFilter(); andFilter.and(new LikeFilter("userPrincipalName", UserPrincipalName+"*")); andFilter.and(new EqualsFilter("objectClass", "user")); List<DirectoryUser> allPersons = getAllPersons(andFilter); DirectoryObjects users = new DirectoryObjects(); DirectoryObjectsList usersList = new DirectoryObjectsList(); usersList.setValues(allPersons.toArray(new DirectoryUser[allPersons.size()])); users.setData(usersList); return ResponseEntity.status(HttpStatus.OK).body(users); }  ResponseEntity<DirectoryObjects> searchByUPN(String UserPrincipalName); ResponseEntity<DirectoryObjects> searchByCorpId(String corpId); ResponseEntity<DirectoryObjects> searchByGroupName(String groupName);  }
@Test public void test_searchByUPN_successfully() { 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> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(users); when(ldapTemplate.search(Mockito.anyString(), Mockito.anyString(), Mockito.any(AttributesMapper.class))).thenReturn(persons); ResponseEntity<DirectoryObjects> responseEntity = directoryService.searchByUPN("test_principal_name"); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected.getBody().getData().getValues()[0], responseEntity.getBody().getData().getValues()[0]); }