@Test public void testGetAggregatorList() throws Exception { int offset = 0; int number = 3; WebTarget target = target("/" + AggregatorOptionListContainer.AGGREGATORS).queryParam("offset", offset).queryParam("number", number); Aggregator aggregator = new Aggregator(null, "Greece", "GR", "http: Aggregator aggregator1 = new Aggregator(null, "Greece1", "GR1", "http: Aggregator aggregator2 = new Aggregator(null, "Greece2", "GR2", "http: List<Aggregator> aggregatorList = new ArrayList<Aggregator>(); aggregatorList.add(aggregator); aggregatorList.add(aggregator1); aggregatorList.add(aggregator2); when(dataManager.getAggregatorsListSorted(offset, number)).thenReturn(aggregatorList).thenThrow(new IndexOutOfBoundsException("Server error : Offset cannot be negative")); Response response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(200, response.getStatus()); List<Aggregator> subList = response.readEntity(new GenericType<List<Aggregator>>(){}); assertEquals(aggregatorList.size(), subList.size()); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(400, response.getStatus()); target = target("/" + AggregatorOptionListContainer.AGGREGATORS).queryParam("offset", -1).queryParam("number", number); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(400, response.getStatus()); }
@GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) public Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number) throws Exception, InvalidArgumentsException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<Aggregator> aggregatorsListSorted; try { aggregatorsListSorted = dataManager.getAggregatorsListSorted(offset, number); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new GenericEntity<List<Aggregator>>(aggregatorsListSorted) { }).build(); }
AggregatorsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) public Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number) throws Exception, InvalidArgumentsException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<Aggregator> aggregatorsListSorted; try { aggregatorsListSorted = dataManager.getAggregatorsListSorted(offset, number); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new GenericEntity<List<Aggregator>>(aggregatorsListSorted) { }).build(); } }
AggregatorsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) public Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number) throws Exception, InvalidArgumentsException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<Aggregator> aggregatorsListSorted; try { aggregatorsListSorted = dataManager.getAggregatorsListSorted(offset, number); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new GenericEntity<List<Aggregator>>(aggregatorsListSorted) { }).build(); } AggregatorsResource();  AggregatorsResource(DefaultDataManager dataManager); }
AggregatorsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) public Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number) throws Exception, InvalidArgumentsException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<Aggregator> aggregatorsListSorted; try { aggregatorsListSorted = dataManager.getAggregatorsListSorted(offset, number); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new GenericEntity<List<Aggregator>>(aggregatorsListSorted) { }).build(); } AggregatorsResource();  AggregatorsResource(DefaultDataManager dataManager); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over aggregator conext.", httpMethod = "OPTIONS", response = AggregatorOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) AggregatorOptionListContainer getOptions(); @GET @Path("/" + AggregatorOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over aggregator conext.", httpMethod = "GET", response = AggregatorOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) AggregatorOptionListContainer getGETOptions(); @GET @Path("/" + AggregatorOptionListContainer.AGGREGATORID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific aggregator.", httpMethod = "GET", response = Aggregator.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Aggregator)"), @ApiResponse(code = 404, message = "DoesNotExistException") }) Aggregator getAggregator(@ApiParam(value = "Id of aggregator", required = true) @PathParam("aggregatorId") String aggregatorId); @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Create an aggregator.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator); @DELETE @Path("/" + AggregatorOptionListContainer.AGGREGATORID) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @ApiOperation(value = "Delete an aggregator.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response deleteAggregator(@ApiParam(value = "Id of aggregator", required = true) @PathParam("aggregatorId") String aggregatorId); @PUT @Path("/" + AggregatorOptionListContainer.AGGREGATORID) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Update an aggregator.", httpMethod = "PUT", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response updateAggregator(@ApiParam(value = "Id of aggregator", required = true) @PathParam("aggregatorId") String aggregatorId,
            @ApiParam(value = "Aggregator data", required = true) Aggregator aggregator); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset,
            @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number); }
AggregatorsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) public Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number) throws Exception, InvalidArgumentsException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<Aggregator> aggregatorsListSorted; try { aggregatorsListSorted = dataManager.getAggregatorsListSorted(offset, number); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200).entity(new GenericEntity<List<Aggregator>>(aggregatorsListSorted) { }).build(); } AggregatorsResource();  AggregatorsResource(DefaultDataManager dataManager); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over aggregator conext.", httpMethod = "OPTIONS", response = AggregatorOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) AggregatorOptionListContainer getOptions(); @GET @Path("/" + AggregatorOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over aggregator conext.", httpMethod = "GET", response = AggregatorOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) AggregatorOptionListContainer getGETOptions(); @GET @Path("/" + AggregatorOptionListContainer.AGGREGATORID) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific aggregator.", httpMethod = "GET", response = Aggregator.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Aggregator)"), @ApiResponse(code = 404, message = "DoesNotExistException") }) Aggregator getAggregator(@ApiParam(value = "Id of aggregator", required = true) @PathParam("aggregatorId") String aggregatorId); @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Create an aggregator.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator); @DELETE @Path("/" + AggregatorOptionListContainer.AGGREGATORID) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @ApiOperation(value = "Delete an aggregator.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response deleteAggregator(@ApiParam(value = "Id of aggregator", required = true) @PathParam("aggregatorId") String aggregatorId); @PUT @Path("/" + AggregatorOptionListContainer.AGGREGATORID) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Update an aggregator.", httpMethod = "PUT", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response updateAggregator(@ApiParam(value = "Id of aggregator", required = true) @PathParam("aggregatorId") String aggregatorId,
            @ApiParam(value = "Aggregator data", required = true) Aggregator aggregator); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get a list of aggregators.", httpMethod = "GET", response = Aggregator.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of aggregators)"), @ApiResponse(code = 400, message = "InvalidArgumentsException") }) Response getAggregatorList(@ApiParam(value = "Index where to start from(negative not allowed)", defaultValue = "0") @DefaultValue("0") @QueryParam("offset") int offset,
            @ApiParam(value = "Number of aggregators requested(-1 to get all)", defaultValue = "-1") @DefaultValue("-1") @QueryParam("number") int number); public DefaultDataManager dataManager; }