You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/11/18 12:33:43 UTC

[servicecomb-java-chassis] 01/01: add test case

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

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

commit fb290c0605a1b330b75f22c454a4c326e5fecede
Author: liubao <bi...@qq.com>
AuthorDate: Fri Nov 18 20:32:59 2022 +0800

    add test case
---
 .../demo/jaxrs/client/TestQueryParamSchema.java    |  6 ++
 .../demo/jaxrs/server/QueryParamSchema.java        |  6 ++
 .../springmvc/client/TestCookieValueSchema.java    | 76 ++++++++++++++++++++++
 .../demo/springmvc/server/CookieValueSchema.java}  | 26 ++++----
 .../springmvc/server/ProducerTestsAfterBootup.java |  4 +-
 5 files changed, 105 insertions(+), 13 deletions(-)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamSchema.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamSchema.java
index dccffc20e..05e446a15 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamSchema.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamSchema.java
@@ -38,6 +38,12 @@ public class TestQueryParamSchema implements CategorizedTestCase {
   @Override
   public void testAllTransport() throws Exception {
     testQueryParamEncodingPlus();
+    testGetQueryStringNull();
+  }
+
+  private void testGetQueryStringNull() {
+    TestMgr.check(null,
+        restTemplate.getForObject("servicecomb://jaxrs/queryParam/testGetQueryString", String.class));
   }
 
   private void testQueryParamEncodingPlus() {
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java
index a15ce1b34..be0ef0eb4 100644
--- a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java
+++ b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java
@@ -31,4 +31,10 @@ public class QueryParamSchema {
   public String testQueryEncode(@QueryParam("param") String param) {
     return param;
   }
+
+  @Path("testGetQueryString")
+  @GET
+  public String testGetQueryString(@QueryParam("param") String param) {
+    return param;
+  }
 }
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestCookieValueSchema.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestCookieValueSchema.java
new file mode 100644
index 000000000..534183e94
--- /dev/null
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestCookieValueSchema.java
@@ -0,0 +1,76 @@
+/*
+ * 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.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+@Component
+public class TestCookieValueSchema implements CategorizedTestCase {
+  private final RestTemplate restTemplate = RestTemplateBuilder.create();
+
+  @Override
+  public void testAllTransport() {
+    testCookieValueInt();
+    testCookieValueIntDefault();
+    testCookieValueString();
+    testCookieValueStringDefault();
+  }
+
+  private void testCookieValueIntDefault() {
+    Integer result =
+        restTemplate.getForObject("servicecomb://springmvc/cookie/testCookieDefaultValueInt",
+            Integer.class);
+    TestMgr.check(100, result);
+  }
+
+  private void testCookieValueStringDefault() {
+    String result =
+        restTemplate.getForObject("servicecomb://springmvc/cookie/testCookieDefaultValueString",
+            String.class);
+    TestMgr.check("foo", result);
+  }
+
+  private void testCookieValueInt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add(HttpHeaders.COOKIE, "param=3");
+
+    HttpEntity<?> requestEntity = new HttpEntity<>(headers);
+    ResponseEntity<Integer> result =
+        restTemplate.exchange("servicecomb://springmvc/cookie/testCookieDefaultValueInt",
+            HttpMethod.GET, requestEntity, Integer.class);
+    TestMgr.check(3, result.getBody());
+  }
+
+  private void testCookieValueString() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add(HttpHeaders.COOKIE, "param=hi");
+
+    HttpEntity<?> requestEntity = new HttpEntity<>(headers);
+    ResponseEntity<String> result =
+        restTemplate.exchange("servicecomb://springmvc/cookie/testCookieDefaultValueString",
+            HttpMethod.GET, requestEntity, String.class);
+    TestMgr.check("hi", result.getBody());
+  }
+}
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CookieValueSchema.java
similarity index 53%
copy from demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java
copy to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CookieValueSchema.java
index a15ce1b34..5994788ad 100644
--- a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamSchema.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CookieValueSchema.java
@@ -15,20 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.servicecomb.demo.jaxrs.server;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.QueryParam;
+package org.apache.servicecomb.demo.springmvc.server;
 
 import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.CookieValue;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RestSchema(schemaId = "CookieValueSchema")
+@RequestMapping(path = "/cookie", produces = MediaType.APPLICATION_JSON_VALUE)
+public class CookieValueSchema {
+  @GetMapping(path = "/testCookieDefaultValueInt")
+  public int testCookieDefaultValueInt(@CookieValue(name = "param", defaultValue = "100") int param) {
+    return param;
+  }
 
-@RestSchema(schemaId = "QueryParamSchema")
-@Path("/queryParam")
-public class QueryParamSchema {
-  @Path("testQueryEncode")
-  @GET
-  public String testQueryEncode(@QueryParam("param") String param) {
+  @GetMapping(path = "/testCookieDefaultValueString")
+  public String testCookieDefaultValueString(@CookieValue(name = "param", defaultValue = "foo") String param) {
     return param;
   }
 }
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
index ebbe1dd8c..e84383681 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
@@ -91,9 +91,9 @@ public class ProducerTestsAfterBootup implements BootListener {
 
   public void testRegisteredBasePath() {
     if (DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport", true).get()) {
-      TestMgr.check(21, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
-    } else {
       TestMgr.check(22, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+    } else {
+      TestMgr.check(23, RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
     }
   }