refactor: standardize MIME handling via Spring MediaType (#4389)

This commit is contained in:
Ludy
2025-09-05 11:08:24 +01:00
committed by GitHub
parent f14955a019
commit 9a39aff19f
82 changed files with 310 additions and 164 deletions
@@ -3,6 +3,7 @@ package stirling.software.common.annotations;
import java.lang.annotation.*;
import org.springframework.core.annotation.AliasFor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -37,7 +38,7 @@ public @interface AutoJobPostMapping {
/** MIME types this endpoint accepts. Defaults to {@code multipart/form-data}. */
@AliasFor(annotation = RequestMapping.class, attribute = "consumes")
String[] consumes() default {"multipart/form-data"};
String[] consumes() default {MediaType.MULTIPART_FORM_DATA_VALUE};
/**
* Maximum execution time in milliseconds before the job is aborted. A negative value means "use
@@ -1,5 +1,6 @@
package stirling.software.common.model.api;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -14,7 +15,7 @@ import lombok.NoArgsConstructor;
public class PDFFile {
@Schema(
description = "The input PDF file",
contentMediaType = "application/pdf",
contentMediaType = MediaType.APPLICATION_PDF_VALUE,
format = "binary")
private MultipartFile fileInput;
@@ -227,7 +227,8 @@ public class JobExecutorService {
if (result instanceof byte[]) {
// Store byte array directly to disk to avoid double memory consumption
String fileId = fileStorage.storeBytes((byte[]) result, "result.pdf");
taskManager.setFileResult(jobId, fileId, "result.pdf", "application/pdf");
taskManager.setFileResult(
jobId, fileId, "result.pdf", MediaType.APPLICATION_PDF_VALUE);
log.debug("Stored byte[] result with fileId: {}", fileId);
// Let the byte array get collected naturally in the next GC cycle
@@ -239,7 +240,7 @@ public class JobExecutorService {
if (body instanceof byte[]) {
// Extract filename from content-disposition header if available
String filename = "result.pdf";
String contentType = "application/pdf";
String contentType = MediaType.APPLICATION_PDF_VALUE;
if (response.getHeaders().getContentDisposition() != null) {
String disposition =
@@ -276,7 +277,7 @@ public class JobExecutorService {
if (fileId != null && !fileId.isEmpty()) {
// Try to get filename and content type
String filename = "result.pdf";
String contentType = "application/pdf";
String contentType = MediaType.APPLICATION_PDF_VALUE;
try {
java.lang.reflect.Method getOriginalFileName =
@@ -317,8 +318,7 @@ public class JobExecutorService {
// Store generic result
taskManager.setResult(jobId, body);
}
} else if (result instanceof MultipartFile) {
MultipartFile file = (MultipartFile) result;
} else if (result instanceof MultipartFile file) {
String fileId = fileStorage.storeFile(file);
taskManager.setFileResult(
jobId, fileId, file.getOriginalFilename(), file.getContentType());
@@ -335,7 +335,7 @@ public class JobExecutorService {
if (fileId != null && !fileId.isEmpty()) {
// Try to get filename and content type
String filename = "result.pdf";
String contentType = "application/pdf";
String contentType = MediaType.APPLICATION_PDF_VALUE;
try {
java.lang.reflect.Method getOriginalFileName =
@@ -398,9 +398,8 @@ public class JobExecutorService {
HttpHeaders.CONTENT_DISPOSITION,
"form-data; name=\"attachment\"; filename=\"result.pdf\"")
.body(result);
} else if (result instanceof MultipartFile) {
} else if (result instanceof MultipartFile file) {
// Return MultipartFile content
MultipartFile file = (MultipartFile) result;
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getContentType()))
.header(
@@ -12,6 +12,8 @@ import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
import org.springframework.http.MediaType;
import lombok.Data;
import lombok.experimental.UtilityClass;
@@ -28,8 +30,8 @@ public class EmlParser {
Pattern.compile("=\\?([^?]+)\\?([BbQq])\\?([^?]*)\\?=");
private static final String DISPOSITION_ATTACHMENT = "attachment";
private static final String TEXT_PLAIN = "text/plain";
private static final String TEXT_HTML = "text/html";
private static final String TEXT_PLAIN = MediaType.TEXT_PLAIN_VALUE;
private static final String TEXT_HTML = MediaType.TEXT_HTML_VALUE;
private static final String MULTIPART_PREFIX = "multipart/";
private static final String HEADER_CONTENT_TYPE = "content-type:";
@@ -69,12 +71,12 @@ public class EmlParser {
if (isJakartaMailAvailable()) {
return extractEmailContentAdvanced(emlBytes, request, customHtmlSanitizer);
} else {
return extractEmailContentBasic(emlBytes, request, customHtmlSanitizer);
return extractEmailContentBasic(emlBytes, customHtmlSanitizer);
}
}
private static EmailContent extractEmailContentBasic(
byte[] emlBytes, EmlToPdfRequest request, CustomHtmlSanitizer customHtmlSanitizer) {
byte[] emlBytes, CustomHtmlSanitizer customHtmlSanitizer) {
String emlContent = new String(emlBytes, StandardCharsets.UTF_8);
EmailContent content = new EmailContent();
@@ -121,7 +123,7 @@ public class EmlParser {
return extractFromMimeMessage(message, request, customHtmlSanitizer);
} catch (ReflectiveOperationException e) {
return extractEmailContentBasic(emlBytes, request, customHtmlSanitizer);
return extractEmailContentBasic(emlBytes, customHtmlSanitizer);
}
}
@@ -8,6 +8,8 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.http.MediaType;
import lombok.experimental.UtilityClass;
import stirling.software.common.model.api.converters.EmlToPdfRequest;
@@ -33,10 +35,10 @@ public class EmlProcessingUtils {
// MIME type detection
private static final Map<String, String> EXTENSION_TO_MIME_TYPE =
Map.of(
".png", "image/png",
".jpg", "image/jpeg",
".jpeg", "image/jpeg",
".gif", "image/gif",
".png", MediaType.IMAGE_PNG_VALUE,
".jpg", MediaType.IMAGE_JPEG_VALUE,
".jpeg", MediaType.IMAGE_JPEG_VALUE,
".gif", MediaType.IMAGE_GIF_VALUE,
".bmp", "image/bmp",
".webp", "image/webp",
".svg", "image/svg+xml",
@@ -81,8 +83,8 @@ public class EmlProcessingUtils {
|| lowerContent.contains("bcc:");
boolean hasMimeStructure =
lowerContent.contains("multipart/")
|| lowerContent.contains("text/plain")
|| lowerContent.contains("text/html")
|| lowerContent.contains(MediaType.TEXT_PLAIN_VALUE)
|| lowerContent.contains(MediaType.TEXT_HTML_VALUE)
|| lowerContent.contains("boundary=");
int headerCount = 0;
@@ -464,7 +466,7 @@ public class EmlProcessingUtils {
}
}
return "image/png";
return MediaType.IMAGE_PNG_VALUE; // Default MIME type
}
public static String decodeUrlEncoded(String encoded) {
@@ -36,7 +36,7 @@ public class PDFToFile {
public ResponseEntity<byte[]> processPdfToMarkdown(MultipartFile inputFile)
throws IOException, InterruptedException {
if (!"application/pdf".equals(inputFile.getContentType())) {
if (!MediaType.APPLICATION_PDF_VALUE.equals(inputFile.getContentType())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@@ -153,7 +153,7 @@ public class PDFToFile {
public ResponseEntity<byte[]> processPdfToHtml(MultipartFile inputFile)
throws IOException, InterruptedException {
if (!"application/pdf".equals(inputFile.getContentType())) {
if (!MediaType.APPLICATION_PDF_VALUE.equals(inputFile.getContentType())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@@ -223,7 +223,7 @@ public class PDFToFile {
MultipartFile inputFile, String outputFormat, String libreOfficeFilter)
throws IOException, InterruptedException {
if (!"application/pdf".equals(inputFile.getContentType())) {
if (!MediaType.APPLICATION_PDF_VALUE.equals(inputFile.getContentType())) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@@ -37,6 +37,7 @@ import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.TextPosition;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
import lombok.Data;
@@ -118,7 +119,7 @@ public class PdfAttachmentHandler {
public String getContentType() {
return attachment.getContentType() != null
? attachment.getContentType()
: "application/octet-stream";
: MediaType.APPLICATION_OCTET_STREAM_VALUE;
}
@Override
@@ -29,6 +29,7 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.text.PDFTextStripper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
import io.github.pixee.security.Filenames;
@@ -156,7 +157,8 @@ public class PdfUtils {
if (DPI > maxSafeDpi) {
throw ExceptionUtils.createIllegalArgumentException(
"error.dpiExceedsLimit",
"DPI value {0} exceeds maximum safe limit of {1}. High DPI values can cause memory issues and crashes. Please use a lower DPI value.",
"DPI value {0} exceeds maximum safe limit of {1}. High DPI values can cause"
+ " memory issues and crashes. Please use a lower DPI value.",
DPI,
maxSafeDpi);
}
@@ -196,7 +198,9 @@ public class PdfUtils {
.contains("Maximum size of image exceeded")) {
throw ExceptionUtils.createIllegalArgumentException(
"error.pageTooBigForDpi",
"PDF page {0} is too large to render at {1} DPI. Please try a lower DPI value (recommended: 150 or less).",
"PDF page {0} is too large to render at {1} DPI. Please"
+ " try a lower DPI value (recommended: 150 or"
+ " less).",
i + 1,
DPI);
}
@@ -241,7 +245,10 @@ public class PdfUtils {
.contains("Maximum size of image exceeded")) {
throw ExceptionUtils.createIllegalArgumentException(
"error.pageTooBigExceedsArray",
"PDF page {0} is too large to render at {1} DPI. The resulting image would exceed Java's maximum array size. Please try a lower DPI value (recommended: 150 or less).",
"PDF page {0} is too large to render at {1} DPI. The"
+ " resulting image would exceed Java's maximum"
+ " array size. Please try a lower DPI value"
+ " (recommended: 150 or less).",
i + 1,
DPI);
}
@@ -282,7 +289,9 @@ public class PdfUtils {
.contains("Maximum size of image exceeded")) {
throw ExceptionUtils.createIllegalArgumentException(
"error.pageTooBigForDpi",
"PDF page {0} is too large to render at {1} DPI. Please try a lower DPI value (recommended: 150 or less).",
"PDF page {0} is too large to render at {1} DPI. Please"
+ " try a lower DPI value (recommended: 150 or"
+ " less).",
i + 1,
DPI);
}
@@ -315,7 +324,8 @@ public class PdfUtils {
&& e.getMessage().contains("Maximum size of image exceeded")) {
throw ExceptionUtils.createIllegalArgumentException(
"error.pageTooBigForDpi",
"PDF page {0} is too large to render at {1} DPI. Please try a lower DPI value (recommended: 150 or less).",
"PDF page {0} is too large to render at {1} DPI. Please try"
+ " a lower DPI value (recommended: 150 or less).",
i + 1,
DPI);
}
@@ -366,7 +376,9 @@ public class PdfUtils {
&& e.getMessage().contains("Maximum size of image exceeded")) {
throw ExceptionUtils.createIllegalArgumentException(
"error.pageTooBigFor300Dpi",
"PDF page {0} is too large to render at 300 DPI. The resulting image would exceed Java's maximum array size. Please use a lower DPI value for PDF-to-image conversion.",
"PDF page {0} is too large to render at 300 DPI. The resulting image"
+ " would exceed Java's maximum array size. Please use a lower DPI"
+ " value for PDF-to-image conversion.",
page + 1);
}
throw e;
@@ -435,7 +447,7 @@ public class PdfUtils {
ImageProcessingUtils.convertColorType(image, colorType);
// Use JPEGFactory if it's JPEG since JPEG is lossy
PDImageXObject pdImage =
(contentType != null && "image/jpeg".equals(contentType))
(contentType != null && MediaType.IMAGE_JPEG_VALUE.equals(contentType))
? JPEGFactory.createFromImage(doc, convertedImage)
: LosslessFactory.createFromImage(doc, convertedImage);
addImageToDocument(doc, pdImage, fitOption, autoRotate);
@@ -11,6 +11,7 @@ import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -23,7 +24,7 @@ class ApplicationPropertiesSaml2HttpTest {
server.enqueue(
new MockResponse()
.setResponseCode(200)
.addHeader("Content-Type", "application/xml")
.addHeader("Content-Type", MediaType.APPLICATION_XML_VALUE)
.setBody("<EntityDescriptor/>"));
server.start();
@@ -1,12 +1,12 @@
package stirling.software.common.service;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static stirling.software.common.service.SpyPDFDocumentFactory.*;
import java.io.*;
import java.nio.file.*;
import java.nio.file.Files;
import java.util.Arrays;
import org.apache.pdfbox.Loader;
@@ -18,9 +18,11 @@ import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import stirling.software.common.model.api.PDFFile;
import stirling.software.common.service.SpyPDFDocumentFactory.StrategyType;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -73,7 +75,7 @@ class CustomPDFDocumentFactoryTest {
void testStrategy_MultipartFile(int sizeMB, StrategyType expected) throws IOException {
byte[] inflated = inflatePdf(basePdfBytes, sizeMB);
MockMultipartFile multipart =
new MockMultipartFile("file", "doc.pdf", "application/pdf", inflated);
new MockMultipartFile("file", "doc.pdf", MediaType.APPLICATION_PDF_VALUE, inflated);
try (PDDocument doc = factory.load(multipart)) {
Assertions.assertEquals(expected, factory.lastStrategyUsed);
}
@@ -84,7 +86,7 @@ class CustomPDFDocumentFactoryTest {
void testStrategy_PDFFile(int sizeMB, StrategyType expected) throws IOException {
byte[] inflated = inflatePdf(basePdfBytes, sizeMB);
MockMultipartFile multipart =
new MockMultipartFile("file", "doc.pdf", "application/pdf", inflated);
new MockMultipartFile("file", "doc.pdf", MediaType.APPLICATION_PDF_VALUE, inflated);
PDFFile pdfFile = new PDFFile();
pdfFile.setFileInput(multipart);
try (PDDocument doc = factory.load(pdfFile)) {
@@ -2,6 +2,8 @@ package stirling.software.common.service;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.AdditionalAnswers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import java.io.IOException;
@@ -15,6 +17,7 @@ import org.junit.jupiter.api.io.TempDir;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -36,7 +39,7 @@ class FileStorageTest {
// Create a mock MultipartFile
mockFile = mock(MultipartFile.class);
when(mockFile.getOriginalFilename()).thenReturn("test.pdf");
when(mockFile.getContentType()).thenReturn("application/pdf");
when(mockFile.getContentType()).thenReturn(MediaType.APPLICATION_PDF_VALUE);
}
@Test
@@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import stirling.software.common.model.job.JobResult;
@@ -77,7 +78,7 @@ class TaskManagerTest {
taskManager.createTask(jobId);
String fileId = "file-id";
String originalFileName = "test.pdf";
String contentType = "application/pdf";
String contentType = MediaType.APPLICATION_PDF_VALUE;
long fileSize = 1024L;
// Mock the fileStorage.getFileSize() call
@@ -185,7 +186,8 @@ class TaskManagerTest {
// 2. Create completed successful job with file
String successFileJobId = "success-file-job";
taskManager.createTask(successFileJobId);
taskManager.setFileResult(successFileJobId, "file-id", "test.pdf", "application/pdf");
taskManager.setFileResult(
successFileJobId, "file-id", "test.pdf", MediaType.APPLICATION_PDF_VALUE);
// 3. Create completed successful job without file
String successJobId = "success-job";
@@ -235,7 +237,7 @@ class TaskManagerTest {
ResultFile.builder()
.fileId("file-id")
.fileName("test.pdf")
.contentType("application/pdf")
.contentType(MediaType.APPLICATION_PDF_VALUE)
.fileSize(1024L)
.build();
ReflectionTestUtils.setField(oldJob, "resultFiles", java.util.List.of(resultFile));
@@ -25,6 +25,7 @@ import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
@@ -57,7 +58,10 @@ class PDFToFileTest {
// Prepare
MultipartFile nonPdfFile =
new MockMultipartFile(
"file", "test.txt", "text/plain", "This is not a PDF".getBytes());
"file",
"test.txt",
MediaType.TEXT_PLAIN_VALUE,
"This is not a PDF".getBytes());
// Execute
ResponseEntity<byte[]> response = pdfToFile.processPdfToMarkdown(nonPdfFile);
@@ -71,7 +75,10 @@ class PDFToFileTest {
// Prepare
MultipartFile nonPdfFile =
new MockMultipartFile(
"file", "test.txt", "text/plain", "This is not a PDF".getBytes());
"file",
"test.txt",
MediaType.TEXT_PLAIN_VALUE,
"This is not a PDF".getBytes());
// Execute
ResponseEntity<byte[]> response = pdfToFile.processPdfToHtml(nonPdfFile);
@@ -86,7 +93,10 @@ class PDFToFileTest {
// Prepare
MultipartFile nonPdfFile =
new MockMultipartFile(
"file", "test.txt", "text/plain", "This is not a PDF".getBytes());
"file",
"test.txt",
MediaType.TEXT_PLAIN_VALUE,
"This is not a PDF".getBytes());
// Execute
ResponseEntity<byte[]> response =
@@ -102,7 +112,10 @@ class PDFToFileTest {
// Prepare
MultipartFile pdfFile =
new MockMultipartFile(
"file", "test.pdf", "application/pdf", "Fake PDF content".getBytes());
"file",
"test.pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Execute with invalid format
ResponseEntity<byte[]> response =
@@ -120,7 +133,10 @@ class PDFToFileTest {
// Create a mock PDF file
MultipartFile pdfFile =
new MockMultipartFile(
"file", "test.pdf", "application/pdf", "Fake PDF content".getBytes());
"file",
"test.pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Create a mock HTML output file
Path htmlOutputFile = tempDir.resolve("test.html");
@@ -168,7 +184,7 @@ class PDFToFileTest {
new MockMultipartFile(
"file",
"multipage.pdf",
"application/pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Setup ProcessExecutor mock
@@ -245,7 +261,10 @@ class PDFToFileTest {
// Create a mock PDF file
MultipartFile pdfFile =
new MockMultipartFile(
"file", "test.pdf", "application/pdf", "Fake PDF content".getBytes());
"file",
"test.pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Setup ProcessExecutor mock
mockedStaticProcessExecutor
@@ -324,7 +343,7 @@ class PDFToFileTest {
new MockMultipartFile(
"file",
"document.pdf",
"application/pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Setup ProcessExecutor mock
@@ -386,7 +405,7 @@ class PDFToFileTest {
new MockMultipartFile(
"file",
"document.pdf",
"application/pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Setup ProcessExecutor mock
@@ -472,7 +491,7 @@ class PDFToFileTest {
new MockMultipartFile(
"file",
"document.pdf",
"application/pdf",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Setup ProcessExecutor mock
@@ -531,7 +550,10 @@ class PDFToFileTest {
// Create a mock PDF file with no filename
MultipartFile pdfFile =
new MockMultipartFile(
"file", "", "application/pdf", "Fake PDF content".getBytes());
"file",
"",
MediaType.APPLICATION_PDF_VALUE,
"Fake PDF content".getBytes());
// Setup ProcessExecutor mock
mockedStaticProcessExecutor
@@ -48,7 +48,8 @@ public class WebResponseUtilsTest {
try {
byte[] fileContent = "Sample file content".getBytes();
MockMultipartFile file =
new MockMultipartFile("file", "sample.txt", "text/plain", fileContent);
new MockMultipartFile(
"file", "sample.txt", MediaType.TEXT_PLAIN_VALUE, fileContent);
ResponseEntity<byte[]> responseEntity =
WebResponseUtils.multiPartFileToWebResponse(file);
@@ -8,6 +8,7 @@ import java.lang.reflect.Method;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
@@ -24,7 +25,10 @@ class CustomColorReplaceStrategyTest {
// Create a mock file
mockFile =
new MockMultipartFile(
"file", "test.pdf", "application/pdf", "test pdf content".getBytes());
"file",
"test.pdf",
MediaType.APPLICATION_PDF_VALUE,
"test pdf content".getBytes());
// Initialize strategy with custom colors
strategy =
@@ -24,6 +24,7 @@ import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
@@ -38,7 +39,9 @@ class InvertFullColorStrategyTest {
void setUp() throws Exception {
// Create a simple PDF document for testing
byte[] pdfBytes = createSimplePdfWithRectangle();
mockPdfFile = new MockMultipartFile("file", "test.pdf", "application/pdf", pdfBytes);
mockPdfFile =
new MockMultipartFile(
"file", "test.pdf", MediaType.APPLICATION_PDF_VALUE, pdfBytes);
// Create the strategy instance
strategy = new InvertFullColorStrategy(mockPdfFile, ReplaceAndInvert.FULL_INVERSION);
@@ -7,6 +7,7 @@ import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
@@ -35,7 +36,10 @@ class ReplaceAndInvertColorStrategyTest {
// Arrange
MultipartFile mockFile =
new MockMultipartFile(
"file", "test.pdf", "application/pdf", "test content".getBytes());
"file",
"test.pdf",
MediaType.APPLICATION_PDF_VALUE,
"test content".getBytes());
ReplaceAndInvert replaceAndInvert = ReplaceAndInvert.CUSTOM_COLOR;
// Act
@@ -56,7 +60,7 @@ class ReplaceAndInvertColorStrategyTest {
// Arrange
byte[] content = "test pdf content".getBytes();
MultipartFile mockFile =
new MockMultipartFile("file", "test.pdf", "application/pdf", content);
new MockMultipartFile("file", "test.pdf", MediaType.APPLICATION_PDF_VALUE, content);
ReplaceAndInvert replaceAndInvert = ReplaceAndInvert.CUSTOM_COLOR;
ReplaceAndInvertColorStrategy strategy =
@@ -74,10 +78,16 @@ class ReplaceAndInvertColorStrategyTest {
// Arrange
MultipartFile mockFile1 =
new MockMultipartFile(
"file1", "test1.pdf", "application/pdf", "content1".getBytes());
"file1",
"test1.pdf",
MediaType.APPLICATION_PDF_VALUE,
"content1".getBytes());
MultipartFile mockFile2 =
new MockMultipartFile(
"file2", "test2.pdf", "application/pdf", "content2".getBytes());
"file2",
"test2.pdf",
MediaType.APPLICATION_PDF_VALUE,
"content2".getBytes());
// Act
ReplaceAndInvertColorStrategy strategy =