You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/08/13 10:48:15 UTC

[GitHub] heyile closed pull request #869: [SCB-839] move int type test case from demo to integration-test

heyile closed pull request #869: [SCB-839] move int type test case from demo to integration-test
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/869
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index a52e787f5..514b870dc 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -24,8 +24,9 @@
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.it.deploy.Deploys;
 import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.apache.servicecomb.it.testcase.base.TestDataTypeJaxrs;
 import org.apache.servicecomb.it.testcase.base.TestDataTypePojo;
-import org.apache.servicecomb.it.testcase.base.TestDataTypeRest;
+import org.apache.servicecomb.it.testcase.base.TestDataTypeSpringmvc;
 import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
 
 
@@ -111,8 +112,8 @@ private static void testStandalone() throws Throwable {
 
   private static void testDataType() {
     testDataType(ProducerDevMode.Pojo, TestDataTypePojo.class);
-    testDataType(ProducerDevMode.Jaxrs, TestDataTypeRest.class);
-    testDataType(ProducerDevMode.Springmvc, TestDataTypeRest.class);
+    testDataType(ProducerDevMode.Jaxrs, TestDataTypeJaxrs.class);
+    testDataType(ProducerDevMode.Springmvc, TestDataTypeSpringmvc.class);
 
     ITJUnitUtils.getParents().push("edge");
 //    runEdge();
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeJaxrs.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeJaxrs.java
new file mode 100644
index 000000000..691b8bd69
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeJaxrs.java
@@ -0,0 +1,258 @@
+/*
+ * 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.it.testcase.base;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.core.Const;
+import org.apache.servicecomb.it.extend.engine.ITClientHttpRequestFactory;
+import org.apache.servicecomb.it.extend.engine.ITInvoker;
+import org.apache.servicecomb.it.testcase.support.DataTypeRestIntf;
+import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
+import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
+import org.junit.Test;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+public class TestDataTypeJaxrs {
+  private static DataTypeRestIntf dataTypeIntf;
+
+  private static ITClientHttpRequestFactory clientHttpRequestFactory = new ITClientHttpRequestFactory();
+
+  private static RestTemplate restTemplate = new CseRestTemplate();
+
+  private static String urlPrefix;
+
+  private static String transport;
+
+  static {
+    restTemplate.setRequestFactory(clientHttpRequestFactory);
+  }
+
+  public static void init(String transport, ProducerDevMode producerDevMode) {
+    TestDataTypeJaxrs.transport = transport;
+    dataTypeIntf = ITInvoker
+        .createProxy("it-producer", "dataType" + producerDevMode.name(), transport, DataTypeRestIntf.class);
+
+    clientHttpRequestFactory.setTransport(transport);
+
+    urlPrefix = "cse://it-producer/v1/dataType" + producerDevMode.name();
+  }
+
+  @Test
+  public void checkTransport_intf() {
+    assertEquals(transport, dataTypeIntf.checkTransport());
+  }
+
+  @Test
+  public void checkTransport_rt() {
+    assertEquals(transport, restTemplate.getForObject(urlPrefix + "/checkTransport", String.class));
+  }
+
+  @Test
+  public void intPath_intf() {
+    int expect = 10;
+    assertEquals(expect, dataTypeIntf.intPath(expect));
+  }
+
+  @Test
+  public void intPath_rt() {
+    int expect = 10;
+    assertEquals(expect, (int) restTemplate.getForObject(urlPrefix + "/intPath/" + expect, int.class));
+  }
+
+  @Test
+  public void intQuery_intf() {
+    assertEquals(10, dataTypeIntf.intQuery(10));
+  }
+
+  @Test
+  public void intQuery_rt() {
+    int expect = 10;
+    assertEquals(expect, (int) restTemplate.getForObject(urlPrefix + "/intQuery?input=" + expect, int.class));
+  }
+
+  @Test
+  public void intHeader_intf() {
+    assertEquals(10, dataTypeIntf.intHeader(10));
+  }
+
+  @Test
+  public void intHeader_rt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("input", "10");
+    @SuppressWarnings("rawtypes")
+    HttpEntity entity = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intHeader",
+        HttpMethod.GET,
+        entity,
+        int.class);
+    assertEquals(10, (int) response.getBody());
+  }
+
+  @Test
+  public void intCookie_intf() {
+    assertEquals(10, dataTypeIntf.intCookie(10));
+  }
+
+  @Test
+  public void intCookie_rt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("Cookie", "input=10");
+    @SuppressWarnings("rawtypes")
+    HttpEntity entity = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intCookie",
+        HttpMethod.GET,
+        entity,
+        int.class);
+    assertEquals(10, (int) response.getBody());
+  }
+
+  @Test
+  public void intBody_intf() {
+    assertEquals(10, dataTypeIntf.intBody(10));
+  }
+
+  @Test
+  public void intBody_rt() {
+    assertEquals(10, (int) restTemplate.postForObject(urlPrefix + "/intBody", 10, int.class));
+  }
+
+  @Test
+  public void intForm_intf() {
+    assertEquals(10, dataTypeIntf.intForm(10));
+  }
+
+  @Test
+  public void intForm_rt() {
+    HttpHeaders formHeaders = new HttpHeaders();
+    formHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+    Map<String, Integer> map = new HashMap<>();
+
+    map.put("a", 10);
+    HttpEntity<Map<String, Integer>> formEntiry = new HttpEntity<>(map, formHeaders);
+
+    assertEquals(10, (int) restTemplate.postForEntity(urlPrefix + "/intForm", formEntiry, int.class).getBody());
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    assertEquals(5, (int) restTemplate.postForEntity(urlPrefix + "/intForm", params, int.class).getBody());
+  }
+
+  @Test
+  public void intQueryWithDefault_rt() {
+    int expect = 10;
+    assertEquals(expect,
+        (int) restTemplate.getForObject(urlPrefix + "/intQueryWithDefault?input=" + expect, int.class));
+    assertEquals(13, (int) restTemplate.getForObject(urlPrefix + "/intQueryWithDefault", int.class));
+  }
+
+  @Test
+  public void intHeaderWithDefault_rt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("input", "11");
+    @SuppressWarnings("rawtypes")
+    HttpEntity entity = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intHeaderWithDefault",
+        HttpMethod.GET,
+        entity,
+        int.class);
+    assertEquals(11, (int) response.getBody());
+    headers.remove("input");
+    @SuppressWarnings("rawtypes")
+    HttpEntity<Object> entity1 = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response1 = restTemplate.exchange(urlPrefix + "/intHeaderWithDefault",
+        HttpMethod.GET,
+        entity1,
+        int.class);
+    assertEquals(13, (int) response1.getBody());
+  }
+
+//  @Test
+//  public void intCookieWithDefault_rt() {
+//    HttpHeaders headers = new HttpHeaders();
+////    headers.add("Cookie", "input=10");
+////    @SuppressWarnings("rawtypes")
+////    HttpEntity entity = new HttpEntity<>( headers);
+////    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intCookieWithDefault",
+////        HttpMethod.GET,
+////        entity,
+////        int.class);
+////    assertEquals(10, (int) response.getBody());
+////    headers.remove("Cookie");
+//    headers.add("Cookie", "input=10");
+//
+//    @SuppressWarnings("rawtypes")
+//    HttpEntity entity1 = new HttpEntity<>(headers);
+//    ResponseEntity<Integer> response1 = restTemplate.exchange(urlPrefix + "/intCookieWithDefault",
+//        HttpMethod.GET,
+//        entity1,
+//        Integer.class);
+//    assertEquals(10, (int) response1.getBody());
+//  }
+
+  @Test
+  public void intFormWithDefault_rt() {
+    HttpHeaders formHeaders = new HttpHeaders();
+    formHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+    Map<String, Integer> map = new HashMap<>();
+
+    map.put("a", 10);
+    HttpEntity<Map<String, Integer>> formEntiry = new HttpEntity<>(map, formHeaders);
+
+    assertEquals(10,
+        (int) restTemplate.postForEntity(urlPrefix + "/intFormWithDefault", formEntiry, int.class).getBody());
+
+    map.remove("a");
+
+    HttpEntity<Map<String, Integer>> formEntiry1 = new HttpEntity<>(map, formHeaders);
+
+    assertEquals(13,
+        (int) restTemplate.postForEntity(urlPrefix + "/intFormWithDefault", formEntiry1, int.class).getBody());
+  }
+
+  //伪契约不支持 highway
+  @Test
+  public void testRequest_rt() {
+    //@context don not support highway
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "3");
+    if (transport.equals(Const.RESTFUL)) {
+      int result = restTemplate.getForObject(urlPrefix + "/request?a={a}&b={b}", Integer.class, 5, 4);
+      assertEquals(1, result);
+    }
+  }
+
+  @Test
+  public void testDefault_intf() {
+    int result = dataTypeIntf.defaultPath();
+    assertEquals(result, 100);
+  }
+
+  @Test
+  public void testDefault_rt() {
+    Integer result = restTemplate.getForObject(urlPrefix, Integer.class);
+    assertEquals((int) result, 100);
+  }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypePojo.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypePojo.java
index a7d660eff..c9bc8e886 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypePojo.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypePojo.java
@@ -16,12 +16,16 @@
  */
 package org.apache.servicecomb.it.testcase.base;
 
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.servicecomb.it.extend.engine.ITClientHttpRequestFactory;
 import org.apache.servicecomb.it.extend.engine.ITInvoker;
 import org.apache.servicecomb.it.testcase.support.DataTypePojoIntf;
 import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
 import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
-import org.junit.Assert;
 import org.junit.Test;
 import org.springframework.web.client.RestTemplate;
 
@@ -51,16 +55,45 @@ public static void init(String transport, ProducerDevMode producerDevMode) {
 
   @Test
   public void checkTransport_intf() {
-    Assert.assertEquals(transport, dataTypePojoIntf.checkTransport());
+    assertEquals(transport, dataTypePojoIntf.checkTransport());
   }
 
   @Test
   public void checkTransport_rt() {
-    Assert.assertEquals(transport, restTemplate.postForObject(urlPrefix + "/checkTransport", "", String.class));
+    assertEquals(transport, restTemplate.postForObject(urlPrefix + "/checkTransport", "", String.class));
   }
 
   @Test
   public void intBody_intf() {
-    Assert.assertEquals(10, dataTypePojoIntf.intBody(10));
+    assertEquals(10, dataTypePojoIntf.intBody(10));
+  }
+
+  @Test
+  public void intBody_rt() {
+    Map<String, Integer> map = new HashMap<>();
+    Map<String, String> map1 = new HashMap<>();
+    map.put("input", 10);
+    map1.put("input", "10");
+
+    assertEquals(10, (int) restTemplate.postForObject(urlPrefix + "/intBody", map, int.class));
+    assertEquals(10, (int) restTemplate.postForObject(urlPrefix + "/intBody", map1
+        , int.class));
+  }
+
+  @Test
+  public void intReduce_intf() {
+    assertEquals(8, dataTypePojoIntf.reduce(10, 2));
+  }
+
+  @Test
+  public void intReduce_rt() {
+    Map<String, Integer> map = new HashMap<>();
+    map.put("a", 10);
+    map.put("b", 2);
+    Map<String, String> map1 = new HashMap<>();
+    map1.put("a", "10");
+    map1.put("b", "2");
+    assertEquals(8, (int) restTemplate.postForObject(urlPrefix + "/reduce", map, int.class));
+    assertEquals(8, (int) restTemplate.postForObject(urlPrefix + "/reduce", map1, int.class));
   }
 }
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeRest.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeRest.java
deleted file mode 100644
index 72d8c5dd2..000000000
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeRest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.it.testcase.base;
-
-import org.apache.servicecomb.it.extend.engine.ITClientHttpRequestFactory;
-import org.apache.servicecomb.it.extend.engine.ITInvoker;
-import org.apache.servicecomb.it.testcase.support.DataTypeRestIntf;
-import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
-import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
-import org.junit.Assert;
-import org.junit.Test;
-import org.springframework.web.client.RestTemplate;
-
-public class TestDataTypeRest {
-  private static DataTypeRestIntf dataTypeIntf;
-
-  private static ITClientHttpRequestFactory clientHttpRequestFactory = new ITClientHttpRequestFactory();
-
-  private static RestTemplate restTemplate = new CseRestTemplate();
-
-  private static String urlPrefix;
-
-  private static String transport;
-
-  static {
-    restTemplate.setRequestFactory(clientHttpRequestFactory);
-  }
-
-  public static void init(String transport, ProducerDevMode producerDevMode) {
-    TestDataTypeRest.transport = transport;
-    dataTypeIntf = ITInvoker
-        .createProxy("it-producer", "dataType" + producerDevMode.name(), transport, DataTypeRestIntf.class);
-
-    clientHttpRequestFactory.setTransport(transport);
-
-    urlPrefix = "cse://it-producer/v1/dataType" + producerDevMode.name();
-  }
-
-  @Test
-  public void checkTransport_intf() {
-    Assert.assertEquals(transport, dataTypeIntf.checkTransport());
-  }
-
-  @Test
-  public void checkTransport_rt() {
-    Assert.assertEquals(transport, restTemplate.getForObject(urlPrefix + "/checkTransport", String.class));
-  }
-
-  @Test
-  public void intPath_intf() {
-    int expect = 10;
-    Assert.assertEquals(expect, dataTypeIntf.intPath(expect));
-  }
-
-  @Test
-  public void intPath_rt() {
-    int expect = 10;
-    Assert.assertEquals(expect, (int) restTemplate.getForObject(urlPrefix + "/intPath/" + expect, int.class));
-  }
-
-  @Test
-  public void intQuery() {
-    Assert.assertEquals(10, dataTypeIntf.intQuery(10));
-  }
-
-  @Test
-  public void intHeader() {
-    Assert.assertEquals(10, dataTypeIntf.intHeader(10));
-  }
-
-  @Test
-  public void intCookie() {
-    Assert.assertEquals(10, dataTypeIntf.intCookie(10));
-  }
-
-  @Test
-  public void intBody() {
-    Assert.assertEquals(10, dataTypeIntf.intBody(10));
-  }
-}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeSpringmvc.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeSpringmvc.java
new file mode 100644
index 000000000..9d98eb19b
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestDataTypeSpringmvc.java
@@ -0,0 +1,302 @@
+/*
+ * 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.it.testcase.base;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.it.extend.engine.ITClientHttpRequestFactory;
+import org.apache.servicecomb.it.extend.engine.ITInvoker;
+import org.apache.servicecomb.it.testcase.support.DataTypeRestIntf;
+import org.apache.servicecomb.it.testcase.support.ProducerDevMode;
+import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
+import org.junit.Test;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+public class TestDataTypeSpringmvc {
+  private static DataTypeRestIntf dataTypeIntf;
+
+  private static ITClientHttpRequestFactory clientHttpRequestFactory = new ITClientHttpRequestFactory();
+
+  private static RestTemplate restTemplate = new CseRestTemplate();
+
+  private static String urlPrefix;
+
+  private static String transport;
+
+  static {
+    restTemplate.setRequestFactory(clientHttpRequestFactory);
+  }
+
+  public static void init(String transport, ProducerDevMode producerDevMode) {
+    TestDataTypeSpringmvc.transport = transport;
+    dataTypeIntf = ITInvoker
+        .createProxy("it-producer", "dataType" + producerDevMode.name(), transport, DataTypeRestIntf.class);
+
+    clientHttpRequestFactory.setTransport(transport);
+
+    urlPrefix = "cse://it-producer/v1/dataType" + producerDevMode.name();
+  }
+
+  @Test
+  public void checkTransport_intf() {
+    assertEquals(transport, dataTypeIntf.checkTransport());
+  }
+
+  @Test
+  public void checkTransport_rt() {
+    assertEquals(transport, restTemplate.getForObject(urlPrefix + "/checkTransport", String.class));
+  }
+
+  @Test
+  public void intPath_intf() {
+    int expect = 10;
+    assertEquals(expect, dataTypeIntf.intPath(expect));
+  }
+
+  @Test
+  public void intPath_rt() {
+    int expect = 10;
+    assertEquals(expect, (int) restTemplate.getForObject(urlPrefix + "/intPath/" + expect, int.class));
+  }
+
+  @Test
+  public void intQuery_intf() {
+    assertEquals(10, dataTypeIntf.intQuery(10));
+  }
+
+  @Test
+  public void intQuery_rt() {
+    int expect = 10;
+    assertEquals(expect, (int) restTemplate.getForObject(urlPrefix + "/intQuery?input=" + expect, int.class));
+  }
+
+  @Test
+  public void intHeader_intf() {
+    assertEquals(10, dataTypeIntf.intHeader(10));
+  }
+
+  @Test
+  public void intHeader_rt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("input", "10");
+    @SuppressWarnings("rawtypes")
+    HttpEntity entity = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intHeader",
+        HttpMethod.GET,
+        entity,
+        int.class);
+    assertEquals(10, (int) response.getBody());
+  }
+
+  @Test
+  public void intCookie_intf() {
+    assertEquals(10, dataTypeIntf.intCookie(10));
+  }
+
+  @Test
+  public void intCookie_rt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("Cookie", "input=10");
+    @SuppressWarnings("rawtypes")
+    HttpEntity entity = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intCookie",
+        HttpMethod.GET,
+        entity,
+        int.class);
+    assertEquals(10, (int) response.getBody());
+  }
+
+  @Test
+  public void intBody_intf() {
+    assertEquals(10, dataTypeIntf.intBody(10));
+  }
+
+  @Test
+  public void intBody_rt() {
+    assertEquals(10, (int) restTemplate.postForObject(urlPrefix + "/intBody", 10, int.class));
+  }
+
+  @Test
+  public void intForm_intf() {
+    assertEquals(10, dataTypeIntf.intForm(10));
+  }
+
+  @Test
+  public void intForm_rt() {
+    HttpHeaders formHeaders = new HttpHeaders();
+    formHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+    Map<String, Integer> map = new HashMap<>();
+
+    map.put("form1", 10);
+    HttpEntity<Map<String, Integer>> formEntiry = new HttpEntity<>(map, formHeaders);
+
+    assertEquals(10, (int) restTemplate.postForEntity(urlPrefix + "/intForm", formEntiry, int.class).getBody());
+    //两种调用方式都可以
+    assertEquals(10, (int) restTemplate.postForEntity(urlPrefix + "/intForm", map, int.class).getBody());
+  }
+
+  @Test
+  public void intAttribute_intf() {
+    assertEquals(10, dataTypeIntf.intAttribute(10));
+  }
+
+  @Test
+  public void intAttribute_rt() {
+    Map<String, Integer> map = new HashMap<>();
+    map.put("a", 10);
+    int result = restTemplate.postForObject(urlPrefix + "/intAttribute", map, Integer.class);
+    assertEquals(10, result);
+  }
+
+  @Test
+  public void intQueryWithDefault_rt() {
+    int expect = 10;
+    assertEquals(expect,
+        (int) restTemplate.getForObject(urlPrefix + "/intQueryWithDefault?input=" + expect, int.class));
+    assertEquals(13, (int) restTemplate.getForObject(urlPrefix + "/intQueryWithDefault", int.class));
+  }
+
+  @Test
+  public void intHeaderWithDefault_rt() {
+    HttpHeaders headers = new HttpHeaders();
+    headers.add("input", "10");
+    @SuppressWarnings("rawtypes")
+    HttpEntity entity = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intHeaderWithDefault",
+        HttpMethod.GET,
+        entity,
+        int.class);
+    assertEquals(10, (int) response.getBody());
+    headers.remove("input");
+    @SuppressWarnings("rawtypes")
+    HttpEntity<Object> entity1 = new HttpEntity<>(null, headers);
+    ResponseEntity<Integer> response1 = restTemplate.exchange(urlPrefix + "/intHeaderWithDefault",
+        HttpMethod.GET,
+        entity1,
+        int.class);
+    assertEquals(13, (int) response1.getBody());
+  }
+//暂时不支持 cookie 设置默认值,不过以后会支持,先放这里
+//  @Test
+//  public void intCookieWithDefault_rt() {
+//    HttpHeaders headers = new HttpHeaders();
+////    headers.add("Cookie", "input=10");
+////    @SuppressWarnings("rawtypes")
+////    HttpEntity entity = new HttpEntity<>( headers);
+////    ResponseEntity<Integer> response = restTemplate.exchange(urlPrefix + "/intCookieWithDefault",
+////        HttpMethod.GET,
+////        entity,
+////        int.class);
+////    assertEquals(10, (int) response.getBody());
+////    headers.remove("Cookie");
+//    headers.add("Cookie", "input=10");
+//
+//    @SuppressWarnings("rawtypes")
+//    HttpEntity entity1 = new HttpEntity<>( headers);
+//    ResponseEntity<Integer> response1 = restTemplate.exchange(urlPrefix + "/intCookieWithDefault",
+//        HttpMethod.GET,
+//        entity1,
+//        Integer.class);
+//    assertEquals(10, (int) response1.getBody());
+//  }
+
+  @Test
+  public void intAttributeWithDefault_rt() {
+    Map<String, Integer> map = new HashMap<>();
+    map.put("a", 10);
+    int result = restTemplate.postForObject(urlPrefix + "/intAttributeWithDefault", map, Integer.class);
+    assertEquals(10, result);
+
+    map.remove("a");
+    int result1 = restTemplate.postForObject(urlPrefix + "/intAttributeWithDefault", map, Integer.class);
+    assertEquals(13, result1);
+  }
+
+  @Test
+  public void intAdd_intf() {
+    int i = dataTypeIntf.intAdd(2, 3);
+    assertEquals(5, i);
+  }
+
+  @Test
+  public void intAdd_rt() {
+    Map<String, Integer> map = new HashMap<>();
+    map.put("a", 10);
+    map.put("b", 10);
+    int result = restTemplate.postForObject(urlPrefix + "/add", map, Integer.class);
+    assertEquals(20, result);
+  }
+
+  @Test
+  public void intMulti_intf() {
+    int a = 1, b = 1, c = 1, d = 1, e = 1;
+    assertEquals(String.format("a=%s,b=%s,c=%s,d=%s,e=%s", a, b, c, d, e), dataTypeIntf.intMulti(a, b, c, d, e));
+  }
+
+  @Test
+  public void intMulti_rt() {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "1");
+    params.put("e", "1");
+    params.put("c", "1");
+    HttpHeaders headers = new HttpHeaders();
+    headers.add(HttpHeaders.COOKIE, "b=1");
+    headers.add("d", "1");
+    HttpEntity<?> requestEntity = new HttpEntity<>(headers);
+    ResponseEntity<String> result = restTemplate.exchange(
+        urlPrefix + "/intMulti/{e}?a={a}&c={c}",
+        HttpMethod.POST,
+        requestEntity,
+        String.class,
+        params);
+    assertEquals(String.format("a=%s,b=%s,c=%s,d=%s,e=%s", 1, 1, 1, 1, 1), result.getBody());
+  }
+
+  @Test
+  public void intRequestQuery_rt() {
+    int expect = 10;
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "10");
+    assertEquals(expect, (int) restTemplate.postForObject(urlPrefix + "/queryRequest?a=" + expect, null, int.class));
+    assertEquals(expect, (int) restTemplate.postForObject(urlPrefix + "/queryRequest?a={a}", null, int.class, params));
+  }
+
+  @Test
+  public void intRequestForm_rt() {
+    HttpHeaders formHeaders = new HttpHeaders();
+    formHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+    Map<String, Integer> map = new HashMap<>();
+
+    map.put("form1", 10);
+    map.put("form2", 10);
+    HttpEntity<Map<String, Integer>> formEntiry = new HttpEntity<>(map, formHeaders);
+
+    assertEquals(String.format("form1=%s,form2=%s", 10, 10),
+        restTemplate.postForEntity(urlPrefix + "/formRequest", formEntiry, String.class).getBody());
+    //other method
+    assertEquals(String.format("form1=%s,form2=%s", 10, 10),
+        restTemplate.postForEntity(urlPrefix + "/formRequest", map, String.class).getBody());
+  }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypePojoIntf.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypePojoIntf.java
index 714627957..eace6981c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypePojoIntf.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypePojoIntf.java
@@ -19,4 +19,6 @@
   String checkTransport();
 
   int intBody(int input);
+
+  int reduce(int a, int b);
 }
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypeRestIntf.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypeRestIntf.java
index 3a794b976..a1dcd3a9c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypeRestIntf.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/support/DataTypeRestIntf.java
@@ -27,4 +27,30 @@
   int intCookie(int input);
 
   int intBody(int input);
+
+  int intForm(int a);
+
+  int intAttribute(int a);
+
+  int intAdd(int a, int b);
+
+  int intPostAdd(int a, int b);
+
+  int defaultPath();
+
+  int intPathWithMinMax(int input);
+
+  int intQueryWithMinMax(int input);
+
+  int intHeaderWithMinMax(int input);
+
+  int intCookieWithMinMax(int input);
+
+  int intFormWithMinMax(int input);
+
+  int intAttributeWithMinMax(int input);
+
+  int intBodyWithMinMax(int input);
+
+  String intMulti(int a, int b, int c, int d, int e);
 }
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrs.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrs.java
index b9b7b134d..f65e09da9 100644
--- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrs.java
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeJaxrs.java
@@ -19,11 +19,15 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.CookieParam;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
 import javax.ws.rs.GET;
 import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
 
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 
@@ -66,9 +70,56 @@ public int intCookie(@CookieParam("input") int input) {
     return pojo.intBody(input);
   }
 
+  @Path("intForm")
+  @POST
+  public int intForm(@FormParam("a") int a) {
+    return pojo.intBody(a);
+  }
+
+
   @Path("intBody")
-  @GET
+  @POST
   public int intBody(int input) {
     return pojo.intBody(input);
   }
+
+  @GET
+  public int defaultPath() {
+    return pojo.intBody(100);
+  }
+
+
+  @Path("intQueryWithDefault")
+  @GET
+  public int intQueryWithDefault(@QueryParam("input") @DefaultValue("13") int input) {
+    return pojo.intBody(input);
+  }
+
+  @Path("intHeaderWithDefault")
+  @GET
+  public int intHeaderWithDefault(@HeaderParam(value = "input") @DefaultValue("13") int input) {
+    return pojo.intBody(input);
+  }
+
+  //暂时不支持 cookie设置默认值,但是不影响先放这里
+  @Path("intCookieWithDefault")
+  @GET
+  public int intCookieWithDefault(@CookieParam(value = "input") @DefaultValue("13") int input) {
+    return pojo.intBody(input);
+  }
+
+  @Path("intFormWithDefault")
+  @POST
+  public int intFormWithDefault(@FormParam("a") @DefaultValue("13") int a) {
+    return pojo.intBody(a);
+  }
+
+  //这个是伪契约,不支持 highway
+  @Path("request")
+  @GET
+  public int request(@Context HttpServletRequest request) {
+    int a = Integer.parseInt(request.getParameter("a"));
+    int b = Integer.parseInt(request.getParameter("b"));
+    return a - b;
+  }
 }
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java
index 47d91e08d..17ecfadfe 100644
--- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypePojo.java
@@ -38,4 +38,8 @@ public String checkTransport(HttpServletRequest request) {
   public int intBody(int input) {
     return input;
   }
+
+  public int reduce(int a, int b) {
+    return a - b;
+  }
 }
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeSpringmvc.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeSpringmvc.java
index 19104b7bf..98f26452e 100644
--- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeSpringmvc.java
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DataTypeSpringmvc.java
@@ -17,16 +17,24 @@
 package org.apache.servicecomb.it.schema;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DefaultValue;
 
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.springframework.web.bind.annotation.CookieValue;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+
 @RestSchema(schemaId = "dataTypeSpringmvc")
 @RequestMapping(path = "/v1/dataTypeSpringmvc")
 public class DataTypeSpringmvc {
@@ -57,8 +65,86 @@ public int intCookie(@CookieValue("input") int input) {
     return pojo.intBody(input);
   }
 
-  @GetMapping("intBody")
+  @PostMapping("intBody")
   public int intBody(@RequestBody int input) {
     return pojo.intBody(input);
   }
+
+  @PostMapping(path = "intForm")
+  @ApiImplicitParams({
+      @ApiImplicitParam(name = "form1", dataType = "integer", format = "int32", paramType = "form", value = "a required form param",
+          required = true)})
+  public int intForm(int form1) {
+    return pojo.intBody(form1);
+  }
+
+  @RequestMapping(path = "intAttribute", method = RequestMethod.POST)
+  public int intAttribute(@RequestAttribute("a") int a) {
+    return pojo.intBody(a);
+  }
+
+  @GetMapping("intQueryWithDefault")
+  public int intQueryWithDefault(@RequestParam(value = "input", defaultValue = "13") int input) {
+    return pojo.intBody(input);
+  }
+
+  @GetMapping("intHeaderWithDefault")
+  public int intHeaderWithDefault(@RequestHeader(value = "input", defaultValue = "13") int input) {
+    return pojo.intBody(input);
+  }
+
+  //暂时不支持cookie默认值,不过以后会修复,先放这里,不影响
+  @GetMapping("intCookieWithDefault")
+  public int intCookieWithDefault(@CookieValue(value = "input", defaultValue = "13") int input) {
+    return pojo.intBody(input);
+  }
+
+  //这里算是 jaxrs 和 springmvc 的一个混用,按道理是不能这么使用的,不过这样确实跑通了
+  //也算是增加了功能,就不删了
+  @RequestMapping(path = "intAttributeWithDefault", method = RequestMethod.POST)
+  public int intAttributeWithDefault(@RequestAttribute("a") @DefaultValue("13") int a) {
+    return pojo.intBody(a);
+  }
+
+  // this should be ignored as it's hidden
+  //服务端是不允许重载的,但是因为 这里设置 hidden = true,所以上面的可以正常运行
+  @ApiOperation(value = "", hidden = true, httpMethod = "POST")
+  public int intAdd(@RequestParam("a") int a) {
+    return pojo.intBody(a);
+  }
+
+  @RequestMapping(path = "add", method = RequestMethod.POST)
+  public int intAdd(@RequestAttribute("a") int a, @RequestAttribute("b") int b) {
+    return a + b;
+  }
+
+  @PostMapping(path = "intMulti/{e}")
+  @ApiImplicitParams({
+      @ApiImplicitParam(name = "a", dataType = "integer", format = "int32", paramType = "query"),
+      @ApiImplicitParam(name = "c", dataType = "integer", format = "int32", paramType = "query"),
+      @ApiImplicitParam(name = "d", dataType = "integer", format = "int32", paramType = "header"),
+      @ApiImplicitParam(name = "e", dataType = "integer", format = "int32", paramType = "path"),
+  })
+  public String intMulti(int a, @CookieValue(name = "b") int b, int c, int d, int e) {
+    return String.format("a=%s,b=%s,c=%s,d=%s,e=%s", a, b, c, d, e);
+  }
+
+  @PostMapping(path = "queryRequest")
+  @ApiImplicitParams({
+      @ApiImplicitParam(name = "a", dataType = "integer", format = "int32", paramType = "query"),
+  })
+  public int intRequestQuery(HttpServletRequest request) {
+    return Integer.parseInt(request.getParameter("a"));
+  }
+
+  @PostMapping(path = "formRequest")
+  @ApiImplicitParams({
+      @ApiImplicitParam(name = "form1", dataType = "integer", format = "int32", paramType = "form", value = "a required form param",
+          required = true),
+      @ApiImplicitParam(name = "form2", dataType = "integer", format = "int32", paramType = "form", value = "an optional form param")})
+  public String intRequestForm(HttpServletRequest request) {
+    int form1 = Integer.parseInt(request.getParameter("form1"));
+    int form2 = Integer.parseInt(request.getParameter("form2"));
+    return String.format("form1=%s,form2=%s", form1, form2);
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services