AppRoleService { public ResponseEntity<String> deleteAppRole(String token, AppRole appRole, UserDetails userDetails){ if (TVaultConstants.SELF_SERVICE_APPROLE_NAME.equals(appRole.getRole_name())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to remove this AppRole\"]}"); } Response permissionResponse = ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH); if (HttpStatus.INTERNAL_SERVER_ERROR.equals(permissionResponse.getHttpstatus()) || HttpStatus.UNAUTHORIZED.equals(permissionResponse.getHttpstatus())) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\""+permissionResponse.getResponse()+"\"]}"); } String jsonStr = JSONUtil.getJSON(appRole); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete AppRoleId"). put(LogMessage.MESSAGE, String.format("Trying to delete AppRoleId [%s]", jsonStr)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); AppRoleMetadata appRoleMetadata = readAppRoleMetadata(token, appRole.getRole_name()); String approleCreatedBy = userDetails.getUsername(); if ( appRoleMetadata.getAppRoleMetadataDetails() != null) { approleCreatedBy = appRoleMetadata.getAppRoleMetadataDetails().getCreatedBy(); } Response response = reqProcessor.process("/auth/approle/role/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 AppRole"). put(LogMessage.MESSAGE, "Delete AppRole completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); String jsonstr = ControllerUtil.populateAppRoleMetaJson(appRole.getRole_name(), userDetails.getUsername()); Response resp = reqProcessor.process("/delete",jsonstr,token); String appRoleUsermetadataJson = ControllerUtil.populateUserMetaJson(appRole.getRole_name(),approleCreatedBy); Response appRoleUserMetaDataDeletionResponse = reqProcessor.process("/delete",appRoleUsermetadataJson,token); if (HttpStatus.NO_CONTENT.equals(resp.getHttpstatus()) && HttpStatus.NO_CONTENT.equals(appRoleUserMetaDataDeletionResponse.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"AppRole deleted\"]}"); } return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"AppRole deleted, metadata delete failed\"]}"); } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Delete AppRole"). put(LogMessage.MESSAGE, "Delete AppRole 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> createAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> readAppRole(String token, String rolename); ResponseEntity<String> readAppRoles(String token); ResponseEntity<String> listAppRoles(String token,  UserDetails userDetails); ResponseEntity<String> readAppRoleRoleId(String token, String rolename); String readRoleId(String token, String rolename); List<String> readAccessorIds(String token, String rolename); AppRoleMetadata readAppRoleMetadata(String token, String rolename); AppRole readAppRoleBasicDetails(String token, String rolename); ResponseEntity<String> readAppRoleRoleId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleSecretId(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readSecretIdAccessors(String token, String rolename, UserDetails userDetails); ResponseEntity<String> readAppRoleDetails(String token, String rolename, UserDetails userDetails); ResponseEntity<String> createsecretId(String token, AppRoleSecretData appRoleSecretData); ResponseEntity<String> readAppRoleSecretId(String token, String rolename); ResponseEntity<String> deleteSecretId(String token, AppRoleNameSecretId appRoleNameSecretId); ResponseEntity<String> deleteAppRole(String token, AppRole appRole, UserDetails userDetails); ResponseEntity<String> deleteSecretIds(String token, AppRoleAccessorIds appRoleAccessorIds, UserDetails userDetails); ResponseEntity<String> login(AppRoleIdSecretId appRoleIdSecretId); ResponseEntity<String> associateApprole(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> updateAppRole(String token, AppRole appRole, UserDetails userDetails); Response configureApprole(String rolename,String policies,String token );  }
@Test public void test_deleteAppRole_successfully() throws Exception{ String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; Response response =getMockResponse(HttpStatus.NO_CONTENT, true, ""); Response responseOK =getMockResponse(HttpStatus.OK, true, "{\"createdBy\":\"safeadmin\"}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"AppRole deleted\"]}"); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(true); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(responseOK); Map<String, Object> responseMap = new HashMap<>(); responseMap.put("createdBy", "safeadmin"); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response); String approleusername="safeadmin"; String role_name=appRole.getRole_name(); String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name; Response approleMetadataResponse = getMockResponse(HttpStatus.OK, true, getAppRoleMetadataJSON(path, approleusername, role_name)); when(reqProcessor.process("/read","{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(approleMetadataResponse); String appRoleResponseJspn = "{\"path\":\"metadata/approle/approle1\",\"data\":{\"name\":\"approle1\",\"createdBy\":\"safeadmin\"}}"; Map<String, Object> appRoleResponseMap = new HashMap<>(); Map<String, Object> appRoleMetadataMap = new HashMap<>(); appRoleMetadataMap.put("createdBy",approleusername); appRoleResponseMap.put ("data", appRoleMetadataMap); when(ControllerUtil.parseJson(appRoleResponseJspn)).thenReturn(appRoleResponseMap); Response permissionResponse =getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_successfully_meta_failure() throws Exception { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; Response response =getMockResponse(HttpStatus.NO_CONTENT, true, ""); Response response404 =getMockResponse(HttpStatus.NOT_FOUND, true, ""); Response responseOK =getMockResponse(HttpStatus.OK, true, "{\"createdBy\":\"safeadmin\"}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"AppRole deleted, metadata delete failed\"]}"); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(true); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(responseOK); Map<String, Object> responseMap = new HashMap<>(); responseMap.put("createdBy", "safeadmin"); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response404); String approleusername="safeadmin"; String role_name=appRole.getRole_name(); String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name; Response approleMetadataResponse = getMockResponse(HttpStatus.OK, true, getAppRoleMetadataJSON(path, approleusername, role_name)); when(reqProcessor.process("/read","{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(approleMetadataResponse); String appRoleResponseJspn = "{\"path\":\"metadata/approle/approle1\",\"data\":{\"name\":\"approle1\",\"createdBy\":\"safeadmin\"}}"; Map<String, Object> appRoleResponseMap = new HashMap<>(); Map<String, Object> appRoleMetadataMap = new HashMap<>(); appRoleMetadataMap.put("createdBy",approleusername); appRoleResponseMap.put ("data", appRoleMetadataMap); when(ControllerUtil.parseJson(appRoleResponseJspn)).thenReturn(appRoleResponseMap); Response permissionResponse =getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_successfully_normaluser() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; Response response =getMockResponse(HttpStatus.NO_CONTENT, true, ""); Response responseOK =getMockResponse(HttpStatus.OK, true, "{\"data\":{\"createdBy\":\"normaluser\"}}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"AppRole deleted\"]}"); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(false); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(responseOK); Map<String, Object> responseMap = new HashMap<>(); Map<String, Object> data = new HashMap<>(); data.put("createdBy", "normaluser"); responseMap.put("data", data); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response); Response permissionResponse =getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_successfully_metadata404() throws Exception{ String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; Response response =getMockResponse(HttpStatus.NO_CONTENT, true, ""); Response response404 =getMockResponse(HttpStatus.NOT_FOUND, true, ""); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"AppRole deleted\"]}"); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(true); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(response404); Map<String, Object> responseMap = new HashMap<>(); Map<String, Object> data = new HashMap<>(); data.put("createdBy", "normaluser"); responseMap.put("data", data); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response); String approleusername="safeadmin"; String role_name=appRole.getRole_name(); String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name; Response approleMetadataResponse = getMockResponse(HttpStatus.OK, true, getAppRoleMetadataJSON(path, approleusername, role_name)); when(reqProcessor.process("/read","{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(approleMetadataResponse); Response permissionResponse =getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_failure_metadata_403() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; Response response =getMockResponse(HttpStatus.NO_CONTENT, true, ""); Response response403 =getMockResponse(HttpStatus.UNAUTHORIZED, true, ""); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Access denied: no permission to remove the role\"]}"); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(true); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(response403); Map<String, Object> responseMap = new HashMap<>(); Map<String, Object> data = new HashMap<>(); data.put("createdBy", "normaluser"); responseMap.put("data", data); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response); Response permissionResponse =getMockResponse(HttpStatus.UNAUTHORIZED, true, "Access denied: no permission to remove the role"); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_failure() throws Exception{ String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; String responseJson = "{\"error\":[\"Internal Server Error\"]}"; Response response =getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, responseJson); Response responseOK =getMockResponse(HttpStatus.OK, true, "{\"createdBy\":\"safeadmin\"}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseJson); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(true); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(responseOK); Map<String, Object> responseMap = new HashMap<>(); responseMap.put("createdBy", "safeadmin"); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response); String approleusername="safeadmin"; String role_name=appRole.getRole_name(); String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name; Response approleMetadataResponse = getMockResponse(HttpStatus.OK, true, getAppRoleMetadataJSON(path, approleusername, role_name)); when(reqProcessor.process("/read","{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(approleMetadataResponse); String appRoleResponseJspn = "{\"path\":\"metadata/approle/approle1\",\"data\":{\"name\":\"approle1\",\"createdBy\":\"safeadmin\"}}"; Map<String, Object> appRoleResponseMap = new HashMap<>(); Map<String, Object> appRoleMetadataMap = new HashMap<>(); appRoleMetadataMap.put("createdBy",approleusername); appRoleResponseMap.put ("data", appRoleMetadataMap); when(ControllerUtil.parseJson(appRoleResponseJspn)).thenReturn(appRoleResponseMap); Response permissionResponse =getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_failure_500() throws Exception{ String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "approle1"; String responseJson = "{\"error\":[\"Error reading role info\"]}"; Response response =getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, responseJson); Response responseOK =getMockResponse(HttpStatus.OK, true, "{\"createdBy\":\"safeadmin\"}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseJson); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); String jsonStr = "{\"role_name\":\"approle1\",\"policies\":null,\"bind_secret_id\":false,\"secret_id_num_uses\":null,\"secret_id_ttl\":null,\"token_num_uses\":null,\"token_ttl\":null,\"token_max_ttl\":null}"; when(JSONUtil.getJSON(appRole)).thenReturn(jsonStr); when(reqProcessor.process("/auth/approle/role/delete",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(true); when(reqProcessor.process(eq("/read"),Mockito.any(),eq(token))).thenReturn(responseOK); Map<String, Object> responseMap = new HashMap<>(); when(ControllerUtil.parseJson(Mockito.any())).thenReturn(responseMap); when(reqProcessor.process(eq("/delete"),Mockito.any(),eq(token))).thenReturn(response); String approleusername="safeadmin"; String role_name=appRole.getRole_name(); String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name; Response approleMetadataResponse = getMockResponse(HttpStatus.OK, true, getAppRoleMetadataJSON(path, approleusername, role_name)); when(reqProcessor.process("/read","{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(approleMetadataResponse); String appRoleResponseJspn = "{\"path\":\"metadata/approle/approle1\",\"data\":{\"name\":\"approle1\",\"createdBy\":\"safeadmin\"}}"; Map<String, Object> appRoleResponseMap = new HashMap<>(); Map<String, Object> appRoleMetadataMap = new HashMap<>(); appRoleMetadataMap.put("createdBy",approleusername); appRoleResponseMap.put ("data", appRoleMetadataMap); when(ControllerUtil.parseJson(appRoleResponseJspn)).thenReturn(appRoleResponseMap); Response permissionResponse =getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.canDeleteRole(appRole.getRole_name(), token, userDetails, TVaultConstants.APPROLE_METADATA_MOUNT_PATH)).thenReturn(permissionResponse); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }
@Test public void test_deleteAppRole_failure_403() { String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; String appRoleId = "selfservicesupportrole"; String responseJson = "{\"errors\":[\"Access denied: no permission to remove this AppRole\"]}"; Response response =getMockResponse(HttpStatus.BAD_REQUEST, true, responseJson); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseJson); AppRole appRole = new AppRole(); appRole.setRole_name(appRoleId); UserDetails userDetails = getMockUser(true); ResponseEntity<String> responseEntityActual = appRoleService.deleteAppRole(token, appRole, userDetails); assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected, responseEntityActual); }