@Test public void getApplications() throws Exception { when(authorization.getUser("foo")).thenReturn(username); when(experiments.getApplications()).thenReturn(applicationNames); whenHttpHeader(applicationNames); applicationsResource.getApplications("foo"); verify(authorization).getUser("foo"); verify(experiments).getApplications(); verifyHttpHeader(applicationNames); }
@GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed public Response getApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { if (authorization.getUser(authorizationHeader) == null) { throw new AuthenticationException("User is not authenticated"); } List<Application.Name> applications = experiments.getApplications(); return httpHeader.headers().entity(applications).build(); } catch (Exception exception) { LOGGER.error("Get applications request failed for provided authorization headers:", exception); throw exception; } }
ApplicationsResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed public Response getApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { if (authorization.getUser(authorizationHeader) == null) { throw new AuthenticationException("User is not authenticated"); } List<Application.Name> applications = experiments.getApplications(); return httpHeader.headers().entity(applications).build(); } catch (Exception exception) { LOGGER.error("Get applications request failed for provided authorization headers:", exception); throw exception; } } }
ApplicationsResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed public Response getApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { if (authorization.getUser(authorizationHeader) == null) { throw new AuthenticationException("User is not authenticated"); } List<Application.Name> applications = experiments.getApplications(); return httpHeader.headers().entity(applications).build(); } catch (Exception exception) { LOGGER.error("Get applications request failed for provided authorization headers:", exception); throw exception; } } @Inject  ApplicationsResource(final AuthorizedExperimentGetter authorizedExperimentGetter,
                         final Experiments experiments,
                         final Authorization authorization,
                         final Priorities priorities, final Pages pages,
                         final HttpHeader httpHeader); }
ApplicationsResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed public Response getApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { if (authorization.getUser(authorizationHeader) == null) { throw new AuthenticationException("User is not authenticated"); } List<Application.Name> applications = experiments.getApplications(); return httpHeader.headers().entity(applications).build(); } catch (Exception exception) { LOGGER.error("Get applications request failed for provided authorization headers:", exception); throw exception; } } @Inject  ApplicationsResource(final AuthorizedExperimentGetter authorizedExperimentGetter,
                         final Experiments experiments,
                         final Authorization authorization,
                         final Priorities priorities, final Pages pages,
                         final HttpHeader httpHeader); @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed Response getApplications(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/{applicationName}/experiments/{experimentLabel}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Return metadata for a single experiment", response = Experiment.class) @Timed Response getExperiment(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("experimentLabel")
            @ApiParam(value = "Experiment Label")
            final Experiment.Label experimentLabel,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/{applicationName}/experiments") @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns metadata for all experiments within an application", response = ExperimentList.class) @Timed Response getExperiments(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = false)
            final String authorizationHeader); @PUT @Path("/{applicationName}/priorities") @Produces(APPLICATION_JSON) @ApiOperation(value = "Create global priority list for an application", notes = "Experiments can only be placed in a priority list in DRAFT, RUNNING, and PAUSED states.") @Timed Response createPriorities(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @ApiParam(required = true, defaultValue = DEFAULT_MODEXP)
            final ExperimentIDList experimentIDList,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("{applicationName}/priorities") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the priority list for an application", notes = "The returned priority list is rank ordered.") // response = ??, //todo: update with proper object @Timed Response getPriorities(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("{applicationName}/pages") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the set of pages associated with an application.") @Timed Response getPagesForApplication(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("{applicationName}/pages/{pageName}/experiments") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the experiments associated to a page", notes = "The experiments returned belong to a single application") @Timed Response getExperimentsForPage(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("pageName") final Page.Name pageName,
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader); @GET @Path("{applicationName}/pageexperimentList") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the set of pages associated with an application.") @Timed Response getPagesAndAssociatedExperimentsForApplication(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/tags") @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns a Map of Applications to their tags", response = Map.class) @Timed Response getAllExperimentTags(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); }
ApplicationsResource { @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed public Response getApplications( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader) { try { if (authorization.getUser(authorizationHeader) == null) { throw new AuthenticationException("User is not authenticated"); } List<Application.Name> applications = experiments.getApplications(); return httpHeader.headers().entity(applications).build(); } catch (Exception exception) { LOGGER.error("Get applications request failed for provided authorization headers:", exception); throw exception; } } @Inject  ApplicationsResource(final AuthorizedExperimentGetter authorizedExperimentGetter,
                         final Experiments experiments,
                         final Authorization authorization,
                         final Priorities priorities, final Pages pages,
                         final HttpHeader httpHeader); @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns all applications") @Timed Response getApplications(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/{applicationName}/experiments/{experimentLabel}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Return metadata for a single experiment", response = Experiment.class) @Timed Response getExperiment(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("experimentLabel")
            @ApiParam(value = "Experiment Label")
            final Experiment.Label experimentLabel,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/{applicationName}/experiments") @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns metadata for all experiments within an application", response = ExperimentList.class) @Timed Response getExperiments(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = false)
            final String authorizationHeader); @PUT @Path("/{applicationName}/priorities") @Produces(APPLICATION_JSON) @ApiOperation(value = "Create global priority list for an application", notes = "Experiments can only be placed in a priority list in DRAFT, RUNNING, and PAUSED states.") @Timed Response createPriorities(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @ApiParam(required = true, defaultValue = DEFAULT_MODEXP)
            final ExperimentIDList experimentIDList,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("{applicationName}/priorities") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the priority list for an application", notes = "The returned priority list is rank ordered.") // response = ??, //todo: update with proper object @Timed Response getPriorities(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("{applicationName}/pages") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the set of pages associated with an application.") @Timed Response getPagesForApplication(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("{applicationName}/pages/{pageName}/experiments") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the experiments associated to a page", notes = "The experiments returned belong to a single application") @Timed Response getExperimentsForPage(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @PathParam("pageName") final Page.Name pageName,
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String authorizationHeader); @GET @Path("{applicationName}/pageexperimentList") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the set of pages associated with an application.") @Timed Response getPagesAndAssociatedExperimentsForApplication(
            @PathParam("applicationName")
            @ApiParam(value = "Application Name")
            final Application.Name applicationName,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); @GET @Path("/tags") @Produces(APPLICATION_JSON) @ApiOperation(value = "Returns a Map of Applications to their tags", response = Map.class) @Timed Response getAllExperimentTags(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader);  }