wy471x opened a new pull request, #7511: URL: https://github.com/apache/shenyu/pull/7511
[X] I have read the [Contributor Guide](https://shenyu.apache.org/community/contributor-guide) [X] I have added test cases for my changes [X] I have run `./mvnw clean install -Dmaven.javadoc.skip=true` locally ## Summary Addresses #6588, which asks for `@WebMvcTest`-style controller tests for five critical admin controllers (`NamespaceController`, `AiProxyApiKeyController`, `DiscoveryController`, `DiscoveryUpstreamController`, `ProxySelectorController`). On current `master`, three of the five already have test classes (`NamespaceControllerTest`, `AiProxyApiKeyControllerTest`, `DiscoveryUpstreamControllerTest` were added since the audit). This PR fills the remaining gap by adding controller tests for `DiscoveryController` and `ProxySelectorController`, following the existing standalone-MockMvc style used by `DiscoveryUpstreamControllerTest` / `AppAuthControllerTest` (controller + mocked service, `ExceptionHandlers` advice). ### Changes: 1. `DiscoveryControllerTest.java` (new, `shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/`) — 6 tests covering: - happy path for `GET /discovery/typeEnums`, `GET /discovery` (query delegation) and `POST /discovery/insertOrUpdate` (service delegation + response payload); - body validation errors: missing `name` triggers "name not null"; `@Existed` namespace check on `namespaceId` returns "namespaceId is not existed" when `NamespaceMapper.existed` is false; - `DELETE /discovery/{discoveryId}` delegates to `DiscoveryService.delete` when the namespace exists. 2. `ProxySelectorControllerTest.java` (new, same package) — 8 tests covering: - `GET /proxy-selector` returns the `CommonPager` from `ProxySelectorService.listByPage`; - `POST /proxy-selector/addProxySelector`, `PUT /proxy-selector/{id}` (asserts the path id is copied into the DTO before `createOrUpdate`), `DELETE /proxy-selector/batch`, `PUT /proxy-selector/fetch/{discoveryHandlerId}` and `POST /proxy-selector/binding` all delegate to the service; - body validation errors: missing `name` fails with "must not be blank"; `@Existed` namespace check returns "namespaceId is not existed". ### Test Cases: - `DiscoveryControllerTest` — 6 tests, all passing. - `ProxySelectorControllerTest` — 8 tests, all passing. - Note on method-param constraints: parameter-level annotations (`@Existed` on `@RequestParam`, `@NotNull` on `currentPage`/`pageSize`) are not evaluated by the standalone MockMvc setup, so error-path coverage for them is provided through the `@Valid` request-body path, mirroring the existing `DiscoveryUpstreamControllerTest` approach. ## Verification - `./mvnw -pl shenyu-admin -am test` (JDK 21, no skips): checkstyle passes for `shenyu-admin` (0 violations) and all 14 new tests pass. Full module run: 1765 tests, 0 failures, 1 pre-existing error (`ClusterSelectMasterServiceZookeeperImplTest`, `JsonUtils.LOG` NPE) that reproduces identically on a clean upstream `master` checkout (1751 tests, same single error) and is unrelated to this change. Fixes #6588 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
