@Test public void testCreateAggregator() throws DocumentException, IOException, InvalidArgumentsException, AlreadyExistsException { WebTarget target = target("/" + AggregatorOptionListContainer.AGGREGATORS); Aggregator aggregator = new Aggregator("ValidId", "Greece", "GR", "http: when(dataManager.createAggregator(aggregator.getId(), aggregator.getName(), aggregator.getNameCode(), aggregator.getHomepage().toString())) .thenReturn(aggregator).thenThrow(new AlreadyExistsException("Already exists!")) .thenThrow(new InvalidArgumentsException("Invalid Argument URL")).thenThrow(new IOException()).thenThrow(new DocumentException()); Response response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(aggregator, MediaType.APPLICATION_XML), Response.class); assertEquals(201, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(aggregator, MediaType.APPLICATION_XML), Response.class); assertEquals(409, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(aggregator, MediaType.APPLICATION_XML), Response.class); assertEquals(400, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(aggregator, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(aggregator, MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); aggregator = new Aggregator(null, null, "GR", "http: response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(aggregator, MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); }
@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") }) public Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException { Aggregator createdAggregator = null; if (aggregator.getName() != null && !aggregator.getName().isEmpty()) { try { createdAggregator = dataManager.createAggregator(aggregator.getId(), aggregator.getName(), aggregator.getNameCode(), aggregator.getHomepage().toString()); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } } else throw new MissingArgumentsException("Missing argument name!"); return Response.created(null) .entity(new Result("Aggregator with id = " + createdAggregator.getId() + " and name = " + createdAggregator.getName() + " created successfully")) .build(); }
AggregatorsResource { @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") }) public Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException { Aggregator createdAggregator = null; if (aggregator.getName() != null && !aggregator.getName().isEmpty()) { try { createdAggregator = dataManager.createAggregator(aggregator.getId(), aggregator.getName(), aggregator.getNameCode(), aggregator.getHomepage().toString()); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } } else throw new MissingArgumentsException("Missing argument name!"); return Response.created(null) .entity(new Result("Aggregator with id = " + createdAggregator.getId() + " and name = " + createdAggregator.getName() + " created successfully")) .build(); } }
AggregatorsResource { @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") }) public Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException { Aggregator createdAggregator = null; if (aggregator.getName() != null && !aggregator.getName().isEmpty()) { try { createdAggregator = dataManager.createAggregator(aggregator.getId(), aggregator.getName(), aggregator.getNameCode(), aggregator.getHomepage().toString()); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } } else throw new MissingArgumentsException("Missing argument name!"); return Response.created(null) .entity(new Result("Aggregator with id = " + createdAggregator.getId() + " and name = " + createdAggregator.getName() + " created successfully")) .build(); } AggregatorsResource();  AggregatorsResource(DefaultDataManager dataManager); }
AggregatorsResource { @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") }) public Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException { Aggregator createdAggregator = null; if (aggregator.getName() != null && !aggregator.getName().isEmpty()) { try { createdAggregator = dataManager.createAggregator(aggregator.getId(), aggregator.getName(), aggregator.getNameCode(), aggregator.getHomepage().toString()); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } } else throw new MissingArgumentsException("Missing argument name!"); return Response.created(null) .entity(new Result("Aggregator with id = " + createdAggregator.getId() + " and name = " + createdAggregator.getName() + " created successfully")) .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 { @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") }) public Response createAggregator(@ApiParam(value = "Aggregator data", required = true) Aggregator aggregator) throws MissingArgumentsException, AlreadyExistsException, InvalidArgumentsException { Aggregator createdAggregator = null; if (aggregator.getName() != null && !aggregator.getName().isEmpty()) { try { createdAggregator = dataManager.createAggregator(aggregator.getId(), aggregator.getName(), aggregator.getNameCode(), aggregator.getHomepage().toString()); } catch (DocumentException | IOException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (InvalidArgumentsException e) { throw new InvalidArgumentsException("Invalid argument: " + e.getMessage()); } catch (AlreadyExistsException e) { throw new AlreadyExistsException("Already exists: " + e.getMessage()); } } else throw new MissingArgumentsException("Missing argument name!"); return Response.created(null) .entity(new Result("Aggregator with id = " + createdAggregator.getId() + " and name = " + createdAggregator.getName() + " created successfully")) .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; }