yeg
2026-08-30 56cddf53e7e71afad29885d7fcf773a222b95f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.ruoyi.web.controller.system;
 
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
 
/** Ticket09 实时接口契约,避免前端依赖未鉴权或 URL 携带令牌的实现。 */
class TTestLiveControllerContractTest
{
    @Test
    void liveStateAndStreamMappingsAreAuthenticatedSurface()
    {
        Method state = method("liveState", Long.class);
        assertArrayEquals(new String[] { "/{testId}/live-state" }, state.getAnnotation(GetMapping.class).value());
        Method live = method("live", Long.class);
        assertArrayEquals(new String[] { "/{testId}/live" }, live.getAnnotation(GetMapping.class).value());
        assertEquals(MediaType.TEXT_EVENT_STREAM_VALUE, live.getAnnotation(GetMapping.class).produces()[0]);
        assertTrue(live.getAnnotation(org.springframework.security.access.prepost.PreAuthorize.class).value()
                .contains("system:test:query"));
    }
 
    private Method method(String name, Class<?>... types)
    {
        try { return TTestLiveController.class.getDeclaredMethod(name, types); }
        catch (NoSuchMethodException exception) { throw new AssertionError(exception); }
    }
}