1
0

Optimierung: Anwendungskonfiguration auf Minimalbedarf zugeschnitten

This commit is contained in:
2026-04-05 09:45:31 +02:00
parent 7764a50308
commit 3657b0c3de
8 changed files with 103 additions and 146 deletions

View File

@@ -1,6 +1,6 @@
package de.gecheckt.pdf.umbenenner.application.service;
import de.gecheckt.pdf.umbenenner.application.config.StartConfiguration;
import de.gecheckt.pdf.umbenenner.application.config.RuntimeConfiguration;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentProcessingOutcome;
import de.gecheckt.pdf.umbenenner.domain.model.PreCheckFailed;
import de.gecheckt.pdf.umbenenner.domain.model.PreCheckFailureReason;
@@ -34,7 +34,7 @@ class DocumentProcessingServiceTest {
Path tempDir;
private SourceDocumentCandidate candidate;
private StartConfiguration configuration;
private RuntimeConfiguration runtimeConfig;
@BeforeEach
void setUp() throws Exception {
@@ -44,30 +44,8 @@ class DocumentProcessingServiceTest {
SourceDocumentLocator locator = new SourceDocumentLocator(pdfFile.toString());
candidate = new SourceDocumentCandidate("document.pdf", 2048L, locator);
// Create directories and files for configuration
Path sourceDir = Files.createDirectories(tempDir.resolve("source"));
Path targetDir = Files.createDirectories(tempDir.resolve("target"));
Path dbFile = tempDir.resolve("db.sqlite");
Files.createFile(dbFile);
Path promptFile = tempDir.resolve("prompt.txt");
Files.createFile(promptFile);
configuration = new StartConfiguration(
sourceDir,
targetDir,
dbFile,
URI.create("http://localhost:8000"),
"gpt-4",
30,
3,
10,
5000,
promptFile,
tempDir.resolve("lock"),
tempDir.resolve("logs"),
"INFO",
"test-key"
);
// Create runtime configuration with maxPages limit
runtimeConfig = new RuntimeConfiguration(10);
}
@Test
@@ -77,7 +55,7 @@ class DocumentProcessingServiceTest {
// Act
DocumentProcessingOutcome outcome = DocumentProcessingService.processDocument(
candidate, extraction, configuration);
candidate, extraction, runtimeConfig);
// Assert: Should produce PreCheckPassed
assertInstanceOf(PreCheckPassed.class, outcome);
@@ -93,7 +71,7 @@ class DocumentProcessingServiceTest {
// Act
DocumentProcessingOutcome outcome = DocumentProcessingService.processDocument(
candidate, extraction, configuration);
candidate, extraction, runtimeConfig);
// Assert: Should produce PreCheckFailed with appropriate reason
assertInstanceOf(PreCheckFailed.class, outcome);
@@ -109,7 +87,7 @@ class DocumentProcessingServiceTest {
// Act
DocumentProcessingOutcome outcome = DocumentProcessingService.processDocument(
candidate, extraction, configuration);
candidate, extraction, runtimeConfig);
// Assert: Should produce PreCheckFailed with page limit reason
assertInstanceOf(PreCheckFailed.class, outcome);
@@ -125,7 +103,7 @@ class DocumentProcessingServiceTest {
// Act
DocumentProcessingOutcome outcome = DocumentProcessingService.processDocument(
candidate, contentError, configuration);
candidate, contentError, runtimeConfig);
// Assert: Should produce PreCheckFailed
assertInstanceOf(PreCheckFailed.class, outcome);
@@ -142,7 +120,7 @@ class DocumentProcessingServiceTest {
// Act
DocumentProcessingOutcome outcome = DocumentProcessingService.processDocument(
candidate, technicalError, configuration);
candidate, technicalError, runtimeConfig);
// Assert: Should produce TechnicalDocumentError
assertInstanceOf(TechnicalDocumentError.class, outcome);
@@ -159,7 +137,7 @@ class DocumentProcessingServiceTest {
// Act
DocumentProcessingOutcome outcome = DocumentProcessingService.processDocument(
candidate, technicalError, configuration);
candidate, technicalError, runtimeConfig);
// Assert
assertInstanceOf(TechnicalDocumentError.class, outcome);
@@ -174,14 +152,14 @@ class DocumentProcessingServiceTest {
// Act & Assert
assertThrows(NullPointerException.class,
() -> DocumentProcessingService.processDocument(null, extraction, configuration));
() -> DocumentProcessingService.processDocument(null, extraction, runtimeConfig));
}
@Test
void testProcessDocument_WithNullExtractionResult_ThrowsException() {
// Act & Assert
assertThrows(NullPointerException.class,
() -> DocumentProcessingService.processDocument(candidate, null, configuration));
() -> DocumentProcessingService.processDocument(candidate, null, runtimeConfig));
}
@Test

