From 486446002f0ce43e0e674395bca8379558ad7964 Mon Sep 17 00:00:00 2001 From: Manuel Klaus Date: Thu, 19 Dec 2024 23:16:07 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20(195):=20Fix=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/hopps/fin/endpoint/DocumentResource.java | 13 ++++++++++--- .../java/app/hopps/fin/kafka/DocumentProducer.java | 4 ++-- .../app/hopps/fin/kafka/model/DocumentData.java | 2 +- .../hopps/fin/endpoint/DocumentResourceTest.java | 5 +---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend/app.hopps.fin/src/main/java/app/hopps/fin/endpoint/DocumentResource.java b/backend/app.hopps.fin/src/main/java/app/hopps/fin/endpoint/DocumentResource.java index 9024e440..4badc0d5 100644 --- a/backend/app.hopps.fin/src/main/java/app/hopps/fin/endpoint/DocumentResource.java +++ b/backend/app.hopps.fin/src/main/java/app/hopps/fin/endpoint/DocumentResource.java @@ -5,6 +5,7 @@ import app.hopps.fin.jpa.entities.TransactionRecord; import app.hopps.fin.kafka.DocumentProducer; import jakarta.inject.Inject; +import jakarta.transaction.Transactional; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; @@ -54,7 +55,8 @@ public InputStream getDocumentByKey(@PathParam("documentKey") String documentKey @Produces(MediaType.APPLICATION_JSON) public Response uploadDocument( @RestForm("file") FileUpload file, - @RestForm @PartType(MediaType.TEXT_PLAIN) Optional bommelId + @RestForm @PartType(MediaType.TEXT_PLAIN) Optional bommelId, + @RestForm @PartType(MediaType.TEXT_PLAIN) Optional type ) { s3Handler.saveFile(file); @@ -63,11 +65,16 @@ public Response uploadDocument( transactionRecord.setDocumentKey(file.fileName()); bommelId.ifPresent(transactionRecord::setBommelId); - repository.persist(transactionRecord); + persistTransactionRecord(transactionRecord); // Sent to kafka to process - documentProducer.sendToProcess(transactionRecord); + documentProducer.sendToProcess(transactionRecord, type.orElse("invoice")); return Response.accepted().build(); } + + @Transactional + void persistTransactionRecord(TransactionRecord transactionRecord) { + repository.persist(transactionRecord); + } } diff --git a/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/DocumentProducer.java b/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/DocumentProducer.java index e45f2dcf..0cf6756f 100644 --- a/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/DocumentProducer.java +++ b/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/DocumentProducer.java @@ -11,9 +11,9 @@ public class DocumentProducer { @Channel("document-out") Emitter documentEmitter; - public void sendToProcess(TransactionRecord transactionRecord) { + public void sendToProcess(TransactionRecord transactionRecord, String type) { String internalFinUrl = "http://fin/document/" + transactionRecord.getDocumentKey(); - DocumentData documentData = new DocumentData(internalFinUrl, transactionRecord.getId()); + DocumentData documentData = new DocumentData(internalFinUrl, transactionRecord.getId(), type); documentEmitter.send(documentData); } } diff --git a/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/model/DocumentData.java b/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/model/DocumentData.java index c9841fb7..77f6f3e3 100644 --- a/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/model/DocumentData.java +++ b/backend/app.hopps.fin/src/main/java/app/hopps/fin/kafka/model/DocumentData.java @@ -1,4 +1,4 @@ package app.hopps.fin.kafka.model; -public record DocumentData(String internalFinUrl, Long referenceKey) { +public record DocumentData(String internalFinUrl, Long referenceKey, String type) { } diff --git a/backend/app.hopps.fin/src/test/java/app/hopps/fin/endpoint/DocumentResourceTest.java b/backend/app.hopps.fin/src/test/java/app/hopps/fin/endpoint/DocumentResourceTest.java index 2aef057b..daf4c31e 100644 --- a/backend/app.hopps.fin/src/test/java/app/hopps/fin/endpoint/DocumentResourceTest.java +++ b/backend/app.hopps.fin/src/test/java/app/hopps/fin/endpoint/DocumentResourceTest.java @@ -9,7 +9,6 @@ import org.eclipse.microprofile.config.inject.ConfigProperty; import org.flywaydb.core.Flyway; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import software.amazon.awssdk.core.sync.RequestBody; import software.amazon.awssdk.services.s3.S3Client; @@ -68,14 +67,12 @@ void shouldGetFile() { } @Test - @Disabled("ByteArrayInputStream serialization error") void shouldUploadFile() { InputStream zugferdInputStream = getClass().getClassLoader().getResourceAsStream("ZUGFeRD.pdf"); given() .contentType(MediaType.MULTIPART_FORM_DATA) - .accept(MediaType.APPLICATION_JSON) - .multiPart("file", zugferdInputStream) + .multiPart("file", "ZUGFeRD.pdf", zugferdInputStream) .when() .post() .then()