@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);
}