test(api): 补齐聚合接口控制器测试并修复参数异常语义
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.bruce.dashboard;
|
||||
|
||||
import com.bruce.common.handler.GlobalExceptionHandler;
|
||||
import com.bruce.dashboard.controller.StudioDashboardController;
|
||||
import com.bruce.dashboard.service.IStudioDashboardService;
|
||||
import com.bruce.dashboard.vo.StudioDashboardMetricsVO;
|
||||
import com.bruce.dashboard.vo.StudioDashboardVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* 验证 Studio 首页聚合接口响应结构,确保前端首页可稳定消费。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class StudioDashboardControllerTests {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Mock
|
||||
private IStudioDashboardService studioDashboardService;
|
||||
|
||||
@InjectMocks
|
||||
private StudioDashboardController studioDashboardController;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(studioDashboardController)
|
||||
.setControllerAdvice(new GlobalExceptionHandler())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void detailShouldReturnStructuredDashboardView() throws Exception {
|
||||
StudioDashboardMetricsVO metrics = new StudioDashboardMetricsVO();
|
||||
metrics.setTodayRunCount(12);
|
||||
metrics.setSuccessRate(98.5D);
|
||||
metrics.setP50Latency("1.28s");
|
||||
metrics.setEstimatedCost("¥4.82");
|
||||
|
||||
StudioDashboardVO dashboard = new StudioDashboardVO();
|
||||
dashboard.setProjectName("Common Agent Studio");
|
||||
dashboard.setEnvironment("Dev");
|
||||
dashboard.setPublishStatus("DRAFT");
|
||||
dashboard.setMetrics(metrics);
|
||||
dashboard.setWarningTitle("发布前仍需补齐模型路由");
|
||||
|
||||
when(studioDashboardService.getDashboard()).thenReturn(dashboard);
|
||||
|
||||
mockMvc.perform(get("/api/studio/dashboard"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.resultcode").value("0"))
|
||||
.andExpect(jsonPath("$.data.projectName").value("Common Agent Studio"))
|
||||
.andExpect(jsonPath("$.data.environment").value("Dev"))
|
||||
.andExpect(jsonPath("$.data.metrics.todayRunCount").value(12));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user