@Test public void getAllUserFeedback() throws Exception { when(authorization.getUser("foo")).thenReturn(username); when(feedback.getAllUserFeedback()).thenReturn(userFeedbacks); when(httpHeader.headers()).thenReturn(responseBuilder); when(responseBuilder.entity(anyCollection())).thenReturn(responseBuilder); when(responseBuilder.build()).thenReturn(response); feedbackResource.getAllUserFeedback("foo"); verify(authorization).getUser("foo"); verify(authorization).checkSuperAdmin(username); verify(feedback).getAllUserFeedback(); verify(httpHeader).headers(); verify(responseBuilder).entity(userFeedbackCaptor.capture()); assertThat(userFeedbackCaptor.getValue().size(), is(1)); assertThat(userFeedbackCaptor.getValue(), hasEntry("feedback", userFeedbacks)); verify(responseBuilder).build(); }
@GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed public Response getAllUserFeedback( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { authorization.checkSuperAdmin(authorization.getUser(authorizationHeader)); ImmutableMap<String, List<UserFeedback>> userFeedback = new ImmutableMap.Builder<String, List<UserFeedback>>() .put("feedback", feedback.getAllUserFeedback()).build(); return httpHeader.headers().entity(userFeedback).build(); } catch (Exception exception) { LOGGER.error("getAllUserFeedback failed with error:", exception); throw exception; } }
FeedbackResource { @GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed public Response getAllUserFeedback( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { authorization.checkSuperAdmin(authorization.getUser(authorizationHeader)); ImmutableMap<String, List<UserFeedback>> userFeedback = new ImmutableMap.Builder<String, List<UserFeedback>>() .put("feedback", feedback.getAllUserFeedback()).build(); return httpHeader.headers().entity(userFeedback).build(); } catch (Exception exception) { LOGGER.error("getAllUserFeedback failed with error:", exception); throw exception; } } }
FeedbackResource { @GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed public Response getAllUserFeedback( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { authorization.checkSuperAdmin(authorization.getUser(authorizationHeader)); ImmutableMap<String, List<UserFeedback>> userFeedback = new ImmutableMap.Builder<String, List<UserFeedback>>() .put("feedback", feedback.getAllUserFeedback()).build(); return httpHeader.headers().entity(userFeedback).build(); } catch (Exception exception) { LOGGER.error("getAllUserFeedback failed with error:", exception); throw exception; } } @Inject  FeedbackResource(final Authorization authorization, final Feedback feedback, final HttpHeader httpHeader); }
FeedbackResource { @GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed public Response getAllUserFeedback( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { authorization.checkSuperAdmin(authorization.getUser(authorizationHeader)); ImmutableMap<String, List<UserFeedback>> userFeedback = new ImmutableMap.Builder<String, List<UserFeedback>>() .put("feedback", feedback.getAllUserFeedback()).build(); return httpHeader.headers().entity(userFeedback).build(); } catch (Exception exception) { LOGGER.error("getAllUserFeedback failed with error:", exception); throw exception; } } @Inject  FeedbackResource(final Authorization authorization, final Feedback feedback, final HttpHeader httpHeader); @GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed Response getAllUserFeedback(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit feedback") @Timed Response postFeedback(
            @ApiParam(name = "userFeedback", value = "Please see model example", required = true)
            final UserFeedback userFeedback,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/users/{username}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get single user feedback") @Timed Response getUserFeedback(
            @PathParam("username")
            @ApiParam(value = "User name")
            final UserInfo.Username username,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); }
FeedbackResource { @GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed public Response getAllUserFeedback( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { authorization.checkSuperAdmin(authorization.getUser(authorizationHeader)); ImmutableMap<String, List<UserFeedback>> userFeedback = new ImmutableMap.Builder<String, List<UserFeedback>>() .put("feedback", feedback.getAllUserFeedback()).build(); return httpHeader.headers().entity(userFeedback).build(); } catch (Exception exception) { LOGGER.error("getAllUserFeedback failed with error:", exception); throw exception; } } @Inject  FeedbackResource(final Authorization authorization, final Feedback feedback, final HttpHeader httpHeader); @GET @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get all feedback") @Timed Response getAllUserFeedback(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Submit feedback") @Timed Response postFeedback(
            @ApiParam(name = "userFeedback", value = "Please see model example", required = true)
            final UserFeedback userFeedback,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/users/{username}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Get single user feedback") @Timed Response getUserFeedback(
            @PathParam("username")
            @ApiParam(value = "User name")
            final UserInfo.Username username,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader);  }