@Test public void testGetProvider() throws MalformedURLException { String providerId = "SampleId"; when(dataManager.getDataProvider(providerId)) .thenReturn(new DataProvider(providerId, "testName", "testCountry", "testDescription", null, "testNameCode", "testHomePage", ProviderType.LIBRARY, "SampleEmail")); WebTarget target = target("/" + ProviderOptionListContainer.PROVIDERS + "/" + providerId); Response response = target.request(MediaType.APPLICATION_XML).head(); assertEquals(200, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).head(); assertEquals(200, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(200, response.getStatus()); DataProvider provider = response.readEntity(DataProvider.class); response = target.request(MediaType.APPLICATION_JSON).get(); assertEquals(200, response.getStatus()); provider = response.readEntity(DataProvider.class); assertEquals(providerId, provider.getId()); target = target("/" + ProviderOptionListContainer.PROVIDERS + "/" + "FakeAggregatorId"); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_JSON).get(); assertEquals(404, response.getStatus()); }
@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")}) public DataProvider getProvider( @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId) throws DoesNotExistException { DataProvider provider = null; provider = dataManager.getDataProvider(providerId); if (provider == null) throw new DoesNotExistException("Provider with id " + providerId + " does NOT exist!"); return provider; }
ProvidersResource { @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")}) public DataProvider getProvider( @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId) throws DoesNotExistException { DataProvider provider = null; provider = dataManager.getDataProvider(providerId); if (provider == null) throw new DoesNotExistException("Provider with id " + providerId + " does NOT exist!"); return provider; } }
ProvidersResource { @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")}) public DataProvider getProvider( @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId) throws DoesNotExistException { DataProvider provider = null; provider = dataManager.getDataProvider(providerId); if (provider == null) throw new DoesNotExistException("Provider with id " + providerId + " does NOT exist!"); return provider; } ProvidersResource();  ProvidersResource(DefaultDataManager dataManager); }
ProvidersResource { @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")}) public DataProvider getProvider( @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId) throws DoesNotExistException { DataProvider provider = null; provider = dataManager.getDataProvider(providerId); if (provider == null) throw new DoesNotExistException("Provider with id " + providerId + " does NOT exist!"); return provider; } 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 @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")}) public DataProvider getProvider( @ApiParam(value = "Id of provider", required = true) @PathParam("providerId") String providerId) throws DoesNotExistException { DataProvider provider = null; provider = dataManager.getDataProvider(providerId); if (provider == null) throw new DoesNotExistException("Provider with id " + providerId + " does NOT exist!"); return provider; } 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; }