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"));
|
}
|
|
@Test
|
void integrityMappingIsAuthenticatedSurface()
|
{
|
Method integrity = method("integrity", Long.class);
|
assertArrayEquals(new String[] { "/{testId}/integrity" }, integrity.getAnnotation(GetMapping.class).value());
|
assertTrue(integrity.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); }
|
}
|
}
|