From 4c68f544b66a61f57d39f6534be2d804ab6df633 Mon Sep 17 00:00:00 2001
From: Riegel <alexander.riegel@hft-stuttgart.de>
Date: Wed, 27 Nov 2024 17:00:03 +0100
Subject: [PATCH] Test: Add test for excessive filesize

---
 .../citydoctor2/ziploader/ZipTest.java        | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/CityDoctorParent/Extensions/CityDoctorZipLoader/src/test/java/de/hft/stuttgart/citydoctor2/ziploader/ZipTest.java b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/test/java/de/hft/stuttgart/citydoctor2/ziploader/ZipTest.java
index d4403c0..c024e11 100644
--- a/CityDoctorParent/Extensions/CityDoctorZipLoader/src/test/java/de/hft/stuttgart/citydoctor2/ziploader/ZipTest.java
+++ b/CityDoctorParent/Extensions/CityDoctorZipLoader/src/test/java/de/hft/stuttgart/citydoctor2/ziploader/ZipTest.java
@@ -8,8 +8,10 @@ import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.zip.ZipEntry;
 
 import static org.junit.Assert.*;
 
@@ -40,6 +42,21 @@ public class ZipTest {
         cgmlArch.exportToZipFile("src/test/resources/mock");
     }
 
+    @Test
+    public void testExcessiveFilesize(){
+        ZipEntry zipEntry = Mockito.mock(ZipEntry.class);
+        Path mockPath = Mockito.mock(Path.class);
+        InputStream mockIs = Mockito.mock(InputStream.class);
+        // Mock filesize of 30 Gb
+        Mockito.when(zipEntry.getSize()).thenReturn(1024L*1024L*30);
+        Mockito.when(zipEntry.getName()).thenReturn("mock.gml");
+        CityGmlZipEntry cgmlZE = CityGmlZipEntry.of(zipEntry, config, "test", mockPath, mockIs);
+        assertNotNull(cgmlZE);
+        assertTrue(cgmlZE.isErroneousEntry());
+        assertEquals(CityGmlZipEntry.ZipEntryErrorType.EXCESSIVE_FILESIZE, cgmlZE.getErrorType());
+
+    }
+
     @Test
     public void testZipping() throws IOException {
         CityGmlArchive cgmlArch = CityGmlArchive.fromZipFile("src/test/resources/mock_archive.zip", config);
@@ -53,7 +70,7 @@ public class ZipTest {
             assertNotNull(cgmlExport);
             assertEquals(5, cgmlExport.getEntries().size());
         } catch (Exception e) {
-            // Rethrow Exceptions to ensure deletion of tmpDir with finally
+            // Rethrow Exceptions to ensure deletion of tmpDir with finally block
             throw e;
         } finally {
             if (tmpDir != null) {
-- 
GitLab