1+ /*
2+ * Copyright 2023-2024 the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .ai .aot ;
18+
19+ import org .junit .jupiter .api .Test ;
20+ import org .slf4j .LoggerFactory ;
21+ import org .slf4j .helpers .NOP_FallbackServiceProvider ;
22+ import org .slf4j .helpers .SubstituteServiceProvider ;
23+ import org .springframework .ai .chat .messages .AbstractMessage ;
24+ import org .springframework .ai .chat .messages .AssistantMessage ;
25+ import org .springframework .ai .chat .messages .Message ;
26+ import org .springframework .ai .chat .messages .MessageType ;
27+ import org .springframework .ai .chat .messages .SystemMessage ;
28+ import org .springframework .ai .chat .messages .ToolResponseMessage ;
29+ import org .springframework .ai .chat .messages .UserMessage ;
30+ import org .springframework .ai .tool .ToolCallback ;
31+ import org .springframework .ai .tool .definition .ToolDefinition ;
32+ import org .springframework .aot .hint .RuntimeHints ;
33+ import org .springframework .aot .hint .TypeReference ;
34+
35+ import static org .assertj .core .api .Assertions .assertThat ;
36+
37+ /**
38+ * Tests for {@link SpringAiCoreRuntimeHints}.
39+ *
40+ * @author Christian Tzolov
41+ * @author Hyunjoon Park
42+ */
43+ class SpringAiCoreRuntimeHintsTests {
44+
45+ @ Test
46+ void registerHints () {
47+ RuntimeHints runtimeHints = new RuntimeHints ();
48+ SpringAiCoreRuntimeHints springAiCoreRuntimeHints = new SpringAiCoreRuntimeHints ();
49+ springAiCoreRuntimeHints .registerHints (runtimeHints , null );
50+
51+ // Verify chat message types are registered
52+ assertThat (runtimeHints .reflection ().typeHints ())
53+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
54+ .isEqualTo (TypeReference .of (AbstractMessage .class )));
55+ assertThat (runtimeHints .reflection ().typeHints ())
56+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
57+ .isEqualTo (TypeReference .of (AssistantMessage .class )));
58+ assertThat (runtimeHints .reflection ().typeHints ())
59+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
60+ .isEqualTo (TypeReference .of (Message .class )));
61+ assertThat (runtimeHints .reflection ().typeHints ())
62+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
63+ .isEqualTo (TypeReference .of (MessageType .class )));
64+ assertThat (runtimeHints .reflection ().typeHints ())
65+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
66+ .isEqualTo (TypeReference .of (SystemMessage .class )));
67+ assertThat (runtimeHints .reflection ().typeHints ())
68+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
69+ .isEqualTo (TypeReference .of (ToolResponseMessage .class )));
70+ assertThat (runtimeHints .reflection ().typeHints ())
71+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
72+ .isEqualTo (TypeReference .of (UserMessage .class )));
73+
74+ // Verify tool types are registered
75+ assertThat (runtimeHints .reflection ().typeHints ())
76+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
77+ .isEqualTo (TypeReference .of (ToolCallback .class )));
78+ assertThat (runtimeHints .reflection ().typeHints ())
79+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
80+ .isEqualTo (TypeReference .of (ToolDefinition .class )));
81+
82+ // Verify SLF4J types are registered for Java 22 compatibility
83+ assertThat (runtimeHints .reflection ().typeHints ())
84+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
85+ .isEqualTo (TypeReference .of (NOP_FallbackServiceProvider .class )));
86+ assertThat (runtimeHints .reflection ().typeHints ())
87+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
88+ .isEqualTo (TypeReference .of (SubstituteServiceProvider .class )));
89+ assertThat (runtimeHints .reflection ().typeHints ())
90+ .anySatisfy (typeHint -> assertThat (typeHint .getType ())
91+ .isEqualTo (TypeReference .of (LoggerFactory .class )));
92+
93+ // Verify resources are registered
94+ assertThat (runtimeHints .resources ().resourcePatternHints ())
95+ .anySatisfy (hint -> assertThat (hint .getIncludes ())
96+ .anyMatch (include -> include .getPattern ().contains ("embedding-model-dimensions.properties" )));
97+ }
98+ }
0 commit comments