修复Excel转PDF转换边界问题

This commit is contained in:
andy
2026-07-16 18:36:45 +07:00
parent 8d53b72363
commit bc0413f21c
6 changed files with 159 additions and 10 deletions

View File

@@ -0,0 +1,38 @@
package cn.nianxx.thhotel.integrations.document.libreoffice.adapter;
import cn.nianxx.thhotel.platform.documentconversion.service.DocumentConversionException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
class ProcessBuilderLibreOfficeProcessRunnerTest {
@TempDir
private Path tempDir;
@Test
void shouldRestoreInterruptFlagWhenInterruptedDuringLibreOfficeWait() {
ProcessBuilderLibreOfficeProcessRunner runner = new ProcessBuilderLibreOfficeProcessRunner();
LibreOfficeProcessRequest request = new LibreOfficeProcessRequest(
List.of("/bin/sh", "-c", "sleep 5"),
tempDir,
tempDir.resolve("source.xlsx"),
tempDir,
tempDir.resolve("lo-profile"),
Duration.ofSeconds(30));
Thread.currentThread().interrupt();
try {
org.assertj.core.api.Assertions.assertThatThrownBy(() -> runner.run(request))
.isInstanceOf(DocumentConversionException.class)
.satisfies(exception -> org.assertj.core.api.Assertions.assertThat(
((DocumentConversionException) exception).getErrorCode())
.isEqualTo("DOCUMENT_CONVERSION_FAILED"));
org.assertj.core.api.Assertions.assertThat(Thread.currentThread().isInterrupted()).isTrue();
} finally {
Thread.interrupted();
}
}
}

View File

@@ -0,0 +1,25 @@
package cn.nianxx.thhotel.platform.documentconversion.control;
import cn.nianxx.thhotel.platform.documentconversion.common.result.DocumentConversionErrorResponse;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
class DocumentConversionControllerAdviceTest {
@Test
void shouldMapFrameworkUploadLimitToSafeJsonError() {
DocumentConversionControllerAdvice advice = new DocumentConversionControllerAdvice();
ResponseEntity<DocumentConversionErrorResponse> response =
advice.handleMaxUploadSizeExceeded(new MaxUploadSizeExceededException(1024));
org.assertj.core.api.Assertions.assertThat(response.getStatusCode())
.isEqualTo(HttpStatus.PAYLOAD_TOO_LARGE);
org.assertj.core.api.Assertions.assertThat(response.getBody())
.isNotNull()
.extracting(DocumentConversionErrorResponse::errorCode)
.isEqualTo("DOCUMENT_CONVERSION_FILE_TOO_LARGE");
}
}

View File

@@ -0,0 +1,22 @@
package cn.nianxx.thhotel.platform.documentconversion.service.impl;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;
class DocumentConversionConfigurationTest {
@Test
void shouldAllowProdProfileToStartWithoutDocumentConversionAccessKeyWhenDisabled() throws IOException {
YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
PropertySource<?> propertySource = loader.load(
"application-prod",
new ClassPathResource("application-prod.yml"))
.get(0);
org.assertj.core.api.Assertions.assertThat(propertySource.getProperty("document-conversion.access-key"))
.isEqualTo("${DOCUMENT_CONVERSION_PROD_ACCESS_KEY:${DOCUMENT_CONVERSION_ACCESS_KEY:}}");
}
}