@Test public void testPostFavorite() throws Exception { Response response = favoritesResource.postFavorite(EXAMPLE_AUTHORIZATION_HEADER, testExperiment); Assert.assertEquals("List was not correctly returned on POST.", expectedFavoriteList, ((Map) response.getEntity()).get("experimentIDs")); }
@POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") public Response postFavorite( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authHeader, @ApiParam(value = "id") final Experiment experiment) { try { UserInfo.Username userName = authorization.getUser(authHeader); List<Experiment.ID> favoriteList = favorites.addFavorite(userName, experiment.getID()); return httpHeader.headers(Response.Status.OK).entity(prepareResponseEntity(favoriteList)).build(); } catch (Exception exception) { LOGGER.error("postFavorite failed for experiment={} with error:", experiment, exception); throw exception; } }
FavoritesResource { @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") public Response postFavorite( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authHeader, @ApiParam(value = "id") final Experiment experiment) { try { UserInfo.Username userName = authorization.getUser(authHeader); List<Experiment.ID> favoriteList = favorites.addFavorite(userName, experiment.getID()); return httpHeader.headers(Response.Status.OK).entity(prepareResponseEntity(favoriteList)).build(); } catch (Exception exception) { LOGGER.error("postFavorite failed for experiment={} with error:", experiment, exception); throw exception; } } }
FavoritesResource { @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") public Response postFavorite( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authHeader, @ApiParam(value = "id") final Experiment experiment) { try { UserInfo.Username userName = authorization.getUser(authHeader); List<Experiment.ID> favoriteList = favorites.addFavorite(userName, experiment.getID()); return httpHeader.headers(Response.Status.OK).entity(prepareResponseEntity(favoriteList)).build(); } catch (Exception exception) { LOGGER.error("postFavorite failed for experiment={} with error:", experiment, exception); throw exception; } } @Inject  FavoritesResource(final HttpHeader httpHeader,
                             final Favorites favorites, final Authorization authorization); }
FavoritesResource { @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") public Response postFavorite( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authHeader, @ApiParam(value = "id") final Experiment experiment) { try { UserInfo.Username userName = authorization.getUser(authHeader); List<Experiment.ID> favoriteList = favorites.addFavorite(userName, experiment.getID()); return httpHeader.headers(Response.Status.OK).entity(prepareResponseEntity(favoriteList)).build(); } catch (Exception exception) { LOGGER.error("postFavorite failed for experiment={} with error:", experiment, exception); throw exception; } } @Inject  FavoritesResource(final HttpHeader httpHeader,
                             final Favorites favorites, final Authorization authorization); @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") Response postFavorite(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authHeader,

            @ApiParam(value = "id")
            final Experiment experiment); @GET @ApiOperation(value = "Gets a list of favorites.", response = Response.class, httpMethod = "DELETE", protocols = "https") @Timed(name = "getFavorites") Response getFavorites(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authHeader); @DELETE @Path("/{experimentID}") @ApiOperation(value = "Removes a favorite.", response = Response.class, httpMethod = "DELETE", protocols = "https") @Timed(name = "deleteFavorite") Response deleteFavorite(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authHeader,

            @PathParam("experimentID")
            @ApiParam(value = "Experiment ID")
            final Experiment.ID experimentID); }
FavoritesResource { @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") public Response postFavorite( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authHeader, @ApiParam(value = "id") final Experiment experiment) { try { UserInfo.Username userName = authorization.getUser(authHeader); List<Experiment.ID> favoriteList = favorites.addFavorite(userName, experiment.getID()); return httpHeader.headers(Response.Status.OK).entity(prepareResponseEntity(favoriteList)).build(); } catch (Exception exception) { LOGGER.error("postFavorite failed for experiment={} with error:", experiment, exception); throw exception; } } @Inject  FavoritesResource(final HttpHeader httpHeader,
                             final Favorites favorites, final Authorization authorization); @POST @Consumes(APPLICATION_JSON) @ApiOperation(value = "Stores a favorite.", response = Response.class, httpMethod = "POST", produces = APPLICATION_JSON, protocols = "https") @Timed(name = "postFavorite") Response postFavorite(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authHeader,

            @ApiParam(value = "id")
            final Experiment experiment); @GET @ApiOperation(value = "Gets a list of favorites.", response = Response.class, httpMethod = "DELETE", protocols = "https") @Timed(name = "getFavorites") Response getFavorites(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authHeader); @DELETE @Path("/{experimentID}") @ApiOperation(value = "Removes a favorite.", response = Response.class, httpMethod = "DELETE", protocols = "https") @Timed(name = "deleteFavorite") Response deleteFavorite(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authHeader,

            @PathParam("experimentID")
            @ApiParam(value = "Experiment ID")
            final Experiment.ID experimentID);  }