From 973accd9265f5c7ff2f5eecf9fc25ab98c130495 Mon Sep 17 00:00:00 2001 From: cloudbase-ai <22498243+cloudbase-ai@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:56:51 -0800 Subject: [PATCH] fix: return an empty page for unmatched dashboard users --- .../controller/DashboardUserController.java | 9 ++------- .../DashboardUserControllerTest.java | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java index 83572d4da40d..51036d48beb8 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DashboardUserController.java @@ -17,7 +17,6 @@ package org.apache.shenyu.admin.controller; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.aspect.annotation.RestApi; import org.apache.shenyu.admin.exception.ValidFailException; @@ -89,12 +88,8 @@ public ShenyuAdminResult queryDashboardUsers(final String userName, @RequestParam @NotNull(message = "pageSize not null") final Integer pageSize) { CommonPager commonPager = dashboardUserService.listByPage(new DashboardUserQuery(userName, new PageParameter(currentPage, pageSize))); - - if (CollectionUtils.isNotEmpty(commonPager.getDataList())) { - return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager); - } else { - return ShenyuAdminResult.error(ShenyuResultMessage.DASHBOARD_QUERY_ERROR); - } + + return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager); } /** diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java index ce15121b8406..edb3350ed037 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/DashboardUserControllerTest.java @@ -112,14 +112,20 @@ public void queryDashboardUsers() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is(ShenyuResultMessage.QUERY_SUCCESS))) .andReturn(); + } - final CommonPager commonPagerError = new CommonPager<>(new PageParameter(), - Collections.emptyList()); - given(dashboardUserService.listByPage(any())).willReturn(commonPagerError); - mockMvc.perform(get(url)) + @Test + public void queryDashboardUsersReturnsEmptyPage() throws Exception { + final CommonPager emptyPage = new CommonPager<>(new PageParameter(1, 12, 0), Collections.emptyList()); + given(dashboardUserService.listByPage(any())).willReturn(emptyPage); + mockMvc.perform(get("/dashboardUser?userName=missing¤tPage=1&pageSize=12")) .andExpect(status().isOk()) - .andExpect(jsonPath("$.message", is(ShenyuResultMessage.DASHBOARD_QUERY_ERROR))) - .andReturn(); + .andExpect(jsonPath("$.code", is(200))) + .andExpect(jsonPath("$.message", is(ShenyuResultMessage.QUERY_SUCCESS))) + .andExpect(jsonPath("$.data.dataList").isEmpty()) + .andExpect(jsonPath("$.data.page.totalCount", is(0))) + .andExpect(jsonPath("$.data.page.currentPage", is(1))) + .andExpect(jsonPath("$.data.page.pageSize", is(12))); } @Test