From a6ec45afca20e5bcc03b0bb198c05a928f0f2660 Mon Sep 17 00:00:00 2001
From: Felix Reichenbach <felix.reichenbach@mgm-tp.com>
Date: Mon, 17 Mar 2025 15:32:57 +0100
Subject: [PATCH] OZG-7573 implement FileService

---
 .../eingang/forwarder/FileService.java        |  5 ++-
 .../eingang/forwarder/FileServiceTest.java    | 39 +++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 forwarder/src/test/java/de/ozgcloud/eingang/forwarder/FileServiceTest.java

diff --git a/forwarder/src/main/java/de/ozgcloud/eingang/forwarder/FileService.java b/forwarder/src/main/java/de/ozgcloud/eingang/forwarder/FileService.java
index 862aba7b8..91dcc0d3e 100644
--- a/forwarder/src/main/java/de/ozgcloud/eingang/forwarder/FileService.java
+++ b/forwarder/src/main/java/de/ozgcloud/eingang/forwarder/FileService.java
@@ -30,13 +30,14 @@ import java.util.concurrent.CompletableFuture;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import de.ozgcloud.common.binaryfile.TempFileUtils;
+
 @Service
 class FileService {
 
 	@Async
 	public CompletableFuture<File> saveToFile(InputStream inputStream) {
-		// TODO Auto-generated method stub
-		throw new UnsupportedOperationException("Unimplemented method 'saveToFile'");
+		return CompletableFuture.completedFuture(TempFileUtils.writeTmpFile(inputStream));
 	}
 
 }
diff --git a/forwarder/src/test/java/de/ozgcloud/eingang/forwarder/FileServiceTest.java b/forwarder/src/test/java/de/ozgcloud/eingang/forwarder/FileServiceTest.java
new file mode 100644
index 000000000..795bcf585
--- /dev/null
+++ b/forwarder/src/test/java/de/ozgcloud/eingang/forwarder/FileServiceTest.java
@@ -0,0 +1,39 @@
+package de.ozgcloud.eingang.forwarder;
+
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.ByteArrayInputStream;
+import java.nio.file.Files;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.mockito.Spy;
+
+import com.thedeanda.lorem.LoremIpsum;
+
+import lombok.SneakyThrows;
+
+class FileServiceTest {
+
+	@Spy
+	private FileService service;
+
+	@Nested
+	class TestSaveToFile {
+
+		private final byte[] content = LoremIpsum.getInstance().getWords(100).getBytes();
+
+		@Test
+		@SneakyThrows
+		void shouldReturnFutureOfFile() {
+			try (var inputStream = new ByteArrayInputStream(content);) {
+				var fileFuture = service.saveToFile(inputStream);
+
+				var fileContent = Files.readAllBytes(fileFuture.get().toPath());
+				assertThat(fileContent).isEqualTo(content);
+
+			}
+		}
+
+	}
+}
-- 
GitLab