Skip to content

Commit 80559e8

Browse files
authored
fix: return an empty list for resources without buttons (#8491)
Co-authored-by: cloudbase-ai <22498243+cloudbase-ai@users.noreply.github.com>
1 parent 8b94d08 commit 80559e8

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

‎shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ResourceController.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ public ShenyuAdminResult getMenuTree() {
105105
@RequiresPermissions(value = {"system:resource:addButton", "system:resource:list"}, logical = Logical.OR)
106106
public ShenyuAdminResult getButton(final String id) {
107107
List<ResourceVO> resourceVOList = resourceService.findByParentId(id);
108-
if (CollectionUtils.isNotEmpty(resourceVOList)) {
109-
return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, resourceVOList);
110-
}
111-
return ShenyuAdminResult.error(ShenyuResultMessage.QUERY_FAILED);
108+
return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, resourceVOList);
112109
}
113110

114111
/**

‎shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/ResourceControllerTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ public void testGetButtonResultSuccess() throws Exception {
148148
}
149149

150150
@Test
151-
public void testGetButtonResultFailed() throws Exception {
151+
public void testGetButtonReturnsEmptyList() throws Exception {
152152
final String mockId = "mock id";
153153
given(resourceService.findByParentId(mockId)).willReturn(newArrayList());
154154

155155
this.mockMvc.perform(MockMvcRequestBuilders.get("/resource/button")
156156
.queryParam("id", mockId))
157-
.andExpect(content().json(GsonUtils.getInstance().toJson(ShenyuAdminResult.error(ShenyuResultMessage.QUERY_FAILED))))
157+
.andExpect(content().json(GsonUtils.getInstance().toJson(ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, Collections.emptyList()))))
158158
.andReturn();
159159
}
160160

0 commit comments

Comments
 (0)