test(api): 补齐剩余业务模块控制器接口验证
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.bruce.modelprovider.controller;
|
||||
|
||||
import com.bruce.common.handler.GlobalExceptionHandler;
|
||||
import com.bruce.modelprovider.service.IModelWorkspaceService;
|
||||
import com.bruce.modelprovider.vo.ModelWorkspaceVO;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 验证模型工作台聚合接口的基础返回契约。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ModelWorkspaceControllerTests {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Mock
|
||||
private IModelWorkspaceService modelWorkspaceService;
|
||||
|
||||
@InjectMocks
|
||||
private ModelWorkspaceController modelWorkspaceController;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(modelWorkspaceController)
|
||||
.setControllerAdvice(new GlobalExceptionHandler())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWorkspaceShouldReturnStructuredAggregateView() throws Exception {
|
||||
ModelWorkspaceVO workspace = new ModelWorkspaceVO();
|
||||
workspace.setProviderCount(3);
|
||||
workspace.setModelCount(5);
|
||||
workspace.setRouteRuleCount(2);
|
||||
workspace.setRecentFailedCallCount(1);
|
||||
|
||||
when(modelWorkspaceService.getWorkspace()).thenReturn(workspace);
|
||||
|
||||
mockMvc.perform(get("/api/model/workspace"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.resultcode").value("0"))
|
||||
.andExpect(jsonPath("$.data.providerCount").value(3))
|
||||
.andExpect(jsonPath("$.data.modelCount").value(5))
|
||||
.andExpect(jsonPath("$.data.routeRuleCount").value(2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user