View File

@@ -1,6 +1,6 @@
package de.gecheckt.pdf.umbenenner.application.service;
import de.gecheckt.pdf.umbenenner.application.config.StartConfiguration;
import de.gecheckt.pdf.umbenenner.application.config.RuntimeConfiguration;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentProcessingOutcome;
import de.gecheckt.pdf.umbenenner.domain.model.PreCheckFailed;
import de.gecheckt.pdf.umbenenner.domain.model.PreCheckFailureReason;
@@ -31,7 +31,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWhenDocumentHasUsableTextAndValidPageCount() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Some meaningful text", new PdfPageCount(5));
@@ -45,7 +45,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_failsWithNoUsableTextWhenExtractedTextIsEmpty() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("", new PdfPageCount(1));
@@ -58,7 +58,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_failsWithNoUsableTextWhenTextIsOnlyWhitespace() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess(" \n\t \r\n ", new PdfPageCount(1));
@@ -71,7 +71,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_failsWithNoUsableTextWhenTextContainsOnlySpecialCharacters() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("!@#$%^&*()_+-=[]{}|;:',.<>?/", new PdfPageCount(1));
@@ -84,7 +84,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWithTextContainingSingleLetter() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("a", new PdfPageCount(1));
@@ -95,7 +95,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWithTextContainingSingleDigit() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("5", new PdfPageCount(1));
@@ -106,7 +106,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWithTextMixedWithSpecialCharactersIfLettersOrDigitsPresent() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("!@#a$%^&*", new PdfPageCount(1));
@@ -117,7 +117,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWithWhitespaceAroundUsableText() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess(" meaningful text ", new PdfPageCount(1));
@@ -128,7 +128,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_failsWithPageLimitExceededWhenPageCountEqualsLimit() throws Exception {
StartConfiguration config = buildConfig(maxPages(5));
RuntimeConfiguration config = buildConfig(maxPages(5));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Valid text", new PdfPageCount(5));
@@ -139,7 +139,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_failsWithPageLimitExceededWhenPageCountExceedsLimit() throws Exception {
StartConfiguration config = buildConfig(maxPages(5));
RuntimeConfiguration config = buildConfig(maxPages(5));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Valid text", new PdfPageCount(6));
@@ -152,7 +152,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_failsWithPageLimitExceededEvenIfTextIsValid() throws Exception {
StartConfiguration config = buildConfig(maxPages(2));
RuntimeConfiguration config = buildConfig(maxPages(2));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Excellent meaningful text with lots of content", new PdfPageCount(100));
@@ -167,7 +167,7 @@ class PreCheckEvaluatorTest {
void evaluate_prefersPageLimitCheckOverTextCheck() throws Exception {
// If both checks fail, page limit check should take precedence (not tested for priority,
// but we verify that one failure is reported consistently)
StartConfiguration config = buildConfig(maxPages(1));
RuntimeConfiguration config = buildConfig(maxPages(1));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("", new PdfPageCount(10));
@@ -181,7 +181,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_throwsNullPointerExceptionWhenCandidateIsNull() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Valid text", new PdfPageCount(1));
assertThrows(NullPointerException.class, () ->
@@ -191,7 +191,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_throwsNullPointerExceptionWhenExtractionIsNull() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
assertThrows(NullPointerException.class, () ->
@@ -211,7 +211,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWithUnicodeGermanUmlauts() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Äußerst äöüß Großes", new PdfPageCount(1));
@@ -222,7 +222,7 @@ class PreCheckEvaluatorTest {
@Test
void evaluate_passesWithOtherUnicodeCharacters() throws Exception {
StartConfiguration config = buildConfig(maxPages(10));
RuntimeConfiguration config = buildConfig(maxPages(10));
SourceDocumentCandidate candidate = buildCandidate();
PdfExtractionSuccess extraction = new PdfExtractionSuccess("Αβγδ 中文 καλημέρα", new PdfPageCount(1));
@@ -235,30 +235,8 @@ class PreCheckEvaluatorTest {
// Helpers
// =========================================================================
private StartConfiguration buildConfig(int maxPages) throws Exception {
Path sourceDir = Files.createDirectories(tempDir.resolve("source"));
Path targetDir = Files.createDirectories(tempDir.resolve("target"));
Path dbFile = tempDir.resolve("db.sqlite");
Files.createFile(dbFile);
Path promptFile = tempDir.resolve("prompt.txt");
Files.createFile(promptFile);
return new StartConfiguration(
sourceDir,
targetDir,
dbFile,
URI.create("https://api.example.com"),
"gpt-4",
30,
3,
maxPages,
50000,
promptFile,
tempDir.resolve("lock.lock"),
tempDir.resolve("logs"),
"INFO",
"test-key"
);
private RuntimeConfiguration buildConfig(int maxPages) throws Exception {
return new RuntimeConfiguration(maxPages);
}
private int maxPages(int limit) {

View File

@@ -1,6 +1,6 @@
package de.gecheckt.pdf.umbenenner.application.usecase;
import de.gecheckt.pdf.umbenenner.application.config.StartConfiguration;
import de.gecheckt.pdf.umbenenner.application.config.RuntimeConfiguration;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunOutcome;
import de.gecheckt.pdf.umbenenner.application.port.out.DocumentRecord;
import de.gecheckt.pdf.umbenenner.application.port.out.DocumentRecordLookupResult;
@@ -71,7 +71,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_successfullyAcquiresAndReleasesLock() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
DefaultBatchRunProcessingUseCase useCase = buildUseCase(
config, lockPort, new EmptyCandidatesPort(), new NoOpExtractionPort(),
@@ -88,7 +88,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_returnsLockUnavailableWhenLockCannotBeAcquired() throws Exception {
CountingRunLockPort lockPort = new CountingRunLockPort(true);
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
DefaultBatchRunProcessingUseCase useCase = buildUseCase(
config, lockPort, new EmptyCandidatesPort(), new NoOpExtractionPort(),
@@ -108,7 +108,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_doesNotReleaseLockWhenAcquireFails() throws Exception {
CountingRunLockPort lockPort = new CountingRunLockPort(true);
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
DefaultBatchRunProcessingUseCase useCase = buildUseCase(
config, lockPort, new EmptyCandidatesPort(), new NoOpExtractionPort(),
@@ -125,7 +125,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_releasesLockEvenOnUnexpectedError() throws Exception {
ErrorAfterAcquireLockPort lockPort = new ErrorAfterAcquireLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
DefaultBatchRunProcessingUseCase useCase = buildUseCase(
config, lockPort, new EmptyCandidatesPort(), new NoOpExtractionPort(),
@@ -146,7 +146,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_withNoCandidates_returnsSuccess() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
DefaultBatchRunProcessingUseCase useCase = buildUseCase(
config, lockPort, new EmptyCandidatesPort(), new NoOpExtractionPort(),
@@ -161,7 +161,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_happyPath_candidatePassesPreChecks_persistenceInvoked() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("document.pdf");
PdfExtractionSuccess success = new PdfExtractionSuccess("Invoice text", new PdfPageCount(1));
@@ -184,7 +184,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_noUsableText_candidateEndsControlled_batchContinues() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("image-only.pdf");
PdfExtractionSuccess emptySuccess = new PdfExtractionSuccess(" ", new PdfPageCount(1));
@@ -206,7 +206,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_pageLimitExceeded_candidateEndsControlled_batchContinues() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("big.pdf");
PdfExtractionSuccess manyPages = new PdfExtractionSuccess("Some text", new PdfPageCount(10));
@@ -228,7 +228,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_extractionContentError_candidateEndsControlled_batchContinues() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("encrypted.pdf");
PdfExtractionContentError contentError = new PdfExtractionContentError("PDF is encrypted");
@@ -250,7 +250,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_extractionTechnicalError_candidateEndsControlled_batchContinues() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("corrupt.pdf");
PdfExtractionTechnicalError technicalError = new PdfExtractionTechnicalError("I/O error reading file", null);
@@ -272,7 +272,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_sourceAccessException_returnsFailure() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidatesPort failingPort = () -> {
throw new SourceDocumentAccessException("Source folder not readable");
@@ -297,7 +297,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_fingerprintFailure_candidateNotHistorised_batchContinues() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("unreadable.pdf");
FixedCandidatesPort candidatesPort = new FixedCandidatesPort(List.of(candidate));
@@ -322,7 +322,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_fingerprintFailure_extractionNotCalled() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate candidate = makeCandidate("unreadable.pdf");
FixedCandidatesPort candidatesPort = new FixedCandidatesPort(List.of(candidate));
@@ -350,7 +350,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_mixedBatch_allOutcomeTypes_batchOverallSucceeds() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
SourceDocumentCandidate goodCandidate = makeCandidate("good.pdf");
SourceDocumentCandidate noTextCandidate = makeCandidate("notext.pdf");
@@ -400,7 +400,7 @@ class BatchRunProcessingUseCaseTest {
@Test
void execute_multipleCandidates_allProcessed_batchSucceeds() throws Exception {
MockRunLockPort lockPort = new MockRunLockPort();
StartConfiguration config = buildConfig(tempDir);
RuntimeConfiguration config = buildConfig(tempDir);
List<SourceDocumentCandidate> candidates = List.of(
makeCandidate("a.pdf"),
@@ -429,41 +429,20 @@ class BatchRunProcessingUseCaseTest {
// -------------------------------------------------------------------------
private static DefaultBatchRunProcessingUseCase buildUseCase(
StartConfiguration config,
RuntimeConfiguration runtimeConfig,
RunLockPort lockPort,
SourceDocumentCandidatesPort candidatesPort,
PdfTextExtractionPort extractionPort,
FingerprintPort fingerprintPort,
DocumentProcessingCoordinator processor) {
return new DefaultBatchRunProcessingUseCase(
config, lockPort, candidatesPort, extractionPort, fingerprintPort, processor,
runtimeConfig, lockPort, candidatesPort, extractionPort, fingerprintPort, processor,
new NoOpProcessingLogger());
}
private static StartConfiguration buildConfig(Path tempDir) throws Exception {
Path sourceDir = Files.createDirectories(tempDir.resolve("source"));
Path targetDir = Files.createDirectories(tempDir.resolve("target"));
Path dbFile = tempDir.resolve("db.sqlite");
if (!Files.exists(dbFile)) Files.createFile(dbFile);
Path promptFile = tempDir.resolve("prompt.txt");
if (!Files.exists(promptFile)) Files.createFile(promptFile);
return new StartConfiguration(
sourceDir,
targetDir,
dbFile,
URI.create("https://api.example.com"),
"gpt-4",
30,
3, // maxRetries
3, // maxPages (low limit useful for page-limit tests)
50000,
promptFile,
tempDir.resolve("lock.lock"),
tempDir.resolve("logs"),
"INFO",
"test-key"
);
private static RuntimeConfiguration buildConfig(Path tempDir) throws Exception {
// maxPages set to 3 useful for page-limit tests
return new RuntimeConfiguration(3);
}
private static SourceDocumentCandidate makeCandidate(String filename) {