package com.ttstd.signaling;

import com.ttstd.signaling.config.BearerAuthFilter;
import com.ttstd.signaling.handler.SignalWebSocketHandler;
import com.ttstd.signaling.security.AuthHandshakeInterceptor;
import com.ttstd.signaling.service.AccountService;
import com.ttstd.signaling.service.DeviceIdentityService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
 * 验证引入鉴权组件后 Spring 上下文可正常装配（含 WebSocket 与过滤器链）。
 * 使用 memory profile，避免测试依赖外部 MySQL/Redis。
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
        properties = {
                "security.jwt.secret=integration-test-secret-key-at-least-32-bytes",
                "security.device.provision-secret=integration-test-provision-secret",
                // 集成测试使用嵌入式 H2，无需外部 MySQL / Redis
                "spring.datasource.url=jdbc:h2:mem:signaltest;DB_CLOSE_DELAY=-1;MODE=MySQL",
                "spring.datasource.driver-class-name=org.h2.Driver",
                "spring.datasource.username=sa",
                "spring.datasource.password=",
                "spring.jpa.database-platform=org.hibernate.dialect.H2Dialect",
                "spring.jpa.hibernate.ddl-auto=create-drop",
                "spring.data.redis.host=127.0.0.1",
                "spring.data.redis.port=6390"
        })
@ActiveProfiles("memory")
class ApplicationContextTest {

    @Autowired
    private AccountService accountService;
    @Autowired
    private DeviceIdentityService deviceIdentityService;
    @Autowired
    private AuthHandshakeInterceptor authHandshakeInterceptor;
    @Autowired
    private BearerAuthFilter bearerAuthFilter;
    @Autowired
    private SignalWebSocketHandler signalWebSocketHandler;

    @Test
    void contextLoads() {
        assertNotNull(accountService);
        assertNotNull(deviceIdentityService);
        assertNotNull(authHandshakeInterceptor);
        assertNotNull(bearerAuthFilter);
        assertNotNull(signalWebSocketHandler);
    }
}
