Copilot commented on code in PR #30:
URL:
https://github.com/apache/shenyu-plugin-store/pull/30#discussion_r4306644783
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginTest.java:
##########
@@ -122,6 +134,30 @@ void testSofa(final GatewayClient gateway, final CaseSpec
spec) {
spec.getVerifiers().forEach(verifier ->
verifier.verify(gateway.getHttpRequesterSupplier().get()));
}
+ @Test
+ void testSelectorUpdateTakesEffect(final AdminClient adminClient, final
GatewayClient gatewayClient) {
Review Comment:
This plain `@Test` runs the class's `before(..., BeforeEachSpec)` and
`after(..., AfterEachSpec)` hooks, but their resolver is registered only for
`@ShenYuScenario` invocations. JUnit fails parameter resolution before the
selector-update test executes. Move the check into the scenario provider or a
separate class without scenario-only lifecycle hooks.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginTest.java:
##########
@@ -122,6 +134,30 @@ void testSofa(final GatewayClient gateway, final CaseSpec
spec) {
spec.getVerifiers().forEach(verifier ->
verifier.verify(gateway.getHttpRequesterSupplier().get()));
}
+ @Test
+ void testSelectorUpdateTakesEffect(final AdminClient adminClient, final
GatewayClient gatewayClient) {
+ SelectorData selectorData =
newSelectorBuilder("sofa-selector-refresh", Plugin.SOFA)
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.EQUAL, "/sofa/findAll"))
+ .build();
+ SelectorDTO selector = adminClient.create(selectorData);
+ RuleDTO rule = adminClient.create(newRuleBuilder("sofa-rule-refresh",
selectorData.getName())
Review Comment:
The second argument to `newRuleBuilder` is a selector ID, not a name.
`AdminClient.create(rule)` sends it unchanged, so this rule cannot attach to
the newly created selector. Pass the ID returned by Admin.
##########
shenyu-e2e/shenyu-plugin-store-e2e-common/src/main/java/org/apache/shenyu/e2e/client/admin/AdminClient.java:
##########
@@ -234,6 +234,22 @@ public List<MetaDataDTO> listAllMetaData() {
return getMetaDataList("/meta-data/findAll",
SEARCHED_METADATAS_TYPE_REFERENCE, v -> v);
}
+ /**
+ * Create or update API metadata through the Admin endpoint.
+ *
+ * @param metaData metadata to create or update
+ */
+ public void createOrUpdateMetaData(final MetaDataDTO metaData) {
+ HttpHeaders headers = new HttpHeaders(basicAuth);
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<MetaDataDTO> entity = new HttpEntity<>(metaData, headers);
Review Comment:
The E2E `MetaDataDTO` has no `namespaceId`, but Admin's
`/meta-data/createOrUpdate` requires a nonblank, existing namespace. Posting
this DTO unchanged rejects both the refresh and restoration requests before
synchronization can be tested. Include the default namespace used by this
client's other writes.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginCases.java:
##########
@@ -67,6 +75,62 @@ private ShenYuScenarioSpec testSofaFindAll() {
.build();
}
+ private ShenYuScenarioSpec testSofaSingleParameter() {
+ return ShenYuScenarioSpec.builder()
+ .name("sofa single parameter request and response")
+ .caseSpec(ShenYuCaseSpec.builder()
+ .add((Verifier) request ->
request.get("/sofa/findById?id=7297")
+ .then().statusCode(200).body("data.id",
equalTo("7297")))
+ .add((Verifier) request ->
request.contentType("application/json")
+ .body(Map.of("id", "simple-e2e", "name",
"simple-parameter"))
Review Comment:
`insert` takes one `SofaSimpleTypeBean`, but
`SofaParamResolveServiceImpl.buildParameter` treats top-level JSON values as
positional arguments. This body supplies two string values rather than one bean
object, so it cannot exercise a successful insert. Wrap the bean fields in a
single top-level argument, as the complex-parameter case does.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginTest.java:
##########
@@ -122,6 +134,30 @@ void testSofa(final GatewayClient gateway, final CaseSpec
spec) {
spec.getVerifiers().forEach(verifier ->
verifier.verify(gateway.getHttpRequesterSupplier().get()));
}
+ @Test
+ void testSelectorUpdateTakesEffect(final AdminClient adminClient, final
GatewayClient gatewayClient) {
+ SelectorData selectorData =
newSelectorBuilder("sofa-selector-refresh", Plugin.SOFA)
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.EQUAL, "/sofa/findAll"))
+ .build();
+ SelectorDTO selector = adminClient.create(selectorData);
+ RuleDTO rule = adminClient.create(newRuleBuilder("sofa-rule-refresh",
selectorData.getName())
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.PATH_PATTERN, "/sofa/**"))
+ .build());
+ try {
+
WaitForHelper.waitForEffecting(gatewayClient.getHttpRequesterSupplier(),
exists("/sofa/findAll"));
+ SelectorData updatedSelector =
newSelectorBuilder(selectorData.getName(), Plugin.SOFA)
+ .id(selector.getId())
Review Comment:
The rebuilt selector omits `namespaceId`. `create` populates this field on
`selectorData`, but `changeSelector` does not populate it on the update
payload. Admin requires a nonblank namespace, so the update is rejected instead
of synchronized. Preserve the original selector's namespace.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginCases.java:
##########
@@ -67,6 +75,62 @@ private ShenYuScenarioSpec testSofaFindAll() {
.build();
}
+ private ShenYuScenarioSpec testSofaSingleParameter() {
+ return ShenYuScenarioSpec.builder()
+ .name("sofa single parameter request and response")
+ .caseSpec(ShenYuCaseSpec.builder()
+ .add((Verifier) request ->
request.get("/sofa/findById?id=7297")
+ .then().statusCode(200).body("data.id",
equalTo("7297")))
+ .add((Verifier) request ->
request.contentType("application/json")
+ .body(Map.of("id", "simple-e2e", "name",
"simple-parameter"))
+ .post("/sofa/insert")
+ .then().statusCode(200)
+ .body("data.id", equalTo("simple-e2e"))
+ .body("data.name",
containsString("simple-parameter")))
+ .build())
+ .build();
+ }
+
+ private ShenYuScenarioSpec testSofaComplexParameter() {
+ Map<String, Object> requestBody = Map.of("sofaComplexTypeBean", Map.of(
+ "sofaSimpleTypeBean", Map.of("id", "nested-id", "name",
"nested-name"),
+ "idLists", List.of("complex-1", "complex-2"),
+ "idMaps", Map.of("map-key", "map-value")));
+ return ShenYuScenarioSpec.builder()
+ .name("sofa complex parameter request and response")
+ .caseSpec(ShenYuCaseSpec.builder()
+ .add((Verifier) request ->
request.contentType("application/json")
+ .body(requestBody)
+ .post("/sofa/saveComplexBean")
+ .then().statusCode(200)
+ .body("data.id", equalTo("[complex-1,
complex-2]"))
+ .body("data.name",
containsString("nested-name")))
+ .build())
+ .build();
+ }
+
+ private ShenYuScenarioSpec testSofaNullResult() {
+ return ShenYuScenarioSpec.builder()
+ .name("sofa null RPC result")
+ .caseSpec(ShenYuCaseSpec.builder()
+ .add((Verifier) request ->
request.get("/sofa/findNull")
+ .then().statusCode(200)
+ .body("data", equalTo("sofa has not return
value!")))
Review Comment:
For a null RPC result, `SofaProxyService` substitutes this sentinel string,
which the default response writer emits as `text/plain`. There is no JSON
`data` field, so this assertion fails despite correct null-result handling.
Compare the entire response body.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginTest.java:
##########
@@ -122,6 +134,30 @@ void testSofa(final GatewayClient gateway, final CaseSpec
spec) {
spec.getVerifiers().forEach(verifier ->
verifier.verify(gateway.getHttpRequesterSupplier().get()));
}
+ @Test
+ void testSelectorUpdateTakesEffect(final AdminClient adminClient, final
GatewayClient gatewayClient) {
+ SelectorData selectorData =
newSelectorBuilder("sofa-selector-refresh", Plugin.SOFA)
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.EQUAL, "/sofa/findAll"))
+ .build();
+ SelectorDTO selector = adminClient.create(selectorData);
+ RuleDTO rule = adminClient.create(newRuleBuilder("sofa-rule-refresh",
selectorData.getName())
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.PATH_PATTERN, "/sofa/**"))
+ .build());
+ try {
+
WaitForHelper.waitForEffecting(gatewayClient.getHttpRequesterSupplier(),
exists("/sofa/findAll"));
+ SelectorData updatedSelector =
newSelectorBuilder(selectorData.getName(), Plugin.SOFA)
+ .id(selector.getId())
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.EQUAL, "/sofa/findById"))
+ .build();
+ adminClient.changeSelector(selector.getId(), updatedSelector);
+
WaitForHelper.waitForEffecting(gatewayClient.getHttpRequesterSupplier(),
notExists("/sofa/findAll"));
+
WaitForHelper.waitForEffecting(gatewayClient.getHttpRequesterSupplier(),
exists("/sofa/findById?id=7297"));
Review Comment:
These waits can succeed even when neither routing assertion ever holds.
`WaitForHelper.waitFor(Supplier, HttpChecker)` catches each `AssertionError`
and returns normally after exhausting retries; `waitForEffecting` only checks
that no exception escaped. Use polling that fails on exhaustion so a missing
selector refresh cannot pass this regression test.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginTest.java:
##########
@@ -122,6 +134,30 @@ void testSofa(final GatewayClient gateway, final CaseSpec
spec) {
spec.getVerifiers().forEach(verifier ->
verifier.verify(gateway.getHttpRequesterSupplier().get()));
}
+ @Test
+ void testSelectorUpdateTakesEffect(final AdminClient adminClient, final
GatewayClient gatewayClient) {
+ SelectorData selectorData =
newSelectorBuilder("sofa-selector-refresh", Plugin.SOFA)
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.EQUAL, "/sofa/findAll"))
+ .build();
+ SelectorDTO selector = adminClient.create(selectorData);
+ RuleDTO rule = adminClient.create(newRuleBuilder("sofa-rule-refresh",
selectorData.getName())
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.PATH_PATTERN, "/sofa/**"))
+ .build());
+ try {
+
WaitForHelper.waitForEffecting(gatewayClient.getHttpRequesterSupplier(),
exists("/sofa/findAll"));
+ SelectorData updatedSelector =
newSelectorBuilder(selectorData.getName(), Plugin.SOFA)
+ .id(selector.getId())
+ .conditionList(newConditions(Condition.ParamType.URI,
Condition.Operator.EQUAL, "/sofa/findById"))
+ .build();
+ adminClient.changeSelector(selector.getId(), updatedSelector);
+
WaitForHelper.waitForEffecting(gatewayClient.getHttpRequesterSupplier(),
notExists("/sofa/findAll"));
Review Comment:
On a fresh stack, the provider-registered selector already routes
`/sofa/findAll`. This test adds another selector without removing the original,
so changing only the new selector does not make the endpoint disappear. The
intended assertion remains false if this test runs before the scenarios that
delete existing selectors. Isolate the routing fixtures and wait for
synchronization before checking the transition, while preserving or restoring
routes needed by other scenarios.
##########
shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-sofa/src/test/java/org/apache/shenyu/e2e/testcase/sofa/SofaPluginCases.java:
##########
@@ -67,6 +75,62 @@ private ShenYuScenarioSpec testSofaFindAll() {
.build();
}
+ private ShenYuScenarioSpec testSofaSingleParameter() {
+ return ShenYuScenarioSpec.builder()
+ .name("sofa single parameter request and response")
+ .caseSpec(ShenYuCaseSpec.builder()
+ .add((Verifier) request ->
request.get("/sofa/findById?id=7297")
+ .then().statusCode(200).body("data.id",
equalTo("7297")))
Review Comment:
Successful SOFA bean responses contain `id` and `name` at the JSON root,
without a `data` envelope; the preserved integrated test also deserializes the
response directly into `SofaTestData`. These assertions therefore fail on a
working gateway. Replace `data.id` and `data.name` with `id` and `name` in the
new findById, insert, and saveComplexBean checks here, and in
`DataSynTest.testMetaDataRefresh` (line 91).
--
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]