|
@@ -7,6 +7,11 @@ import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
+import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
|
+import org.springframework.test.web.servlet.MvcResult;
|
|
|
|
|
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
|
|
|
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
|
|
|
|
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -63,4 +68,27 @@ class OrderStreamControllerTest {
|
|
|
assertTrue(ex.getMessage().contains("未登录"), "实际文案=" + ex.getMessage());
|
|
assertTrue(ex.getMessage().contains("未登录"), "实际文案=" + ex.getMessage());
|
|
|
assertEquals(0, hub.connectionCount(), "匿名不许往桶里挂空连接");
|
|
assertEquals(0, hub.connectionCount(), "匿名不许往桶里挂空连接");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 前面三条用例都**直接调方法**,从不经 DispatcherServlet ⇒ 类级映射写错它们照样绿
|
|
|
|
|
+ * (2026-10-05 实测:后端日志 `路径不存在 [/api/v1/payment/stream/orders]`,而这条流量的
|
|
|
|
|
+ * 真实 URL 得是 `/api/v1/api/v1/...` 才通)。这一条补上那段路:
|
|
|
|
|
+ * 前缀由 `server.servlet.context-path=/api/v1` 供给(见 application.yml),
|
|
|
|
|
+ * 所以类级 {@code @RequestMapping} 只能是 `/payment/stream`,多写一次就双双落空。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void orders_urlUnderServletContextPath_reachesHandler() throws Exception {
|
|
|
|
|
+ login(2L, false);
|
|
|
|
|
+ MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
|
|
|
|
|
+
|
|
|
|
|
+ MvcResult result = mockMvc.perform(MockMvcRequestBuilders
|
|
|
|
|
+ .get("/api/v1/payment/stream/orders")
|
|
|
|
|
+ .contextPath("/api/v1"))
|
|
|
|
|
+ .andReturn();
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(200, result.getResponse().getStatus(),
|
|
|
|
|
+ "context-path 之外的路径必须就是控制器映射;实际状态=" + result.getResponse().getStatus()
|
|
|
|
|
+ + ",响应体=" + result.getResponse().getContentAsString());
|
|
|
|
|
+ MockMvcResultMatchers.request().asyncStarted().match(result);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|