@Test public void testGetProviderList() throws Exception { int offset = 0; int number = 3; String aggregatorId = "SampleAggregatorId"; WebTarget target = target("/" + ProviderOptionListContainer.PROVIDERS).queryParam("aggregatorId", aggregatorId).queryParam("offset", offset).queryParam("number", number); DataProvider provider = new DataProvider(); provider.setName("Name"); DataProvider provider1 = new DataProvider(); provider1.setName("Name1"); DataProvider provider2 = new DataProvider(); provider2.setName("Name2"); List<DataProvider> providerList = new ArrayList<DataProvider>(); providerList.add(provider); providerList.add(provider1); providerList.add(provider2); when(dataManager.getDataProvidersListSorted(aggregatorId, offset, number)).thenReturn(providerList).thenThrow(new ObjectNotFoundException(aggregatorId)); Response response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(200, response.getStatus()); List<DataProvider> subList = response.readEntity(new GenericType<List<DataProvider>>() { }); assertEquals(providerList.size(), subList.size()); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(404, response.getStatus()); target = target("/" + ProviderOptionListContainer.PROVIDERS).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 providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) public Response getProviderList( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @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 InvalidArgumentsException, DoesNotExistException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<DataProvider> providersListSorted; try { providersListSorted = dataManager.getDataProvidersListSorted(aggregatorId, offset, number); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200) .entity(new GenericEntity<List<DataProvider>>(providersListSorted) {}).build(); }
ProvidersResource { @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) public Response getProviderList( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @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 InvalidArgumentsException, DoesNotExistException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<DataProvider> providersListSorted; try { providersListSorted = dataManager.getDataProvidersListSorted(aggregatorId, offset, number); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200) .entity(new GenericEntity<List<DataProvider>>(providersListSorted) {}).build(); } }
ProvidersResource { @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) public Response getProviderList( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @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 InvalidArgumentsException, DoesNotExistException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<DataProvider> providersListSorted; try { providersListSorted = dataManager.getDataProvidersListSorted(aggregatorId, offset, number); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200) .entity(new GenericEntity<List<DataProvider>>(providersListSorted) {}).build(); } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); }
ProvidersResource { @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) public Response getProviderList( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @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 InvalidArgumentsException, DoesNotExistException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<DataProvider> providersListSorted; try { providersListSorted = dataManager.getDataProvidersListSorted(aggregatorId, offset, number); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200) .entity(new GenericEntity<List<DataProvider>>(providersListSorted) {}).build(); } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); @OPTIONS @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "OPTIONS", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getOptions(); @GET @Path("/" + ProviderOptionListContainer.OPTIONS) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "GET", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getGETOptions(); @GET @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get specific provider.", httpMethod = "GET", response = DataProvider.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Provider)"), @ApiResponse(code = 404, message = "DoesNotExistException")}) DataProvider getProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId); @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response createProvider(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @DELETE @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Delete a provider.", 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 deleteProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String dataProviderId); @PUT @Path("/" + ProviderOptionListContainer.PROVIDERID) @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Update a provider.", 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 = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response updateProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId,
      @ApiParam(value = "Aggregator Id", required = false) @QueryParam("newAggregatorId") String newAggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) Response getProviderList(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @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); }
ProvidersResource { @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) public Response getProviderList( @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId, @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 InvalidArgumentsException, DoesNotExistException { if (offset < 0) throw new InvalidArgumentsException("Offset negative values not allowed!"); List<DataProvider> providersListSorted; try { providersListSorted = dataManager.getDataProvidersListSorted(aggregatorId, offset, number); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } catch (IndexOutOfBoundsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } return Response.status(200) .entity(new GenericEntity<List<DataProvider>>(providersListSorted) {}).build(); } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); @OPTIONS @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "OPTIONS", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getOptions(); @GET @Path("/" + ProviderOptionListContainer.OPTIONS) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get options over providers conext.", httpMethod = "GET", response = ProviderOptionListContainer.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK (Response containing a list of all available options)")}) ProviderOptionListContainer getGETOptions(); @GET @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get specific provider.", httpMethod = "GET", response = DataProvider.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing an Provider)"), @ApiResponse(code = 404, message = "DoesNotExistException")}) DataProvider getProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId); @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Create a provider.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "Created (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response createProvider(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @DELETE @Path("/" + ProviderOptionListContainer.PROVIDERID) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Delete a provider.", 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 deleteProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String dataProviderId); @PUT @Path("/" + ProviderOptionListContainer.PROVIDERID) @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Update a provider.", 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 = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException")}) Response updateProvider(
      @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId,
      @ApiParam(value = "Aggregator Id", required = false) @QueryParam("newAggregatorId") String newAggregatorId,
      @ApiParam(value = "Provider data", required = true) DataProvider provider); @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation(value = "Get a list of providers.", httpMethod = "GET", response = DataProvider.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of providers)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException")}) Response getProviderList(
      @ApiParam(value = "AggregatorId", required = true) @QueryParam("aggregatorId") String aggregatorId,
      @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; }