This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 1e90c2bf8 [#4268]add test case for issue (#4273)
1e90c2bf8 is described below
commit 1e90c2bf82caa3378d368b9546d9429fe8e788f0
Author: liubao68 <[email protected]>
AuthorDate: Wed Mar 27 17:39:28 2024 +0800
[#4268]add test case for issue (#4273)
---
.../springmvc/client/TestAnnotationsSchema.java | 98 ++++++++++++++++++++++
.../springmvc/server/AnnotationsSchema.java} | 9 +-
.../demo/springmvc/SpringmvcClient.java | 43 ----------
.../springmvc/client/TestAnnotationsSchema.java | 98 ++++++++++++++++++++++
...AnnotationsTest.java => AnnotationsSchema.java} | 7 +-
5 files changed, 209 insertions(+), 46 deletions(-)
diff --git
a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/TestAnnotationsSchema.java
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/TestAnnotationsSchema.java
new file mode 100644
index 000000000..7d77fa1be
--- /dev/null
+++
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/TestAnnotationsSchema.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.springboot.springmvc.client;
+
+import org.apache.http.HttpStatus;
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.demo.controller.Person;
+import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
+import
org.apache.servicecomb.provider.springmvc.reference.UrlWithServiceNameClientHttpRequestFactory;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class TestAnnotationsSchema implements CategorizedTestCase {
+ private static final String microserviceName = "springmvc";
+
+ private static final RestTemplate templateUrlWithServiceName = new
CseRestTemplate();
+
+ @Override
+ public void testRestTransport() throws Exception {
+ templateUrlWithServiceName.setRequestFactory(new
UrlWithServiceNameClientHttpRequestFactory());
+ testRequiredBody(templateUrlWithServiceName, microserviceName);
+ testRegExpPath();
+ }
+
+ private void testRegExpPath() {
+ String prefix = "cse://" + microserviceName;
+ String result = templateUrlWithServiceName.getForObject(prefix +
"/annotations/testRegExpPath/a?name={name}",
+ String.class, "a");
+ TestMgr.check("a", result);
+ result = templateUrlWithServiceName.getForObject(prefix +
"/annotations/testRegExpPath/a/b?name={name}",
+ String.class, "ab");
+ TestMgr.check("ab", result);
+ result = templateUrlWithServiceName.getForObject(prefix +
"/annotations/testRegExpPath/a/b/c?name={name}",
+ String.class, "abc");
+ TestMgr.check("abc", result);
+ }
+
+ private static void testRequiredBody(RestTemplate template, String
microserviceName) {
+ String prefix = "cse://" + microserviceName;
+ Person user = new Person();
+
+ TestMgr.check("No user data found",
+ template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
+ user,
+ String.class,
+ "ha"));
+
+ user.setName("world");
+ TestMgr.check("ha world",
+ template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
+ user,
+ String.class,
+ "ha"));
+
+ TestMgr.check("No user data found",
+ template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
+ null,
+ String.class,
+ "ha"));
+
+ TestMgr.check("No user name found",
+ template.postForObject(prefix + "/annotations/say",
+ "",
+ String.class,
+ "ha"));
+ TestMgr.check("test",
+ template.postForObject(prefix + "/annotations/say",
+ "test",
+ String.class,
+ "ha"));
+
+ try {
+ template.postForObject(prefix + "/annotations/testRequiredBody",
+ null,
+ String.class);
+ TestMgr.fail("should fail");
+ } catch (InvocationException e) {
+ TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST);
+ }
+ }
+}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsTest.java
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/AnnotationsSchema.java
similarity index 92%
copy from
demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsTest.java
copy to
demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/AnnotationsSchema.java
index a6bd75957..b1bcaba83 100644
---
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsTest.java
+++
b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/AnnotationsSchema.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.servicecomb.demo.springmvc.server;
+package org.apache.servicecomb.springboot.springmvc.server;
import org.apache.servicecomb.demo.controller.Person;
import org.apache.servicecomb.provider.rest.common.RestSchema;
@@ -34,7 +34,7 @@ import jakarta.ws.rs.core.MediaType;
@RestSchema(schemaId = "annotations")
@RequestMapping(path = "/springmvc/annotations", produces =
MediaType.APPLICATION_JSON)
-public class AnnotationsTest {
+public class AnnotationsSchema {
@GetMapping(path = "/add")
public int add(@RequestParam(name = "a", defaultValue = "10") int a,
@RequestParam(name = "b", defaultValue = "10") int b) {
@@ -78,4 +78,9 @@ public class AnnotationsTest {
}
return user.getName();
}
+
+ @RequestMapping(path = "/testRegExpPath/{path: .+}", method =
RequestMethod.GET)
+ public String testRegExpPath(@RequestParam("name") String name) {
+ return name;
+ }
}
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
index 72d6b845b..291900ea4 100644
---
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java
@@ -216,7 +216,6 @@ public class SpringmvcClient {
testControllerAllTransport(templateUrlWithServiceName, microserviceName);
testController();
- testRequiredBody(templateUrlWithServiceName, microserviceName);
testSpringMvcDefaultValuesAllTransport(templateUrlWithServiceName,
microserviceName);
testSpringMvcDefaultValuesJavaPrimitiveAllTransport(templateUrlWithServiceName,
microserviceName);
testThirdService();
@@ -340,49 +339,7 @@ public class SpringmvcClient {
TestMgr.check("ha world", controller.saySomething("ha", user));
}
- private static void testRequiredBody(RestTemplate template, String
microserviceName) {
- String prefix = "cse://" + microserviceName;
- Person user = new Person();
-
- TestMgr.check("No user data found",
- template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
- user,
- String.class,
- "ha"));
-
- user.setName("world");
- TestMgr.check("ha world",
- template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
- user,
- String.class,
- "ha"));
- TestMgr.check("No user data found",
- template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
- null,
- String.class,
- "ha"));
-
- TestMgr.check("No user name found",
- template.postForObject(prefix + "/annotations/say",
- "",
- String.class,
- "ha"));
- TestMgr.check("test",
- template.postForObject(prefix + "/annotations/say",
- "test",
- String.class,
- "ha"));
-
- try {
- template.postForObject(prefix + "/annotations/testRequiredBody",
- null,
- String.class);
- TestMgr.fail("should fail");
- } catch (InvocationException e) {
- TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST);
- }
- }
private static void testSpringMvcDefaultValuesRest(RestTemplate template,
String microserviceName) {
String cseUrlPrefix = "cse://" + microserviceName +
"/SpringMvcDefaultValues/";
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestAnnotationsSchema.java
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestAnnotationsSchema.java
new file mode 100644
index 000000000..89f786238
--- /dev/null
+++
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestAnnotationsSchema.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.demo.springmvc.client;
+
+import org.apache.http.HttpStatus;
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.demo.controller.Person;
+import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
+import
org.apache.servicecomb.provider.springmvc.reference.UrlWithServiceNameClientHttpRequestFactory;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class TestAnnotationsSchema implements CategorizedTestCase {
+ private static final String microserviceName = "springmvc";
+
+ private static final RestTemplate templateUrlWithServiceName = new
CseRestTemplate();
+
+ @Override
+ public void testAllTransport() throws Exception {
+ templateUrlWithServiceName.setRequestFactory(new
UrlWithServiceNameClientHttpRequestFactory());
+ testRequiredBody(templateUrlWithServiceName, microserviceName);
+ testRegExpPath();
+ }
+
+ private void testRegExpPath() {
+ String prefix = "cse://" + microserviceName;
+ String result = templateUrlWithServiceName.getForObject(prefix +
"/annotations/testRegExpPath/a?name={name}",
+ String.class, "a");
+ TestMgr.check("a", result);
+ result = templateUrlWithServiceName.getForObject(prefix +
"/annotations/testRegExpPath/a/b?name={name}",
+ String.class, "ab");
+ TestMgr.check("ab", result);
+ result = templateUrlWithServiceName.getForObject(prefix +
"/annotations/testRegExpPath/a/b/c?name={name}",
+ String.class, "abc");
+ TestMgr.check("abc", result);
+ }
+
+ private static void testRequiredBody(RestTemplate template, String
microserviceName) {
+ String prefix = "cse://" + microserviceName;
+ Person user = new Person();
+
+ TestMgr.check("No user data found",
+ template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
+ user,
+ String.class,
+ "ha"));
+
+ user.setName("world");
+ TestMgr.check("ha world",
+ template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
+ user,
+ String.class,
+ "ha"));
+
+ TestMgr.check("No user data found",
+ template.postForObject(prefix +
"/annotations/saysomething?prefix={prefix}",
+ null,
+ String.class,
+ "ha"));
+
+ TestMgr.check("No user name found",
+ template.postForObject(prefix + "/annotations/say",
+ "",
+ String.class,
+ "ha"));
+ TestMgr.check("test",
+ template.postForObject(prefix + "/annotations/say",
+ "test",
+ String.class,
+ "ha"));
+
+ try {
+ template.postForObject(prefix + "/annotations/testRequiredBody",
+ null,
+ String.class);
+ TestMgr.fail("should fail");
+ } catch (InvocationException e) {
+ TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST);
+ }
+ }
+}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsTest.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsSchema.java
similarity index 94%
rename from
demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsTest.java
rename to
demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsSchema.java
index a6bd75957..45f2c01e4 100644
---
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsTest.java
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/AnnotationsSchema.java
@@ -34,7 +34,7 @@ import jakarta.ws.rs.core.MediaType;
@RestSchema(schemaId = "annotations")
@RequestMapping(path = "/springmvc/annotations", produces =
MediaType.APPLICATION_JSON)
-public class AnnotationsTest {
+public class AnnotationsSchema {
@GetMapping(path = "/add")
public int add(@RequestParam(name = "a", defaultValue = "10") int a,
@RequestParam(name = "b", defaultValue = "10") int b) {
@@ -78,4 +78,9 @@ public class AnnotationsTest {
}
return user.getName();
}
+
+ @RequestMapping(path = "/testRegExpPath/{path: .+}", method =
RequestMethod.GET)
+ public String testRegExpPath(@RequestParam("name") String name) {
+ return name;
+ }
}