@Test public void testGetStatistics() throws IOException, DocumentException, SQLException { WebTarget target = target("/" + StatisticsOptionListContainer.STATISTICS); DefaultRepoxStatistics defaultRepoxStatistics = any(DefaultRepoxStatistics.class); when(statisticsManager.generateStatistics(null)).thenThrow(new IOException()).thenReturn(defaultRepoxStatistics); Document document = DocumentHelper.createDocument(); Element root = document.addElement("root"); Element node = root.addElement("author") .addAttribute("name", "exampleName") .addText("Some Text"); when(statisticsManager.getStatisticsReport(defaultRepoxStatistics)).thenThrow(new IOException()).thenReturn(document); Response response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).get(); assertEquals(200, response.getStatus()); }
@GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response getStatistics() throws InternalServerErrorException{ RepoxStatistics statistics; Document statisticsReport; try { statistics = statisticsManager.generateStatistics(null); statisticsReport = statisticsManager .getStatisticsReport(statistics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (statisticsReport != null) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( baos, "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(outputStreamWriter, format); writer.write(statisticsReport); writer.close(); } return Response.status(200).entity(new Result(baos.toString("UTF-8"))).build(); } catch (IOException | DocumentException | SQLException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } }
StatisticsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response getStatistics() throws InternalServerErrorException{ RepoxStatistics statistics; Document statisticsReport; try { statistics = statisticsManager.generateStatistics(null); statisticsReport = statisticsManager .getStatisticsReport(statistics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (statisticsReport != null) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( baos, "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(outputStreamWriter, format); writer.write(statisticsReport); writer.close(); } return Response.status(200).entity(new Result(baos.toString("UTF-8"))).build(); } catch (IOException | DocumentException | SQLException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } } }
StatisticsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response getStatistics() throws InternalServerErrorException{ RepoxStatistics statistics; Document statisticsReport; try { statistics = statisticsManager.generateStatistics(null); statisticsReport = statisticsManager .getStatisticsReport(statistics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (statisticsReport != null) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( baos, "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(outputStreamWriter, format); writer.write(statisticsReport); writer.close(); } return Response.status(200).entity(new Result(baos.toString("UTF-8"))).build(); } catch (IOException | DocumentException | SQLException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } } StatisticsResource();  StatisticsResource(StatisticsManager statisticsManager); }
StatisticsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response getStatistics() throws InternalServerErrorException{ RepoxStatistics statistics; Document statisticsReport; try { statistics = statisticsManager.generateStatistics(null); statisticsReport = statisticsManager .getStatisticsReport(statistics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (statisticsReport != null) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( baos, "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(outputStreamWriter, format); writer.write(statisticsReport); writer.close(); } return Response.status(200).entity(new Result(baos.toString("UTF-8"))).build(); } catch (IOException | DocumentException | SQLException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } } StatisticsResource();  StatisticsResource(StatisticsManager statisticsManager); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over statistics conext.", httpMethod = "OPTIONS", response = StatisticsOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) StatisticsOptionListContainer getOptions(); @GET @Path("/" + StatisticsOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over statistics conext.", httpMethod = "GET", response = StatisticsOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) StatisticsOptionListContainer getGETOptions(); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getStatistics(); }
StatisticsResource { @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response getStatistics() throws InternalServerErrorException{ RepoxStatistics statistics; Document statisticsReport; try { statistics = statisticsManager.generateStatistics(null); statisticsReport = statisticsManager .getStatisticsReport(statistics); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (statisticsReport != null) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( baos, "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(outputStreamWriter, format); writer.write(statisticsReport); writer.close(); } return Response.status(200).entity(new Result(baos.toString("UTF-8"))).build(); } catch (IOException | DocumentException | SQLException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } } StatisticsResource();  StatisticsResource(StatisticsManager statisticsManager); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over statistics conext.", httpMethod = "OPTIONS", response = StatisticsOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) StatisticsOptionListContainer getOptions(); @GET @Path("/" + StatisticsOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over statistics conext.", httpMethod = "GET", response = StatisticsOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) StatisticsOptionListContainer getGETOptions(); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Retrieve the statistics.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getStatistics(); public StatisticsManager statisticsManager; }