M3-AP-007: Startvalidierung für Quellordner testbar gemacht
This commit is contained in:
@@ -683,4 +683,153 @@ class StartConfigurationValidatorTest {
|
||||
assertTrue(message.contains("max.pages: must be > 0"));
|
||||
assertTrue(message.contains("max.text.characters: must be > 0"));
|
||||
}
|
||||
|
||||
/**
|
||||
* M3/AP-007: Focused tests for source folder validation using mocked filesystem checks.
|
||||
* <p>
|
||||
* These tests verify the four critical paths for source folder validation without
|
||||
* relying on platform-dependent filesystem permissions or the actual FS state.
|
||||
*/
|
||||
|
||||
@Test
|
||||
void validate_failsWhenSourceFolderDoesNotExist_mocked() throws Exception {
|
||||
Path targetFolder = Files.createDirectory(tempDir.resolve("target"));
|
||||
Path sqliteFile = Files.createFile(tempDir.resolve("db.sqlite"));
|
||||
Path promptTemplateFile = Files.createFile(tempDir.resolve("prompt.txt"));
|
||||
|
||||
StartConfiguration config = new StartConfiguration(
|
||||
tempDir.resolve("nonexistent"),
|
||||
targetFolder,
|
||||
sqliteFile,
|
||||
URI.create("https://api.example.com"),
|
||||
"gpt-4",
|
||||
30,
|
||||
3,
|
||||
100,
|
||||
50000,
|
||||
promptTemplateFile,
|
||||
null,
|
||||
null,
|
||||
"INFO",
|
||||
"test-api-key"
|
||||
);
|
||||
|
||||
// Mock: always return "does not exist" error for any path
|
||||
StartConfigurationValidator.SourceFolderChecker mockChecker = path ->
|
||||
"- source.folder: path does not exist: " + path;
|
||||
|
||||
StartConfigurationValidator validatorWithMock = new StartConfigurationValidator(mockChecker);
|
||||
|
||||
InvalidStartConfigurationException exception = assertThrows(
|
||||
InvalidStartConfigurationException.class,
|
||||
() -> validatorWithMock.validate(config)
|
||||
);
|
||||
assertTrue(exception.getMessage().contains("source.folder: path does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validate_failsWhenSourceFolderIsNotADirectory_mocked() throws Exception {
|
||||
Path targetFolder = Files.createDirectory(tempDir.resolve("target"));
|
||||
Path sqliteFile = Files.createFile(tempDir.resolve("db.sqlite"));
|
||||
Path promptTemplateFile = Files.createFile(tempDir.resolve("prompt.txt"));
|
||||
|
||||
StartConfiguration config = new StartConfiguration(
|
||||
tempDir.resolve("somepath"),
|
||||
targetFolder,
|
||||
sqliteFile,
|
||||
URI.create("https://api.example.com"),
|
||||
"gpt-4",
|
||||
30,
|
||||
3,
|
||||
100,
|
||||
50000,
|
||||
promptTemplateFile,
|
||||
null,
|
||||
null,
|
||||
"INFO",
|
||||
"test-api-key"
|
||||
);
|
||||
|
||||
// Mock: simulate path exists but is not a directory
|
||||
StartConfigurationValidator.SourceFolderChecker mockChecker = path ->
|
||||
"- source.folder: path is not a directory: " + path;
|
||||
|
||||
StartConfigurationValidator validatorWithMock = new StartConfigurationValidator(mockChecker);
|
||||
|
||||
InvalidStartConfigurationException exception = assertThrows(
|
||||
InvalidStartConfigurationException.class,
|
||||
() -> validatorWithMock.validate(config)
|
||||
);
|
||||
assertTrue(exception.getMessage().contains("source.folder: path is not a directory"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validate_failsWhenSourceFolderIsNotReadable_mocked() throws Exception {
|
||||
Path targetFolder = Files.createDirectory(tempDir.resolve("target"));
|
||||
Path sqliteFile = Files.createFile(tempDir.resolve("db.sqlite"));
|
||||
Path promptTemplateFile = Files.createFile(tempDir.resolve("prompt.txt"));
|
||||
|
||||
StartConfiguration config = new StartConfiguration(
|
||||
tempDir.resolve("somepath"),
|
||||
targetFolder,
|
||||
sqliteFile,
|
||||
URI.create("https://api.example.com"),
|
||||
"gpt-4",
|
||||
30,
|
||||
3,
|
||||
100,
|
||||
50000,
|
||||
promptTemplateFile,
|
||||
null,
|
||||
null,
|
||||
"INFO",
|
||||
"test-api-key"
|
||||
);
|
||||
|
||||
// Mock: simulate path exists, is directory, but is not readable
|
||||
// This is the critical M3/AP-007 case that is hard to test on actual FS
|
||||
StartConfigurationValidator.SourceFolderChecker mockChecker = path ->
|
||||
"- source.folder: directory is not readable: " + path;
|
||||
|
||||
StartConfigurationValidator validatorWithMock = new StartConfigurationValidator(mockChecker);
|
||||
|
||||
InvalidStartConfigurationException exception = assertThrows(
|
||||
InvalidStartConfigurationException.class,
|
||||
() -> validatorWithMock.validate(config)
|
||||
);
|
||||
assertTrue(exception.getMessage().contains("source.folder: directory is not readable"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validate_succeedsWhenSourceFolderIsValid_mocked() throws Exception {
|
||||
Path sourceFolder = Files.createDirectory(tempDir.resolve("source"));
|
||||
Path targetFolder = Files.createDirectory(tempDir.resolve("target"));
|
||||
Path sqliteFile = Files.createFile(tempDir.resolve("db.sqlite"));
|
||||
Path promptTemplateFile = Files.createFile(tempDir.resolve("prompt.txt"));
|
||||
|
||||
StartConfiguration config = new StartConfiguration(
|
||||
sourceFolder,
|
||||
targetFolder,
|
||||
sqliteFile,
|
||||
URI.create("https://api.example.com"),
|
||||
"gpt-4",
|
||||
30,
|
||||
3,
|
||||
100,
|
||||
50000,
|
||||
promptTemplateFile,
|
||||
null,
|
||||
null,
|
||||
"INFO",
|
||||
"test-api-key"
|
||||
);
|
||||
|
||||
// Mock: all checks pass (return null)
|
||||
StartConfigurationValidator.SourceFolderChecker mockChecker = path -> null;
|
||||
|
||||
StartConfigurationValidator validatorWithMock = new StartConfigurationValidator(mockChecker);
|
||||
|
||||
assertDoesNotThrow(() -> validatorWithMock.validate(config),
|
||||
"Validation should succeed when source folder checker returns null");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user