From 1d287ed34bccb7dcc15a33be32ce480831dffa8d Mon Sep 17 00:00:00 2001 From: Martin Panzer Date: Sat, 13 May 2023 20:02:38 +0200 Subject: [PATCH] start writing tests --- .mvn/wrapper/maven-wrapper.properties | 18 + deployment/pom.xml | 37 +- .../test/JasperreportsDevModeTest.java | 2 +- .../jasperreports/test/JasperreportsTest.java | 2 +- integration-tests/pom.xml | 12 +- .../it/JasperreportsResource.java | 317 +- .../src/main/resources/CustomersReport.jrxml | 94 + .../src/main/resources/OrdersReport.jrxml | 96 + .../src/main/resources/northwind.xml | 13836 ++++++++++++++++ .../it/JasperreportsResourceTest.java | 95 +- mvnw | 308 + mvnw.cmd | 205 + pom.xml | 22 +- runtime/pom.xml | 153 +- 14 files changed, 15114 insertions(+), 83 deletions(-) create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 integration-tests/src/main/resources/CustomersReport.jrxml create mode 100644 integration-tests/src/main/resources/OrdersReport.jrxml create mode 100644 integration-tests/src/main/resources/northwind.xml create mode 100644 mvnw create mode 100644 mvnw.cmd diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..6f40a26 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/deployment/pom.xml b/deployment/pom.xml index c51db7e..96df7b1 100644 --- a/deployment/pom.xml +++ b/deployment/pom.xml @@ -9,11 +9,32 @@ quarkus-jasperreports-deployment Quarkus Jasperreports - Deployment + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${version.quarkus} + + + + + + + io.quarkus quarkus-arc-deployment + + io.quarkus + quarkus-jackson-deployment + io.quarkiverse.jasperreports quarkus-jasperreports @@ -25,20 +46,4 @@ test - - - - maven-compiler-plugin - - - - io.quarkus - quarkus-extension-processor - ${quarkus.version} - - - - - - diff --git a/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsDevModeTest.java b/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsDevModeTest.java index f234583..a35d7cc 100644 --- a/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsDevModeTest.java +++ b/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsDevModeTest.java @@ -13,7 +13,7 @@ public class JasperreportsDevModeTest { // Start hot reload (DevMode) test with your extension loaded @RegisterExtension static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); @Test public void writeYourOwnDevModeTest() { diff --git a/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsTest.java b/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsTest.java index b04c410..fb9bae7 100644 --- a/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsTest.java +++ b/deployment/src/test/java/io/quarkiverse/jasperreports/test/JasperreportsTest.java @@ -13,7 +13,7 @@ public class JasperreportsTest { // Start unit test with your extension loaded @RegisterExtension static final QuarkusUnitTest unitTest = new QuarkusUnitTest() - .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); @Test public void writeYourOwnUnitTest() { diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 00ea0ff..4be43b5 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -15,13 +15,18 @@ io.quarkus - quarkus-resteasy + quarkus-resteasy-reactive io.quarkiverse.jasperreports quarkus-jasperreports ${project.version} + + io.quarkiverse.poi + quarkus-poi + ${version.quarkus-poi} + io.quarkus quarkus-junit5 @@ -32,6 +37,11 @@ rest-assured test + + net.sf.jasperreports + jasperreports-fonts + ${version.jasperreports} + diff --git a/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperreportsResource.java b/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperreportsResource.java index 4340491..74aeb82 100644 --- a/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperreportsResource.java +++ b/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperreportsResource.java @@ -16,17 +16,324 @@ */ package io.quarkiverse.jasperreports.it; +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; + +import org.w3c.dom.Document; + +import io.quarkus.logging.Log; +import net.sf.jasperreports.engine.DefaultJasperReportsContext; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRParameter; +import net.sf.jasperreports.engine.JasperCompileManager; +import net.sf.jasperreports.engine.JasperPrint; +import net.sf.jasperreports.engine.JasperPrintManager; +import net.sf.jasperreports.engine.JasperReport; +import net.sf.jasperreports.engine.ReportContext; +import net.sf.jasperreports.engine.SimpleReportContext; +import net.sf.jasperreports.engine.design.JasperDesign; +import net.sf.jasperreports.engine.export.HtmlExporter; +import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRPdfExporter; +import net.sf.jasperreports.engine.export.JRRtfExporter; +import net.sf.jasperreports.engine.export.JRXlsExporter; +import net.sf.jasperreports.engine.export.JRXmlExporter; +import net.sf.jasperreports.engine.export.oasis.JROdsExporter; +import net.sf.jasperreports.engine.export.oasis.JROdtExporter; +import net.sf.jasperreports.engine.export.ooxml.JRDocxExporter; +import net.sf.jasperreports.engine.export.ooxml.JRPptxExporter; +import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; +import net.sf.jasperreports.engine.fill.JRFiller; +import net.sf.jasperreports.engine.fill.SimpleJasperReportSource; +import net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory; +import net.sf.jasperreports.engine.util.JRLoader; +import net.sf.jasperreports.engine.util.JRXmlUtils; +import net.sf.jasperreports.engine.xml.JRXmlLoader; +import net.sf.jasperreports.export.SimpleExporterInput; +import net.sf.jasperreports.export.SimpleHtmlExporterOutput; +import net.sf.jasperreports.export.SimpleOdsReportConfiguration; +import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput; +import net.sf.jasperreports.export.SimpleWriterExporterOutput; +import net.sf.jasperreports.export.SimpleXlsReportConfiguration; +import net.sf.jasperreports.export.SimpleXlsxReportConfiguration; +import net.sf.jasperreports.export.SimpleXmlExporterOutput; +import net.sf.jasperreports.repo.JasperDesignCache; +import net.sf.jasperreports.repo.SimpleRepositoryResourceContext; @Path("/jasperreports") @ApplicationScoped public class JasperreportsResource { - // add some rest methods here - @GET - public String hello() { - return "Hello jasperreports"; + private static final String TEST_REPORT_NAME = "CustomersReport"; + private static final String TEST_SUB_REPORT_NAME = "OrdersReport"; + + private JasperReport compile(String reportName) throws JRException { + long start = System.currentTimeMillis(); + JasperDesign jasperDesign = JRXmlLoader + .load(Thread.currentThread().getContextClassLoader().getResourceAsStream(reportName + ".jrxml")); + + JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); + + Log.info("Compilation time : " + (System.currentTimeMillis() - start)); + + return jasperReport; + } + + private JasperPrint fill() throws JRException { + long start = System.currentTimeMillis(); + + JasperReport mainReport = compile(TEST_REPORT_NAME); + JasperReport subReport = compile(TEST_SUB_REPORT_NAME); + + ReportContext reportContext = new SimpleReportContext(); + + Map params = new HashMap<>(); + Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream("northwind.xml")); + params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document); + params.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd"); + params.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##"); + params.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.ENGLISH); + params.put(JRParameter.REPORT_LOCALE, Locale.US); + params.put(JRParameter.REPORT_CONTEXT, reportContext); + + JasperDesignCache.getInstance(DefaultJasperReportsContext.getInstance(), reportContext).set("OrdersReport.jasper", + subReport); + + JasperPrint jasperPrint = JRFiller.fill(DefaultJasperReportsContext.getInstance(), + SimpleJasperReportSource.from(mainReport, null, new SimpleRepositoryResourceContext()), + params); + + Log.info("Filling time : " + (System.currentTimeMillis() - start)); + + return jasperPrint; + } + + @POST + @Path("print") + public void print() throws JRException { + long start = System.currentTimeMillis(); + JasperPrintManager.printReport("CustomersReport.jrprint", true); + Log.info("Printing time : " + (System.currentTimeMillis() - start)); + } + + @POST + @Path("pdf") + public byte[] pdf() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRPdfExporter exporter = new JRPdfExporter(DefaultJasperReportsContext.getInstance()); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + + exporter.exportReport(); + + Log.info("PDF creation time : " + (System.currentTimeMillis() - start)); + + return outputStream.toByteArray(); + } + + @POST + @Path("rtf") + public byte[] rtf() throws JRException { + long start = System.currentTimeMillis(); + + JasperPrint jasperPrint = fill(); + + JRRtfExporter exporter = new JRRtfExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleWriterExporterOutput(outputStream)); + + exporter.exportReport(); + + Log.info("RTF creation time : " + (System.currentTimeMillis() - start)); + + return outputStream.toByteArray(); + } + + @POST + @Path("xml") + public byte[] xml(@QueryParam("embedded") boolean embedded) throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRXmlExporter exporter = new JRXmlExporter(DefaultJasperReportsContext.getInstance()); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + SimpleXmlExporterOutput xmlOutput = new SimpleXmlExporterOutput(outputStream); + xmlOutput.setEmbeddingImages(embedded); + exporter.setExporterOutput(xmlOutput); + exporter.exportReport(); + Log.info("XML creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("html") + public byte[] html() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + HtmlExporter exporter = new HtmlExporter(DefaultJasperReportsContext.getInstance()); + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleHtmlExporterOutput(outputStream)); + + exporter.exportReport(); + Log.info("HTML creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("xls") + public byte[] xls() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRXlsExporter exporter = new JRXlsExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); + configuration.setOnePagePerSheet(true); + exporter.setConfiguration(configuration); + + exporter.exportReport(); + + Log.info("XLS creation time : " + (System.currentTimeMillis() - start)); + + return outputStream.toByteArray(); + } + + @POST + @Path("csv") + public byte[] csv() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRCsvExporter exporter = new JRCsvExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleWriterExporterOutput(outputStream)); + + exporter.exportReport(); + + Log.info("CSV creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("odt") + public byte[] odt() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JROdtExporter exporter = new JROdtExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + + exporter.exportReport(); + + Log.info("ODT creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("ods") + public byte[] ods() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JROdsExporter exporter = new JROdsExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration(); + configuration.setOnePagePerSheet(true); + exporter.setConfiguration(configuration); + + exporter.exportReport(); + + Log.info("ODS creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("docx") + public byte[] docx() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRDocxExporter exporter = new JRDocxExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + + exporter.exportReport(); + + Log.info("DOCX creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("xlsx") + public byte[] xlsx() throws JRException { + long start = System.currentTimeMillis(); + JasperPrint jasperPrint = fill(); + + JRXlsxExporter exporter = new JRXlsxExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); + configuration.setOnePagePerSheet(true); + exporter.setConfiguration(configuration); + + exporter.exportReport(); + + Log.info("XLSX creation time : " + (System.currentTimeMillis() - start)); + return outputStream.toByteArray(); + } + + @POST + @Path("pptx") + public byte[] pptx() throws JRException { + long start = System.currentTimeMillis(); + + JasperPrint jasperPrint = fill(); + + JRPptxExporter exporter = new JRPptxExporter(); + + exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); + + exporter.exportReport(); + + Log.info("PPTX creation time : " + (System.currentTimeMillis() - start)); + + return outputStream.toByteArray(); } } diff --git a/integration-tests/src/main/resources/CustomersReport.jrxml b/integration-tests/src/main/resources/CustomersReport.jrxml new file mode 100644 index 0000000..4467df1 --- /dev/null +++ b/integration-tests/src/main/resources/CustomersReport.jrxml @@ -0,0 +1,94 @@ + + +