diff --git a/src/test/java/com/webgame/webgamebackend/sse/SseIntegrationTest.java b/src/test/java/com/webgame/webgamebackend/sse/SseIntegrationTest.java new file mode 100644 index 0000000..3c1dd0f --- /dev/null +++ b/src/test/java/com/webgame/webgamebackend/sse/SseIntegrationTest.java @@ -0,0 +1,49 @@ +package com.webgame.webgamebackend.sse; + +import com.alibaba.fastjson2.JSON; +import com.webgame.webgamebackend.common.event.SseEventPublisher; +import com.webgame.webgamebackend.common.event.SseEventType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * SSE 集成测试 + * + * 验证 SSE 事件发布器的基本功能。 + * 需要 Redis 和 MySQL 运行。 + */ +@SpringBootTest +@DisplayName("SSE 集成测试") +class SseIntegrationTest { + + @Autowired + private SseEventPublisher publisher; + + @Test + @DisplayName("SseEventPublisher Bean 应被正确注入") + void publisher_shouldBeInjected() { + assertThat(publisher).isNotNull(); + } + + @Test + @DisplayName("broadcast 方法不应抛异常") + void broadcast_shouldNotThrowException() { + // Act & Assert: 发布广播事件不应抛异常 + publisher.broadcast(SseEventType.ROOM_CREATED, + Map.of("roomId", "test-001", "name", "测试房间")); + } + + @Test + @DisplayName("sendTo 方法不应抛异常") + void sendTo_shouldNotThrowException() { + // Act & Assert: 发布定向事件不应抛异常 + publisher.sendTo("test-user-id", SseEventType.KICKED, + Map.of("roomId", "test-001")); + } +}