LDAPAuthService { public ResponseEntity<String> fetchLdapUser(String token, String username){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Fetch LDAP user"). put(LogMessage.MESSAGE, String.format("Trying to fetch LDAP user for [%s]", username)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/ldap/users","{\"username\":\""+username+"\"}",token); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Fetch LDAP user"). put(LogMessage.MESSAGE, "Listing of LDAP user completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }  ResponseEntity<String> authenticateLdap(UserLogin userLogin); ResponseEntity<String> configureLdapGroup(String token, LDAPGroup ldapGroup); ResponseEntity<String> listLdapGroups(String token); ResponseEntity<String> fetchLdapGroup(String token, String groupname); ResponseEntity<String> deleteLdapGroup(String token, String groupname); ResponseEntity<String> configureLdapUser(String token, LDAPUser ldapUser); ResponseEntity<String> listLdapUsers(String token); ResponseEntity<String> fetchLdapUser(String token, String username); ResponseEntity<String> deleteLdapUser(String token, String username);  }
@Test public void test_fetchLdapUser_successfully() { String token = "4EpPYDSfgN2D4Gf7UmNO3nuL"; Response responseUser = getMockResponse(HttpStatus.OK, true, "{ \"data\": {\"groups\": \"\",\"policies\": [ \"admin\", \"default\" ] }}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{ \"data\": {\"groups\": \"\",\"policies\": [ \"admin\", \"default\" ] }}"); when(reqProcessor.process("/auth/ldap/users","{\"username\":\"safeadmin\"}",token)).thenReturn(responseUser); ResponseEntity<String> responseEntity = ldapAuthService.fetchLdapUser(token, "safeadmin"); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }