Back to Repositories

Testing XingHuo Chat Model Integration in RuoYi-Vue-Pro

This test suite validates the XingHuo Chat Model integration within the RuoYi Vue Pro framework, focusing on both synchronous and streaming chat interactions. The tests verify proper message handling and response generation using the Spring AI framework.

Test Coverage Overview

The test suite covers core functionality of the XingHuo Chat Model implementation, including:

  • Synchronous chat message processing via testCall()
  • Streaming response handling through testStream()
  • System and user message integration
  • Chat prompt construction and processing

Implementation Analysis

The testing approach utilizes JUnit 5 with Spring AI components for chat model validation. The implementation demonstrates reactive programming patterns through Flux for streaming responses, while maintaining synchronous operation support for standard chat interactions.

Technical Details

  • JUnit Jupiter for test execution
  • Spring AI chat message framework
  • Reactor Core for reactive streams
  • XingHuo API integration with authentication
  • System and User message types for chat interactions

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Separate test methods for distinct functionality
  • Proper test setup with authentication credentials
  • Clear test method naming conventions
  • Disabled annotation for API-dependent tests
  • Structured message preparation and response handling

yunaiv/ruoyi-vue-pro

yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/XingHuoChatModelTests.java

            
package cn.iocoder.yudao.framework.ai.chat;

import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import reactor.core.publisher.Flux;

import java.util.ArrayList;
import java.util.List;

/**
 * {@link XingHuoChatModel} 集成测试
 *
 * @author fansili
 */
public class XingHuoChatModelTests {

    private final XingHuoChatModel chatModel = new XingHuoChatModel(
            "cb6415c19d6162cda07b47316fcb0416",
            "Y2JiYTIxZjA3MDMxMjNjZjQzYzVmNzdh");

    @Test
    @Disabled
    public void testCall() {
        // 准备参数
        List<Message> messages = new ArrayList<>();
        messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
        messages.add(new UserMessage("1 + 1 = ?"));

        // 调用
        ChatResponse response = chatModel.call(new Prompt(messages));
        // 打印结果
        System.out.println(response);
    }

    @Test
    @Disabled
    public void testStream() {
        // 准备参数
        List<Message> messages = new ArrayList<>();
        messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
        messages.add(new UserMessage("1 + 1 = ?"));

        // 调用
        Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages));
        // 打印结果
        flux.doOnNext(System.out::println).then().block();
    }

}