From 59d08791248eedfd93c0633b5130d29c39829e9c Mon Sep 17 00:00:00 2001 From: Alex Klimenko Date: Wed, 6 Aug 2025 13:28:55 +0200 Subject: [PATCH] test: Add comprehensive test coverage for VectorStore runtime hints registration Signed-off-by: Alex Klimenko --- .../aot/VectorStoreRuntimeHintsTests.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spring-ai-vector-store/src/test/java/org/springframework/ai/vectorstore/aot/VectorStoreRuntimeHintsTests.java b/spring-ai-vector-store/src/test/java/org/springframework/ai/vectorstore/aot/VectorStoreRuntimeHintsTests.java index f3a6e46d234..21bcc467678 100644 --- a/spring-ai-vector-store/src/test/java/org/springframework/ai/vectorstore/aot/VectorStoreRuntimeHintsTests.java +++ b/spring-ai-vector-store/src/test/java/org/springframework/ai/vectorstore/aot/VectorStoreRuntimeHintsTests.java @@ -21,6 +21,7 @@ import org.springframework.aot.hint.RuntimeHints; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.resource; public class VectorStoreRuntimeHintsTests { @@ -34,4 +35,39 @@ void vectorStoreRuntimeHints() { .matches(resource().forResource("antlr4/org/springframework/ai/vectorstore/filter/antlr4/Filters.g4")); } + @Test + void registerHintsWithNullClassLoader() { + var runtimeHints = new RuntimeHints(); + var vectorStoreHints = new VectorStoreRuntimeHints(); + + // Should not throw exception with null ClassLoader + assertThatCode(() -> vectorStoreHints.registerHints(runtimeHints, null)).doesNotThrowAnyException(); + } + + @Test + void ensureResourceHintsAreRegistered() { + var runtimeHints = new RuntimeHints(); + var vectorStoreHints = new VectorStoreRuntimeHints(); + vectorStoreHints.registerHints(runtimeHints, null); + + // Ensure the specific ANTLR resource is registered + assertThat(runtimeHints) + .matches(resource().forResource("antlr4/org/springframework/ai/vectorstore/filter/antlr4/Filters.g4")); + } + + @Test + void verifyResourceHintsForDifferentPaths() { + var runtimeHints = new RuntimeHints(); + var vectorStoreHints = new VectorStoreRuntimeHints(); + vectorStoreHints.registerHints(runtimeHints, null); + + // Test that the exact resource path is registered + assertThat(runtimeHints) + .matches(resource().forResource("antlr4/org/springframework/ai/vectorstore/filter/antlr4/Filters.g4")); + + // Verify that similar but incorrect paths are not matched + assertThat(runtimeHints).doesNotMatch(resource().forResource("antlr4/Filters.g4")); + assertThat(runtimeHints).doesNotMatch(resource().forResource("org/springframework/ai/vectorstore/Filters.g4")); + } + }