MonthlyTaxReportService { public byte[] generateReport(Long jobExecutionId, int year, int month) throws PDFGenerationException { Resource monthlyReportTemplate = new ClassPathResource("monthly-tax-report-template.docx"); Map<String, Object> contextMap = new HashMap<>(); contextMap.put("success_sum", sumOfTaxes.getSuccessSum(year, month)); contextMap.put("failed_sum", sumOfTaxes.getFailedSum(year, month)); contextMap.put("date", month + " " + year); byte[] pdfBytes = pdfGeneratorService.generatePdfAsByteArray(monthlyReportTemplate, contextMap); MonthlyReport monthlyReport = MonthlyReport.from(jobExecutionId, year, month, pdfBytes, DateTime.now()); monthlyReportRepository.save(monthlyReport); return pdfBytes; }  byte[] generateReport(Long jobExecutionId, int year, int month); void setPdfGeneratorService(PDFGeneratorService pdfGeneratorService);  }
@Test public void generateReportWithCorrectData() throws PDFGenerationException, IOException { byte[] pdfBytes = monthlyTaxReportService.generateReport(3L, TEST_YEAR, TEST_MONTH); PDDocument pdfDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes)); assertThat(pdfDocument) .containsText("WEBSERVICE RETURNS SUCCESS " + SUCCESS_AMOUNT + " euro"); pdfDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes)); assertThat(pdfDocument) .containsText("WEBSERVICE RETURNS FAILURE " + FAILED_AMOUNT + " euro"); pdfDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes)); assertThat(pdfDocument) .containsText("PERIOD: " + 5 + " " + TEST_YEAR); }
@Test public void testResultsArePersisted() throws Exception { byte[] expectedPdfBytes = monthlyTaxReportService.generateReport(3L, TEST_YEAR, TEST_MONTH); verify(monthlyReportRepository).save(monthlyReportArgumentCaptor.capture()); MonthlyReport value = monthlyReportArgumentCaptor.getValue(); assertThat(value.getMonthlyReportPdf()).isEqualTo(expectedPdfBytes); assertThat(value.getYear()).isEqualTo(TEST_YEAR); assertThat(value.getMonth()).isEqualTo(TEST_MONTH); assertThat(value.getCalculationDate()).isNotNull(); }