UserResource { @ApiOperation(notes = "Retrieves a list of Users", value = "list", response = UserDTO.class, responseContainer = "List") @GET @Produces(MediaType.APPLICATION_JSON) public Stream<UserDTO> list() { Collection<? extends UserInfo> users = userService.listUsers(); return users != null ? users.stream().map(this.modelTranslator.getStreamMapper(UserInfo.class, UserDTO.class)) : null; } @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 testListAllUsers() { int userCount = 5; for (int i = 0; i < userCount; ++i) { User user = new User(); user.setUsername("test-user-" + i); user.setPassword("banana"); user.setSuperAdmin(true); this.userCurator.create(user); } Stream<UserDTO> response = this.resource.list(); assertNotNull(response); List<UserDTO> users = response.collect(Collectors.toList()); assertEquals(userCount, users.size()); for (UserDTO user : users) { assertNotNull(user); assertNotNull(user.getUsername()); assertTrue(user.getUsername().startsWith("test-user-")); assertNull(user.getHashedPassword()); assertTrue(user.isSuperAdmin()); } }