UserResource { @ApiOperation(notes = "Retrieves a single User", value = "getUserInfo") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Path("/{username}") @Produces(MediaType.APPLICATION_JSON) public UserDTO getUserInfo(@PathParam("username") @Verify(User.class) String username) { return this.modelTranslator.translate(this.fetchUserByUsername(username), UserDTO.class); } @Inject  UserResource(UserServiceAdapter userService, I18n i18n, OwnerCurator ownerCurator,
        ModelTranslator modelTranslator); @ApiOperation(notes = "Retrieves a list of Users", value = "list", response = UserDTO.class, responseContainer = "List") @GET @Produces(MediaType.APPLICATION_JSON) Stream<UserDTO> list(); @ApiOperation(notes = "Retrieves a single User", value = "getUserInfo") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Path("/{username}") @Produces(MediaType.APPLICATION_JSON) UserDTO getUserInfo(@PathParam("username") @Verify(User.class) String username); @ApiOperation(notes = "Retrieves a list of Roles by User", value = "getUserRoles", response = RoleDTO.class, responseContainer = "List") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Path("/{username}/roles") @Produces(MediaType.APPLICATION_JSON) Stream<RoleDTO> getUserRoles(@PathParam("username") @Verify(User.class) String username); @ApiOperation(notes = "Creates a User", value = "createUser") // We declare an implict parameter to get the Swagger generated client to submit passwords but not to // expect them back. @ApiImplicitParams({ @ApiImplicitParam(name = "user", paramType = "body", required = true, dataType = "org.candlepin.model.User$UserCreationRequest") }) @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 409, message = "") }) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) UserDTO createUser(@ApiParam(hidden = true) UserDTO dto); @ApiOperation(notes = "Updates a User", value = "updateUser") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/{username}") UserDTO updateUser(
        @PathParam("username") @Verify(User.class) String username,
        @ApiParam(name = "user", required = true) UserDTO dto); @ApiOperation(notes = "Removes a User", value = "deleteUser") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @DELETE @Path("/{username}") @Produces(MediaType.APPLICATION_JSON) void deleteUser(@PathParam("username") String username); @ApiOperation(notes = "Retrieve a list of owners the user can register systems to. " + "Previously this represented owners the user was an admin for. Because the " + "client uses this API call to list the owners a user can register to, when " + "we introduced 'my systems' administrator, we have to change its meaning to " + "listing the owners that can be registered to by default to maintain " + "compatability with released clients.", value = "listUsersOwners", response = OwnerDTO.class, responseContainer = "List") // TODO: should probably accept access level and sub-resource query params someday @GET @Path("/{username}/owners") @Produces(MediaType.APPLICATION_JSON) Stream<OwnerDTO> listUsersOwners(
        @PathParam("username") @Verify(User.class) String username,
        @Context Principal principal);  }
@Test public void testLookupUser() { User user = new User(); user.setUsername("test-user"); user.setPassword("banana"); user.setSuperAdmin(true); this.userCurator.create(user); UserDTO output = this.resource.getUserInfo(user.getUsername()); assertNotNull(output); assertEquals(output.getUsername(), user.getUsername()); assertEquals(output.isSuperAdmin(), user.isSuperAdmin()); assertNull(output.getHashedPassword()); }
@Test public void testLookupUserDoesntExist() { User user = new User(); user.setUsername("test-user"); user.setPassword("banana"); user.setSuperAdmin(true); this.userCurator.create(user); assertThrows(NotFoundException.class, () -> this.resource.getUserInfo("no such user")); }
@Test public void testLookupUserNullUsername() { User user = new User(); user.setUsername("test-user"); user.setPassword("banana"); user.setSuperAdmin(true); this.userCurator.create(user); assertThrows(BadRequestException.class, () -> this.resource.getUserInfo(null)); }