use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.
the class RuntimeExceptionMapperTest method jbossBadRequestException.
@Test
public void jbossBadRequestException() {
String foo = "foo";
BadRequestException bre = new BadRequestException(foo);
Response r = rem.toResponse(bre);
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
verifyMessage(r, "Runtime Error");
}
use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.
the class RoleResource method updateRole.
@ApiOperation(notes = "Updates a Role. To avoid race conditions, we do not support " + "updating the user or permission collections. Currently this call will only update " + "the role name. See the specific nested POST/DELETE calls for modifying users and" + " permissions.", value = "updateRole")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@PUT
@Path("{role_id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Role updateRole(@PathParam("role_id") String roleId, @ApiParam(name = "role", required = true) Role role) {
// and that ID is NOT equal to what the ID in the URL is, then throw an error
if (role.getId() != null && !roleId.equals(role.getId())) {
throw new BadRequestException(i18n.tr("Role ID does not match path."));
}
Role existingRole = lookupRole(roleId);
existingRole.setName(role.getName());
return this.userService.updateRole(existingRole);
}
use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.
the class RoleResource method addRolePermission.
@ApiOperation(notes = "Adds a Permission to a Role. Returns the updated Role.", value = "addRolePermission")
@ApiResponses({ @ApiResponse(code = 404, message = ""), @ApiResponse(code = 400, message = "") })
@POST
@Path("{role_id}/permissions")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Role addRolePermission(@PathParam("role_id") String roleId, @ApiParam(name = "permissionBlueprint", required = true) PermissionBlueprint permission) {
Role existingRole = lookupRole(roleId);
// internal use:
if (permission.getAccess().equals(Access.NONE)) {
throw new BadRequestException(i18n.tr("Access type NONE not supported."));
}
// Attach actual owner objects to each incoming permission:
Owner temp = permission.getOwner();
Owner real = ownerCurator.lookupByKey(temp.getKey());
permission.setOwner(real);
existingRole.addPermission(permission);
Role r = this.userService.updateRole(existingRole);
return r;
}
use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.
the class BadRequestExceptionMapperTest method emptyMessage.
@Test
public void emptyMessage() {
rem = injector.getInstance(BadRequestExceptionMapper.class);
BadRequestException bre = new BadRequestException("");
Response r = rem.toResponse(bre);
assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
verifyMessage(r, "Bad Request");
}
use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.
the class BadRequestExceptionMapperTest method extractIllegalValue.
@Test
public void extractIllegalValue() {
rem = injector.getInstance(BadRequestExceptionMapper.class);
String foo = "javax.ws.rs.SomeThing(\"paramName\") value is 'strVal' for";
BadRequestException bre = new BadRequestException(foo);
Response r = rem.toResponse(bre);
assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
verifyMessage(r, "strVal is not a valid value for paramName");
}
Aggregations