test(api): 补齐剩余业务模块控制器接口验证
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.bruce.mcp.controller;
|
||||
|
||||
import com.bruce.common.handler.GlobalExceptionHandler;
|
||||
import com.bruce.mcp.service.IMcpCapabilityService;
|
||||
import com.bruce.mcp.service.IMcpImportService;
|
||||
import com.bruce.mcp.service.IMcpServerService;
|
||||
import com.bruce.mcp.service.IMcpWorkspaceService;
|
||||
import com.bruce.mcp.vo.McpWorkspaceVO;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 验证 MCP 工作台查询接口的基础契约。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class McpImportControllerTests {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Mock
|
||||
private IMcpImportService mcpImportService;
|
||||
|
||||
@Mock
|
||||
private IMcpServerService mcpServerService;
|
||||
|
||||
@Mock
|
||||
private IMcpCapabilityService mcpCapabilityService;
|
||||
|
||||
@Mock
|
||||
private IMcpWorkspaceService mcpWorkspaceService;
|
||||
|
||||
@InjectMocks
|
||||
private McpImportController mcpImportController;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(mcpImportController)
|
||||
.setControllerAdvice(new GlobalExceptionHandler())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void workspaceShouldReturnStructuredWorkspaceView() throws Exception {
|
||||
McpWorkspaceVO workspace = new McpWorkspaceVO();
|
||||
workspace.setServerId(301L);
|
||||
workspace.setServerCode("jira_server");
|
||||
workspace.setServerName("Jira 服务");
|
||||
workspace.setImportType("URL");
|
||||
workspace.setHealthStatus("HEALTHY");
|
||||
|
||||
when(mcpWorkspaceService.getWorkspace(301L)).thenReturn(workspace);
|
||||
|
||||
mockMvc.perform(get("/api/mcp/workspace").param("serverId", "301"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.resultcode").value("0"))
|
||||
.andExpect(jsonPath("$.data.serverId").value(301))
|
||||
.andExpect(jsonPath("$.data.serverCode").value("jira_server"))
|
||||
.andExpect(jsonPath("$.data.healthStatus").value("HEALTHY"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user