|
|
@@ -1,44 +0,0 @@
|
|
|
-package com.platform.api.manager;
|
|
|
-
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
-import org.springframework.test.util.ReflectionTestUtils;
|
|
|
-
|
|
|
-import java.nio.file.Files;
|
|
|
-import java.nio.file.Path;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
-
|
|
|
-class UploadServiceTest {
|
|
|
-
|
|
|
- @Test
|
|
|
- void processBase64ImagesToLocalAsyncShouldExtractDataUrlPayload() throws Exception {
|
|
|
- UploadService uploadService = new UploadService();
|
|
|
- Path storagePath = Files.createTempDirectory("weighbridge-images");
|
|
|
- ReflectionTestUtils.setField(uploadService, "imageStoragePath", storagePath.toString());
|
|
|
-
|
|
|
- String image = "\"data:image/png;base64,iVBORw0KGgo=\\n\"]}";
|
|
|
- String savedPath = uploadService.processBase64ImagesToLocalAsync(List.of(image), "test")
|
|
|
- .get();
|
|
|
-
|
|
|
- Path path = Path.of(savedPath);
|
|
|
- assertTrue(Files.exists(path));
|
|
|
- assertTrue(path.getFileName().toString().endsWith(".png"));
|
|
|
- assertArrayEquals(new byte[]{
|
|
|
- (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A
|
|
|
- }, Files.readAllBytes(path));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void processBase64ImagesToLocalAsyncShouldHandleSpaceConvertedPlusSign() throws Exception {
|
|
|
- UploadService uploadService = new UploadService();
|
|
|
- Path storagePath = Files.createTempDirectory("weighbridge-images");
|
|
|
- ReflectionTestUtils.setField(uploadService, "imageStoragePath", storagePath.toString());
|
|
|
-
|
|
|
- String savedPath = uploadService.processBase64ImagesToLocalAsync(List.of("data:image/jpeg;base64, w=="), "test")
|
|
|
- .get();
|
|
|
-
|
|
|
- assertArrayEquals(new byte[]{(byte) 0xFB}, Files.readAllBytes(Path.of(savedPath)));
|
|
|
- }
|
|
|
-}
|