This is an automated email from the ASF dual-hosted git repository.
apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new a34480d633 Provide basic test for pdf:merge
a34480d633 is described below
commit a34480d63356d3041f93c05c64fe4ddaacfaa402
Author: Aurélien Pupier <[email protected]>
AuthorDate: Mon Jan 5 15:51:33 2026 +0100
Provide basic test for pdf:merge
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../quarkus/component/pdf/it/PdfResource.java | 15 +++++++++++
.../camel/quarkus/component/pdf/it/PdfTest.java | 30 ++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git
a/integration-tests/pdf/src/main/java/org/apache/camel/quarkus/component/pdf/it/PdfResource.java
b/integration-tests/pdf/src/main/java/org/apache/camel/quarkus/component/pdf/it/PdfResource.java
index 6f3b486a4f..3a212c5020 100644
---
a/integration-tests/pdf/src/main/java/org/apache/camel/quarkus/component/pdf/it/PdfResource.java
+++
b/integration-tests/pdf/src/main/java/org/apache/camel/quarkus/component/pdf/it/PdfResource.java
@@ -16,8 +16,10 @@
*/
package org.apache.camel.quarkus.component.pdf.it;
+import java.io.File;
import java.io.IOException;
import java.net.URI;
+import java.util.List;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -122,4 +124,17 @@ public class PdfResource {
return Response.ok().entity(result).build();
}
+
+ @Path("/merge")
+ @POST
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response merge(@QueryParam("firstPdf") String firstPdf,
@QueryParam("secondPdf") String secondPdf) throws Exception {
+ document = producerTemplate.requestBodyAndHeader(
+ "pdf:merge", null,
PdfHeaderConstants.FILES_TO_MERGE_HEADER_NAME,
+ List.of(new File(firstPdf), new File(secondPdf)),
byte[].class);
+
+ LOG.infof("The PDDocument has been merged and contains %d bytes",
document.length);
+
+ return Response.created(new URI("pdf/merge")).entity(document).build();
+ }
}
diff --git
a/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
b/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
index 2775659d2c..0001eb1473 100644
---
a/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
+++
b/integration-tests/pdf/src/test/java/org/apache/camel/quarkus/component/pdf/it/PdfTest.java
@@ -17,6 +17,8 @@
package org.apache.camel.quarkus.component.pdf.it;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
@@ -84,6 +86,34 @@ class PdfTest {
assertTrue(pdfText.contains("another line that should be appended"));
}
+ @Test
+ public void merge() throws IOException {
+ byte[] bytesFirstPDF =
RestAssured.given().contentType(ContentType.TEXT)
+ .body("first
content").post("/pdf/createFromText").then().statusCode(201)
+ .extract().asByteArray();
+ Path firstPdfPath = Files.createTempFile("firstPdf", ".pdf");
+ Files.write(firstPdfPath, bytesFirstPDF);
+ byte[] bytesSecondPDF =
RestAssured.given().contentType(ContentType.TEXT)
+ .body("second
content").post("/pdf/createFromText").then().statusCode(201)
+ .extract().asByteArray();
+ Path secondPdfPath = Files.createTempFile("secondPdf", ".pdf");
+ Files.write(secondPdfPath, bytesSecondPDF);
+
+ byte[] bytesMergedPDF = RestAssured.given()
+ .queryParam("firstPdf", firstPdfPath.toString())
+ .queryParam("secondPdf", secondPdfPath.toString())
+ .post("/pdf/merge").then().statusCode(201)
+ .extract().asByteArray();
+
+ PDDocument doc = Loader.loadPDF(bytesMergedPDF);
+ PDFTextStripper pdfTextStripper = new PDFTextStripper();
+ String text = pdfTextStripper.getText(doc);
+ assertEquals(2, doc.getNumberOfPages());
+ assertTrue(text.contains("first content\nsecond content"));
+
+ doc.close();
+ }
+
@Test
public void encryptDecrypt() throws IOException {
final String ownerPassword = "p4ssw0rd";