You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2020/11/27 02:16:05 UTC

[servicecomb-java-chassis] 01/03: [#2081]add a test case for query with List

This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit 96afde535ff4acd6f224a40a636f15dddbd4baf6
Author: liubao <bi...@qq.com>
AuthorDate: Thu Nov 26 18:02:31 2020 +0800

    [#2081]add a test case for query with List<String>
---
 .../jaxrs/client/TestQueryParamWithListSchema.java | 154 +++++++++++++++++++++
 .../jaxrs/server/QueryParamWithListSchema.java     |  62 +++++++++
 2 files changed, 216 insertions(+)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamWithListSchema.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamWithListSchema.java
new file mode 100644
index 0000000..84ab80a
--- /dev/null
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamWithListSchema.java
@@ -0,0 +1,154 @@
+/*
+ * 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.jaxrs.client;
+
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class TestQueryParamWithListSchema implements CategorizedTestCase {
+  private RestTemplate restTemplate = RestTemplateBuilder.create();
+
+  @Override
+  public void testAllTransport() throws Exception {
+    testMulti();
+    testCSV();
+    testSSV();
+    testTSV();
+    testPipes();
+  }
+
+  @Override
+  public void testRestTransport() throws Exception {
+    testMultiRest();
+    testCSVRest();
+    testSSVRest();
+    testTSVRest();
+    testPipesRest();
+  }
+
+  @Override
+  // highway do not handle empty/default/null
+  public void testHighwayTransport() throws Exception {
+    testMultiHighway();
+    testCSVHighway();
+    testSSVHighway();
+    testTSVHighway();
+    testPipesHighway();
+  }
+
+  private void testCSVHighway() {
+    TestMgr.check("null",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListCSV?", String.class));
+  }
+
+  private void testCSVRest() {
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListCSV?", String.class));
+  }
+
+  private void testSSV() {
+    TestMgr.check("[1, 2]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListSSV?queryList=1%202", String.class));
+    TestMgr.check("[, ]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListSSV?queryList=%20", String.class));
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListSSV?queryList=", String.class));
+  }
+
+  private void testTSVHighway() {
+    TestMgr.check("null",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListTSV?", String.class));
+  }
+
+  private void testTSVRest() {
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListTSV?", String.class));
+  }
+
+  private void testTSV() {
+    TestMgr.check("[1, 2]",
+        restTemplate
+            .getForObject("cse://jaxrs/queryList/queryListTSV?queryList={1}", String.class, "1\t2"));
+    TestMgr.check("[, ]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListTSV?queryList={1}", String.class, "\t"));
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListTSV?queryList=", String.class));
+  }
+
+  private void testPipesHighway() {
+    TestMgr.check("null",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListPIPES?", String.class));
+  }
+
+  private void testPipesRest() {
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListPIPES?", String.class));
+  }
+
+  private void testPipes() {
+    TestMgr.check("[1, 2]",
+        restTemplate
+            .getForObject("cse://jaxrs/queryList/queryListPIPES?queryList={1}", String.class, "1|2"));
+    TestMgr.check("[, ]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListPIPES?queryList={1}", String.class, "|"));
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListPIPES?queryList=", String.class));
+  }
+
+  private void testSSVHighway() {
+    TestMgr.check("null",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListSSV?", String.class));
+  }
+
+  private void testSSVRest() {
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListSSV?", String.class));
+  }
+
+  private void testCSV() {
+    TestMgr.check("[1, 2]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListCSV?queryList=1,2", String.class));
+    TestMgr.check("[, ]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListCSV?queryList=,", String.class));
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListCSV?queryList=", String.class));
+  }
+
+  private void testMultiHighway() {
+    TestMgr.check("null",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListMULTI?", String.class));
+  }
+
+  private void testMultiRest() {
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListMULTI?", String.class));
+  }
+
+  private void testMulti() {
+    TestMgr.check("[1, 2]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListMULTI?queryList=1&queryList=2", String.class));
+    TestMgr.check("[, ]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListMULTI?queryList=&queryList=", String.class));
+    TestMgr.check("[]",
+        restTemplate.getForObject("cse://jaxrs/queryList/queryListMULTI?queryList=", String.class));
+  }
+}
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamWithListSchema.java b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamWithListSchema.java
new file mode 100644
index 0000000..1f0b10b
--- /dev/null
+++ b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamWithListSchema.java
@@ -0,0 +1,62 @@
+/*
+ * 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.jaxrs.server;
+
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+import io.swagger.annotations.ApiParam;
+
+@RestSchema(schemaId = "QueryParamWithListSchema")
+@Path("/queryList")
+public class QueryParamWithListSchema {
+  @Path("queryListCSV")
+  @GET
+  public String queryListCSV(@ApiParam(collectionFormat = "csv") @QueryParam("queryList") List<String> queryList) {
+    return queryList == null ? "null" : queryList.toString();
+  }
+
+  @Path("queryListSSV")
+  @GET
+  public String queryListSSV(@ApiParam(collectionFormat = "ssv") @QueryParam("queryList") List<String> queryList) {
+    return queryList == null ? "null" : queryList.toString();
+  }
+
+  @Path("queryListTSV")
+  @GET
+  public String queryListTSV(@ApiParam(collectionFormat = "tsv") @QueryParam("queryList") List<String> queryList) {
+    return queryList == null ? "null" : queryList.toString();
+  }
+
+  @Path("queryListPIPES")
+  @GET
+  public String queryListPIPES(@ApiParam(collectionFormat = "pipes") @QueryParam("queryList") List<String> queryList) {
+    return queryList == null ? "null" : queryList.toString();
+  }
+
+  @Path("queryListMULTI")
+  @GET
+  public String queryListMULTI(@ApiParam(collectionFormat = "multi") @QueryParam("queryList") List<String> queryList) {
+    return queryList == null ? "null" : queryList.toString();
+  }
+}