M4 AP-007 Scope bereinigen und Startfehler-Test ergänzen
This commit is contained in:
+47
@@ -7,6 +7,8 @@ import de.gecheckt.pdf.umbenenner.application.config.StartConfigurationValidator
|
||||
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunOutcome;
|
||||
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunProcessingUseCase;
|
||||
import de.gecheckt.pdf.umbenenner.application.port.out.ConfigurationPort;
|
||||
import de.gecheckt.pdf.umbenenner.application.port.out.DocumentPersistenceException;
|
||||
import de.gecheckt.pdf.umbenenner.application.port.out.PersistenceSchemaInitializationPort;
|
||||
import de.gecheckt.pdf.umbenenner.application.port.out.RunLockPort;
|
||||
import de.gecheckt.pdf.umbenenner.domain.model.BatchRunContext;
|
||||
|
||||
@@ -41,6 +43,7 @@ class BootstrapRunnerTest {
|
||||
() -> mockConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> new MockRunBatchProcessingUseCase(true),
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -65,6 +68,7 @@ class BootstrapRunnerTest {
|
||||
() -> mockConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
() -> failingValidator,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> new MockRunBatchProcessingUseCase(true),
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -84,6 +88,7 @@ class BootstrapRunnerTest {
|
||||
() -> failingConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> new MockRunBatchProcessingUseCase(true),
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -103,6 +108,7 @@ class BootstrapRunnerTest {
|
||||
() -> throwingConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> new MockRunBatchProcessingUseCase(true),
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -121,6 +127,7 @@ class BootstrapRunnerTest {
|
||||
() -> mockConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> failingUseCase,
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -140,6 +147,7 @@ class BootstrapRunnerTest {
|
||||
() -> mockConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> lockUnavailableUseCase,
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -191,6 +199,7 @@ class BootstrapRunnerTest {
|
||||
return new MockRunLockPort();
|
||||
},
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> new MockRunBatchProcessingUseCase(true),
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
@@ -219,6 +228,7 @@ class BootstrapRunnerTest {
|
||||
() -> mockConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new MockSchemaInitializationPort(),
|
||||
(config, lock) -> useCaseWithDocumentFailures,
|
||||
SchedulerBatchCommand::new
|
||||
);
|
||||
@@ -233,6 +243,36 @@ class BootstrapRunnerTest {
|
||||
assertNotNull(runner, "Default constructor should create a valid BootstrapRunner");
|
||||
}
|
||||
|
||||
/**
|
||||
* AP-007: Hard startup failure test — schema initialization failure must be treated as
|
||||
* a startup error and result in exit code 1. This verifies that
|
||||
* {@link DocumentPersistenceException} thrown from
|
||||
* {@link PersistenceSchemaInitializationPort#initializeSchema()} is correctly caught
|
||||
* and handled as a bootstrap failure.
|
||||
*/
|
||||
@Test
|
||||
void run_returnsOneWhenSchemaInitializationFails() throws Exception {
|
||||
ConfigurationPort mockConfigPort = new MockConfigurationPort(tempDir, true);
|
||||
|
||||
BootstrapRunner runner = new BootstrapRunner(
|
||||
() -> mockConfigPort,
|
||||
lockFile -> new MockRunLockPort(),
|
||||
StartConfigurationValidator::new,
|
||||
jdbcUrl -> new PersistenceSchemaInitializationPort() {
|
||||
@Override
|
||||
public void initializeSchema() {
|
||||
throw new DocumentPersistenceException("Simulated schema initialization failure");
|
||||
}
|
||||
},
|
||||
(config, lock) -> new MockRunBatchProcessingUseCase(true),
|
||||
useCase -> new SchedulerBatchCommand(useCase)
|
||||
);
|
||||
|
||||
int exitCode = runner.run();
|
||||
|
||||
assertEquals(1, exitCode, "Schema initialization failure should return exit code 1");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Mocks
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -306,4 +346,11 @@ class BootstrapRunnerTest {
|
||||
@Override
|
||||
public void release() { }
|
||||
}
|
||||
|
||||
private static class MockSchemaInitializationPort implements PersistenceSchemaInitializationPort {
|
||||
@Override
|
||||
public void initializeSchema() {
|
||||
// Success by default; can be subclassed to throw exceptions for testing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user