AccessService { public ResponseEntity<String> getPolicyInfo(String token, String accessid){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Get Policy information"). put(LogMessage.MESSAGE, String.format("Trying to get policy information for [%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","{\"accessid\":\""+accessid+"\"}",token); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Get Policy information"). put(LogMessage.MESSAGE, "Getting policy information Complete"). 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_getAccessPolicyInfo_successfully() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String accessId = "test-access-policy"; String responseJson = "{\"policies\": [\"default\",\"my-test-policy\",\"root\"]}"; Response response =getMockResponse(HttpStatus.OK, true, responseJson); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(responseJson); when(reqProcessor.process("/access","{\"accessid\":\""+accessId+"\"}",token)).thenReturn(response); ResponseEntity<String> responseEntity = accessService.getPolicyInfo(token, accessId); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_getAccessPolicyInfo_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.getPolicyInfo(token, accessId); assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }