Skip to content

Commit

Permalink
✅ (195): Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Klaus committed Dec 19, 2024
1 parent b2c76bc commit 4864460
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Long> bommelId
@RestForm @PartType(MediaType.TEXT_PLAIN) Optional<Long> bommelId,
@RestForm @PartType(MediaType.TEXT_PLAIN) Optional<String> type
) {
s3Handler.saveFile(file);

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class DocumentProducer {
@Channel("document-out")
Emitter<DocumentData> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4864460

Please sign in to comment.