@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); }
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; }
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; } }
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; }  }
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); }
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);  }