commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package org.example.service;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.tool.ToolCallback;
|
||||
import org.springframework.ai.tool.ToolCallbackProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Chat + Embedding 解耦验证测试
|
||||
* <p>
|
||||
* 验证 ChatModel Bean 注入、ModelRoutingConfig 路由、ChatService 接口兼容。
|
||||
* Chat: DeepSeek via OpenAI-compatible API
|
||||
* Embedding: Ollama BGE-M3 (需要本地 ollama 运行)
|
||||
*/
|
||||
@SpringBootTest
|
||||
@DisplayName("Chat + Embedding 解耦验证")
|
||||
class ChatAndEmbeddingSmokeTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
private ChatModel chatModel;
|
||||
|
||||
@Autowired
|
||||
private ChatService chatService;
|
||||
|
||||
/**
|
||||
* 提供 mock ToolCallbackProvider(MCP 已禁用时需要)
|
||||
*/
|
||||
@TestConfiguration
|
||||
static class MockToolConfig {
|
||||
@Bean
|
||||
public ToolCallbackProvider toolCallbackProvider() {
|
||||
return () -> new ToolCallback[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Spring 容器启动成功")
|
||||
void contextLoads() {
|
||||
assertNotNull(context, "Spring 容器应为非空");
|
||||
assertNotNull(chatModel, "ChatModel Bean 应注入成功");
|
||||
assertNotNull(chatService, "ChatService Bean 应注入成功");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ModelRoutingConfig @Primary ChatModel 生效")
|
||||
void chatModelPrimaryBeanWorks() {
|
||||
assertNotNull(chatModel, "@Primary ChatModel 应被自动注入");
|
||||
System.out.println("✓ ChatModel 类型: " + chatModel.getClass().getName());
|
||||
|
||||
// 验证路由到 openAiChatModel (DeepSeek)
|
||||
assertTrue(context.containsBean("openAiChatModel"), "openAiChatModel 应存在");
|
||||
System.out.println(" Chat → openAiChatModel (DeepSeek) ✓");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ChatService.createReactAgent 接受 ChatModel 接口")
|
||||
void chatServiceAcceptsChatModelInterface() {
|
||||
var agent = chatService.createReactAgent(chatModel, "测试系统提示词");
|
||||
assertNotNull(agent, "ReactAgent 应创建成功");
|
||||
assertEquals("intelligent_assistant", agent.name());
|
||||
System.out.println("✓ ReactAgent 创建成功: " + agent.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ChatModel 实现 ChatModel 接口(类型安全验证)")
|
||||
void chatModelIsProperType() {
|
||||
assertNotNull(chatModel, "注入的 Bean 应为 ChatModel 实例");
|
||||
System.out.println("✓ ChatModel 接口实现: " + chatModel.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("EmbeddingModel 状态")
|
||||
void embeddingModelStatus() {
|
||||
boolean hasEmbedding = context.containsBean("embeddingModel");
|
||||
if (hasEmbedding) {
|
||||
System.out.println("✓ EmbeddingModel 已配置");
|
||||
} else {
|
||||
System.out.println("⚠ EmbeddingModel 未找到 — 检查 Ollama 是否运行");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user