AccessService { public ResponseEntity<String> deletePolicyInfo(String token, String accessid){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Policy"). put(LogMessage.MESSAGE, String.format("Trying to delete policy [%s]", accessid)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(null == accessid || "".equals(accessid)){ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Missing accessid \"]}"); } Response response = reqProcessor.process("/access/delete","{\"accessid\":\""+accessid+"\"}",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 Policy"). put(LogMessage.MESSAGE, "Policy information deleted succssfully"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Access is deleted\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete Policy"). put(LogMessage.MESSAGE, "Deletion of Policy information 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> createPolicy(String token, AccessPolicy accessPolicy); ResponseEntity<String> updatePolicy( String token,  AccessPolicy accessPolicy); ResponseEntity<String> listAllPolices(String token); ResponseEntity<String> getPolicyInfo(String token, String accessid); ResponseEntity<String> deletePolicyInfo(String token, String accessid);  }
@Test public void test_deleteAccessPolicy_successfully() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String accessId = "test-access-policy"; String responseJson = "{\"messages\":[\"Access is deleted\"]}"; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(responseJson); Response response =getMockResponse(HttpStatus.NO_CONTENT, true, ""); when(reqProcessor.process("/access/delete","{\"accessid\":\""+accessId+"\"}",token)).thenReturn(response); ResponseEntity<String> responseEntity = accessService.deletePolicyInfo(token, accessId); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_deleteAccessPolicy_failure_500() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String accessId = "test-access-policy"; String responseJson = ""; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseJson); Response response =getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, false, ""); when(reqProcessor.process("/access/delete","{\"accessid\":\""+accessId+"\"}",token)).thenReturn(response); ResponseEntity<String> responseEntity = accessService.deletePolicyInfo(token, accessId); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); }
@Test public void test_deleteAccessPolicy_failure_400() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String accessId = ""; String responseJson = "{\"errors\":[\"Missing accessid \"]}"; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseJson); ResponseEntity<String> responseEntity = accessService.deletePolicyInfo(token, accessId); assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); }