UserPassService { public ResponseEntity<String> deleteUser(String token, String username){ UserLogin user = new UserLogin(); user.setUsername(username); String jsonStr = JSONUtil.getJSON(user); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete User"). put(LogMessage.MESSAGE, "Trying to delete user"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/auth/userpass/delete",jsonStr,token); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete User"). put(LogMessage.MESSAGE, "Username User deleted successfully"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Username User deleted\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete User"). put(LogMessage.MESSAGE, "Username User failed"). put(LogMessage.RESPONSE, response.getResponse()). 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> createUser(String token, UserpassUser user); ResponseEntity<String> readUser(String token, String username); ResponseEntity<String> deleteUser(String token, String username); ResponseEntity<String> updatePassword( String token, UserpassUser user); ResponseEntity<String> listUsers(String token); ResponseEntity<String> login(UserLogin user);  }
@Test public void test_deleteUser_successfully() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; UserLogin user = new UserLogin(); user.setUsername("testuser"); String jsonStr = "{\"username\":\"testuser\",\"password\":null}"; Response response = getMockResponse(HttpStatus.NO_CONTENT, true, ""); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Username User deleted\"]}"); when(JSONUtil.getJSON(Mockito.any(UserLogin.class))).thenReturn(jsonStr); when(reqProcessor.process("/auth/userpass/delete",jsonStr,token)).thenReturn(response); ResponseEntity<String> responseEntity = userPassService.deleteUser(token,"testuser"); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_deleteUser_failed_500() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; UserLogin user = new UserLogin(); user.setUsername("testuser"); String jsonStr = "{\"username\":\"testuser\",\"password\":null}"; Response response = getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, "{\"errors\":[\"Delete User failed\"]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Delete User failed\"]}"); when(JSONUtil.getJSON(Mockito.any(UserLogin.class))).thenReturn(jsonStr); when(reqProcessor.process("/auth/userpass/delete",jsonStr,token)).thenReturn(response); ResponseEntity<String> responseEntity = userPassService.deleteUser(token,"testuser"); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }