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 2018/11/07 06:40:08 UTC

[incubator-servicecomb-java-chassis] branch master updated (6dc11dd -> 8465bdd)

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

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


    from 6dc11dd  [SCB-979] add reminder log on the selection of SwaggerGeneratorContext
     new 4b9b9c2  [SCB-1007] not support CustomGeneric<Map<String,String>>
     new 8465bdd  [SCB-1007] not support CustomGeneric<Map<String,String>> : resolve locale problem

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/servicecomb/it/schema}/Generic.java |   2 +-
 .../org/apache/servicecomb/it/schema}/User.java    |   3 +-
 .../org/apache/servicecomb/it/ConsumerMain.java    |   6 +
 .../servicecomb/it/testcase/TestGenericEdge.java   |  88 ++++++++
 .../servicecomb/it/testcase/base/TestGeneric.java  | 234 ++++++++++++++++++++-
 .../it-edge/src/main/resources/microservice.yaml   |  25 +++
 .../servicecomb/it/schema/GenericSchema.java       | 101 +++++++++
 .../swagger/generator/core/utils/ClassUtils.java   |   2 +-
 8 files changed, 456 insertions(+), 5 deletions(-)
 copy {demo/demo-schema/src/main/java/org/apache/servicecomb/demo => integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema}/Generic.java (95%)
 copy {demo/demo-schema/src/main/java/org/apache/servicecomb/demo/server => integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema}/User.java (97%)
 create mode 100644 integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestGenericEdge.java
 create mode 100644 integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java


[incubator-servicecomb-java-chassis] 01/02: [SCB-1007] not support CustomGeneric>

Posted by li...@apache.org.
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/incubator-servicecomb-java-chassis.git

commit 4b9b9c2d2ea2cf5068373047e5efec8048d43114
Author: heyile <he...@huawei.com>
AuthorDate: Mon Nov 5 21:43:10 2018 +0800

    [SCB-1007] not support CustomGeneric<Map<String,String>>
---
 .../org/apache/servicecomb/it/schema/Generic.java} |  11 +-
 .../org/apache/servicecomb/it/schema/User.java     |  76 +++++++
 .../org/apache/servicecomb/it/ConsumerMain.java    |   5 +-
 .../servicecomb/it/testcase/TestGenericEdge.java   |  88 ++++++++
 .../servicecomb/it/testcase/base/TestGeneric.java  | 230 ++++++++++++++++++++-
 .../it-edge/src/main/resources/microservice.yaml   |  25 +++
 .../servicecomb/it/schema/GenericSchema.java       | 101 +++++++++
 .../swagger/generator/core/utils/ClassUtils.java   |   2 +-
 8 files changed, 527 insertions(+), 11 deletions(-)

diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/Generic.java
similarity index 85%
copy from integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
copy to integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/Generic.java
index 4c85af1..085b2d1 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
+++ b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/Generic.java
@@ -14,13 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicecomb.it.testcase.base;
+package org.apache.servicecomb.it.schema;
 
-import org.junit.Test;
-
-public class TestGeneric {
-  @Test
-  public void test() {
-
-  }
+public class Generic<T> {
+  public T value;
 }
diff --git a/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/User.java b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/User.java
new file mode 100644
index 0000000..3f87a94
--- /dev/null
+++ b/integration-tests/it-common/src/main/java/org/apache/servicecomb/it/schema/User.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.it.schema;
+
+import org.apache.servicecomb.foundation.common.utils.JsonUtils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class User {
+  private String name = "nameA";
+
+  private int age = 100;
+
+  private int index;
+
+  private String[] names;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String[] getNames() {
+    return names;
+  }
+
+  public void setNames(String[] names) {
+    this.names = names;
+  }
+
+  public int getAge() {
+    return age;
+  }
+
+  public void setAge(int age) {
+    this.age = age;
+  }
+
+  public int getIndex() {
+    return index;
+  }
+
+  public void setIndex(int index) {
+    this.index = index;
+  }
+
+  @Override
+  public String toString() {
+    return "User [name=" + name + ", age=" + age + ", index=" + index + "]";
+  }
+
+  public String jsonString() {
+    try {
+      return JsonUtils.writeValueAsString(this);
+    } catch (JsonProcessingException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+}
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 cbc00d7..8b0a9b5 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
@@ -30,6 +30,7 @@ import org.apache.servicecomb.it.testcase.TestDefaultJsonValueJaxrsSchema;
 import org.apache.servicecomb.it.testcase.TestDefaultValue;
 import org.apache.servicecomb.it.testcase.TestDownload;
 import org.apache.servicecomb.it.testcase.TestDownloadSlowStreamEdge;
+import org.apache.servicecomb.it.testcase.TestGenericEdge;
 import org.apache.servicecomb.it.testcase.TestIgnoreMethod;
 import org.apache.servicecomb.it.testcase.TestIgnoreStaticMethod;
 import org.apache.servicecomb.it.testcase.TestParamCodec;
@@ -40,6 +41,7 @@ import org.apache.servicecomb.it.testcase.TestRestServerConfig;
 import org.apache.servicecomb.it.testcase.TestRestServerConfigEdge;
 import org.apache.servicecomb.it.testcase.TestTrace;
 import org.apache.servicecomb.it.testcase.TestTraceEdge;
+import org.apache.servicecomb.it.testcase.base.TestGeneric;
 import org.apache.servicecomb.it.testcase.thirdparty.Test3rdPartyInvocation;
 
 public class ConsumerMain {
@@ -97,7 +99,8 @@ public class ConsumerMain {
     ITJUnitUtils.runWithHighwayAndRest(TestChangeTransport.class);
     ITJUnitUtils.runWithHighwayAndRest(TestDataTypePrimitive.class);
     ITJUnitUtils.runWithHighwayAndRest(TestAnnotatedAttribute.class);
-
+    ITJUnitUtils.runWithRest(TestGeneric.class);
+    ITJUnitUtils.run(TestGenericEdge.class);
     // only rest support default value feature
     ITJUnitUtils.runWithRest(TestDefaultValue.class);
 
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestGenericEdge.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestGenericEdge.java
new file mode 100644
index 0000000..f20380b
--- /dev/null
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestGenericEdge.java
@@ -0,0 +1,88 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
+import org.apache.servicecomb.it.schema.Generic;
+import org.apache.servicecomb.it.schema.User;
+import org.junit.Test;
+
+public class TestGenericEdge {
+  private static GateRestTemplate client = GateRestTemplate.createEdgeRestTemplate("generic");
+
+  @Test
+  public void testGenericMap() {
+    Generic<Map<String, String>> mapGeneric = new Generic<>();
+    Map<String, String> map = new HashMap<>();
+    map.put("test", "hello");
+    mapGeneric.value = map;
+    @SuppressWarnings("unchecked")
+    Generic<Map<String, String>> result = client.postForObject("/genericMap", mapGeneric, Generic.class);
+    String test = result.value.get("test");
+    assertEquals(test, "hello");
+  }
+
+  @Test
+  public void testGenericMapList() {
+    Generic<Map<String, List<String>>> mapListGeneric = new Generic<>();
+    Map<String, List<String>> map = new HashMap<>();
+    List<String> list = new ArrayList<>();
+    list.add("hello");
+    map.put("test", list);
+    mapListGeneric.value = map;
+    @SuppressWarnings("unchecked")
+    Generic<Map<String, List<String>>> result = client.postForObject("/genericMapList", mapListGeneric, Generic.class);
+    String test = result.value.get("test").get(0);
+    assertEquals("hello", test);
+  }
+
+  @Test
+  public void testGenericUser() {
+    Generic<User> generic = new Generic<>();
+    generic.value = new User();
+    @SuppressWarnings("unchecked")
+    Generic<Map<String, Object>> result = client.postForObject("/genericUser", generic, Generic.class);
+    Map<String, Object> resultUser = result.value;
+    assertEquals("nameA", resultUser.get("name"));
+    assertEquals(100, resultUser.get("age"));
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testGenericMapListUser() {
+    Generic<Map<String, List<User>>> mapListUserGeneric = new Generic<>();
+    Map<String, List<User>> map = new HashMap<>();
+    List<User> list = new ArrayList<>();
+    list.add(new User());
+    map.put("test", list);
+    mapListUserGeneric.value = map;
+
+    Generic<Map<String, List<Map<String, Object>>>> result = client
+        .postForObject("/genericMapListUser", mapListUserGeneric, Generic.class);
+    Map<String, Object> resultUser = result.value.get("test").get(0);
+
+    assertEquals("nameA", resultUser.get("name"));
+    assertEquals(100, resultUser.get("age"));
+  }
+}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
index 4c85af1..bf20ccc 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
@@ -16,11 +16,239 @@
  */
 package org.apache.servicecomb.it.testcase.base;
 
+import static org.junit.Assert.assertEquals;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.ws.Holder;
+
+import org.apache.servicecomb.it.Consumers;
+import org.apache.servicecomb.it.schema.Generic;
+import org.apache.servicecomb.it.schema.User;
 import org.junit.Test;
+import org.springframework.http.HttpStatus;
 
 public class TestGeneric {
+  interface GenericIntf {
+    Holder<User> holderUser(Holder<User> input);
+
+    Generic<User> genericUser(Generic<User> input);
+
+    Generic<Long> genericLong(Generic<Long> input);
+
+    Generic<Date> genericDate(Generic<Date> input);
+
+    Generic<HttpStatus> genericEnum(Generic<HttpStatus> input);
+
+    Generic<Generic<User>> genericGenericUser(Generic<Generic<User>> input);
+
+    Generic<Map<String, String>> genericMap(Generic<Map<String, String>> mapGeneric);
+
+    Generic<Map<String, List<String>>> genericMapList(Generic<Map<String, List<String>>> mapListGeneric);
+
+    Generic<Map<String, List<User>>> genericMapListUser(Generic<Map<String, List<User>>> mapListUserGeneric);
+  }
+
+  private static Consumers<GenericIntf> consumers = new Consumers<>("generic", GenericIntf.class);
+
+  private String expectUserStr = "{\"name\":\"nameA\",\"age\":100,\"index\":0,\"names\":null}";
+
+  private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+
   @Test
-  public void test() {
+  public void testHolderUser_intf() {
+    Holder<User> holder = new Holder<>(new User());
+    Holder<User> result = consumers.getIntf().holderUser(holder);
+    assertEquals(result.value.jsonString(), expectUserStr);
+  }
 
+  @Test
+  public void testHolderUser_rt() {
+    Holder<User> holder = new Holder<>(new User());
+    @SuppressWarnings("unchecked")
+    Holder<User> result = consumers.getSCBRestTemplate().postForObject("/holderUser", holder, Holder.class);
+    assertEquals(result.value.jsonString(), expectUserStr);
+  }
+
+  @Test
+  public void testGenericUser_intf() {
+    Generic<User> generic = new Generic<>();
+    generic.value = new User();
+
+    Generic<User> result = consumers.getIntf().genericUser(generic);
+    assertEquals(result.value.jsonString(), expectUserStr);
+  }
+
+  @Test
+  public void testGenericUser_rt() {
+    Generic<User> generic = new Generic<>();
+    generic.value = new User();
+    @SuppressWarnings("unchecked")
+    Generic<User> result = consumers.getSCBRestTemplate().postForObject("/genericUser", generic, Generic.class);
+    assertEquals(result.value.jsonString(), expectUserStr);
+  }
+
+  @Test
+  public void testGenericLong_intf() {
+    Generic<Long> generic = new Generic<>();
+    generic.value = 100L;
+    Generic<Long> result = consumers.getIntf().genericLong(generic);
+    assertEquals(Long.class, result.value.getClass());
+    assertEquals(100L, (long) result.value);
+  }
+
+  @Test
+  public void testGenericLong_rt() {
+    Generic<Long> generic = new Generic<>();
+    generic.value = 100L;
+    @SuppressWarnings("unchecked")
+    Generic<Long> result = consumers.getSCBRestTemplate().postForObject("/genericLong", generic, Generic.class);
+    assertEquals(Long.class, result.value.getClass());
+    assertEquals(100L, (long) result.value);
+  }
+
+  @Test
+  public void testGenericDate_intf() {
+    Generic<Date> generic = new Generic<>();
+    generic.value = new Date(1001);
+    Generic<Date> result = consumers.getIntf().genericDate(generic);
+    assertEquals(result.value.getClass(), Date.class);
+    assertEquals("1970-01-01T08:00:01.001Z", simpleDateFormat.format(result.value));
+  }
+
+  @Test
+  public void testGenericDate_rt() {
+    Generic<Date> generic = new Generic<>();
+    generic.value = new Date(1001);
+    @SuppressWarnings("unchecked")
+    Generic<Date> result = consumers.getSCBRestTemplate().postForObject("/genericDate", generic, Generic.class);
+    assertEquals(result.value.getClass(), Date.class);
+    assertEquals("1970-01-01T08:00:01.001Z", simpleDateFormat.format(result.value));
+  }
+
+  @Test
+  public void testGenericEnum_intf() {
+    Generic<HttpStatus> generic = new Generic<>();
+    generic.value = HttpStatus.OK;
+
+    Generic<HttpStatus> result = consumers.getIntf().genericEnum(generic);
+    assertEquals(HttpStatus.class, result.value.getClass());
+    assertEquals(HttpStatus.OK, result.value);
+  }
+
+  @Test
+  public void testGenericEnum_rt() {
+    Generic<HttpStatus> generic = new Generic<>();
+    generic.value = HttpStatus.OK;
+    @SuppressWarnings("unchecked")
+    Generic<HttpStatus> result = consumers.getSCBRestTemplate().postForObject("/genericEnum", generic, Generic.class);
+    assertEquals(HttpStatus.class, result.value.getClass());
+    assertEquals(HttpStatus.OK, result.value);
+  }
+
+  @Test
+  public void testGenericGenericUser_intf() {
+    Generic<Generic<User>> generic = new Generic<>();
+    generic.value = new Generic<>();
+    generic.value.value = new User();
+
+    Generic<Generic<User>> result = consumers.getIntf().genericGenericUser(generic);
+    assertEquals(result.value.value.jsonString(), expectUserStr);
+  }
+
+  @Test
+  public void testGenericGenericUser_rt() {
+    Generic<Generic<User>> generic = new Generic<>();
+    generic.value = new Generic<>();
+    generic.value.value = new User();
+    @SuppressWarnings("unchecked")
+    Generic<Generic<User>> result = consumers.getSCBRestTemplate()
+        .postForObject("/genericGenericUser", generic, Generic.class);
+    assertEquals(result.value.value.jsonString(), expectUserStr);
+  }
+
+  @Test
+  public void testGenericMap_intf() {
+    Generic<Map<String, String>> mapGeneric = new Generic<>();
+    Map<String, String> map = new HashMap<>();
+    map.put("test", "hello");
+    mapGeneric.value = map;
+    Generic<Map<String, String>> result = consumers.getIntf().genericMap(mapGeneric);
+    String test = result.value.get("test");
+    assertEquals(test, "hello");
+  }
+
+  @Test
+  public void testGenericMap_rt() {
+    Generic<Map<String, String>> mapGeneric = new Generic<>();
+    Map<String, String> map = new HashMap<>();
+    map.put("test", "hello");
+    mapGeneric.value = map;
+    @SuppressWarnings("unchecked")
+    Generic<Map<String, String>> result = consumers.getSCBRestTemplate()
+        .postForObject("/genericMap", mapGeneric, Generic.class);
+    String test = result.value.get("test");
+    assertEquals(test, "hello");
+  }
+
+  @Test
+  public void testGenericListMap_intf() {
+    Generic<Map<String, List<String>>> mapListGeneric = new Generic<>();
+    Map<String, List<String>> map = new HashMap<>();
+    List<String> list = new ArrayList<>();
+    list.add("hello");
+    map.put("test", list);
+    mapListGeneric.value = map;
+    Generic<Map<String, List<String>>> result = consumers.getIntf().genericMapList(mapListGeneric);
+    String test = result.value.get("test").get(0);
+    assertEquals(test, "hello");
+  }
+
+  @Test
+  public void testGenericListMap_rt() {
+    Generic<Map<String, List<String>>> mapListGeneric = new Generic<>();
+    Map<String, List<String>> map = new HashMap<>();
+    List<String> list = new ArrayList<>();
+    list.add("hello");
+    map.put("test", list);
+    mapListGeneric.value = map;
+    @SuppressWarnings("unchecked")
+    Generic<Map<String, List<String>>> result = consumers.getSCBRestTemplate()
+        .postForObject("/genericMapList", mapListGeneric, Generic.class);
+    String test = result.value.get("test").get(0);
+    assertEquals(test, "hello");
+  }
+
+  @Test
+  public void testGenericListUserMap_intf() {
+    Generic<Map<String, List<User>>> mapListUserGeneric = new Generic<>();
+    Map<String, List<User>> map = new HashMap<>();
+    List<User> list = new ArrayList<>();
+    list.add(new User());
+    map.put("test", list);
+    mapListUserGeneric.value = map;
+    Generic<Map<String, List<User>>> result = consumers.getIntf().genericMapListUser(mapListUserGeneric);
+    String test = result.value.get("test").get(0).jsonString();
+    assertEquals(test, expectUserStr);
+  }
+
+  @Test
+  public void testGenericListUserMap_rt() {
+    Generic<Map<String, List<User>>> mapListUserGeneric = new Generic<>();
+    Map<String, List<User>> map = new HashMap<>();
+    List<User> list = new ArrayList<>();
+    list.add(new User());
+    map.put("test", list);
+    mapListUserGeneric.value = map;
+    @SuppressWarnings("unchecked")
+    Generic<Map<String, List<User>>> result = consumers.getSCBRestTemplate()
+        .postForObject("/genericMapListUser", mapListUserGeneric, Generic.class);
+    String test = result.value.get("test").get(0).jsonString();
+    assertEquals(test, expectUserStr);
   }
 }
diff --git a/integration-tests/it-edge/src/main/resources/microservice.yaml b/integration-tests/it-edge/src/main/resources/microservice.yaml
index 888f1dd..59b5580 100644
--- a/integration-tests/it-edge/src/main/resources/microservice.yaml
+++ b/integration-tests/it-edge/src/main/resources/microservice.yaml
@@ -34,6 +34,11 @@ servicecomb:
   #        emptyAsNull: true
   operation:
     it-producer:
+      generic:
+        genericUser:
+          transport: rest
+        genericMapListUser:
+          transport: rest
       download:
         slowInputStream:
           transport: rest
@@ -43,6 +48,11 @@ servicecomb:
         queryInput:
           transport: rest
     it-producer-h2:
+      generic:
+        genericUser:
+          transport: rest
+        genericMapListUser:
+          transport: rest
       download:
         slowInputStream:
           transport: rest
@@ -52,6 +62,11 @@ servicecomb:
         queryInput:
           transport: rest
     it-producer-h2c:
+      generic:
+        genericUser:
+          transport: rest
+        genericMapListUser:
+          transport: rest
       download:
         slowInputStream:
           transport: rest
@@ -61,6 +76,11 @@ servicecomb:
         queryInput:
           transport: rest
     it-producer-deploy-springboot2-servlet:
+      generic:
+        genericUser:
+          transport: rest
+        genericMapListUser:
+          transport: rest
       download:
         slowInputStream:
           transport: rest
@@ -70,6 +90,11 @@ servicecomb:
         queryInput:
           transport: rest
     it-producer-deploy-springboot2-standalone:
+      generic:
+        genericUser:
+          transport: rest
+        genericMapListUser:
+          transport: rest
       download:
         slowInputStream:
           transport: rest
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java
new file mode 100644
index 0000000..42f9ce0
--- /dev/null
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java
@@ -0,0 +1,101 @@
+/*
+ * 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.schema;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.ws.Holder;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.http.HttpStatus;
+import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RestSchema(schemaId = "generic")
+@RequestMapping(path = "/v1/generic")
+public class GenericSchema {
+
+  @PostMapping(path = "/holderUser")
+  public Holder<User> holderUser(@RequestBody Holder<User> input) {
+    Assert.isInstanceOf(Holder.class, input);
+    Assert.isInstanceOf(User.class, input.value);
+    return input;
+  }
+
+  @PostMapping(path = "/genericUser")
+  public Generic<User> genericUser(@RequestBody Generic<User> input) {
+    Assert.isInstanceOf(Generic.class, input);
+    Assert.isInstanceOf(User.class, input.value);
+    return input;
+  }
+
+  @PostMapping(path = "/genericLong")
+  public Generic<Long> genericLong(@RequestBody Generic<Long> input) {
+    Assert.isInstanceOf(Generic.class, input);
+    Assert.isInstanceOf(Long.class, input.value);
+    return input;
+  }
+
+  @PostMapping(path = "/genericDate")
+  public Generic<Date> genericDate(@RequestBody Generic<Date> input) {
+    Assert.isInstanceOf(Generic.class, input);
+    Assert.isInstanceOf(Date.class, input.value);
+    return input;
+  }
+
+  @PostMapping(path = "/genericEnum")
+  public Generic<HttpStatus> genericEnum(@RequestBody Generic<HttpStatus> input) {
+    Assert.isInstanceOf(Generic.class, input);
+    Assert.isInstanceOf(HttpStatus.class, input.value);
+    return input;
+  }
+
+  @PostMapping(path = "/genericGenericUser")
+  public Generic<Generic<User>> genericGenericUser(@RequestBody Generic<Generic<User>> input) {
+    Assert.isInstanceOf(Generic.class, input);
+    Assert.isInstanceOf(Generic.class, input.value);
+    Assert.isInstanceOf(User.class, input.value.value);
+    return input;
+  }
+
+  @PostMapping(path = "/genericMap")
+  public Generic<Map<String, String>> genericMap(@RequestBody Generic<Map<String, String>> mapGeneric) {
+    Assert.isInstanceOf(Generic.class, mapGeneric);
+    Assert.isInstanceOf(Map.class, mapGeneric.value);
+    return mapGeneric;
+  }
+
+  @PostMapping(path = "/genericMapList")
+  public Generic<Map<String, List<String>>> genericMapList(
+      @RequestBody Generic<Map<String, List<String>>> mapListGeneric) {
+    Assert.isInstanceOf(Generic.class, mapListGeneric);
+    Assert.isInstanceOf(Map.class, mapListGeneric.value);
+    return mapListGeneric;
+  }
+
+  @PostMapping(path = "/genericMapListUser")
+  public Generic<Map<String, List<User>>> genericMapListUser(
+      @RequestBody Generic<Map<String, List<User>>> mapListUserGeneric) {
+    Assert.isInstanceOf(Generic.class, mapListUserGeneric);
+    Assert.isInstanceOf(Map.class, mapListUserGeneric.value);
+    return mapListUserGeneric;
+  }
+}
diff --git a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/utils/ClassUtils.java b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/utils/ClassUtils.java
index ae7b7ad..1e43c7e 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/utils/ClassUtils.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/utils/ClassUtils.java
@@ -166,7 +166,7 @@ public final class ClassUtils {
         continue;
       }
 
-      part = part.replaceAll("[;<>-]", "_").replace("[", "array_");
+      part = part.replaceAll("[,;<>-]", "_").replace("[", "array_");
       if (Character.isDigit(part.charAt(0)) || SourceVersion.isKeyword(part)) {
         part = "_" + part;
       }


[incubator-servicecomb-java-chassis] 02/02: [SCB-1007] not support CustomGeneric> : resolve locale problem

Posted by li...@apache.org.
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/incubator-servicecomb-java-chassis.git

commit 8465bddbc9e05e758873bf36bcd48e52f90f7c6f
Author: heyile <he...@huawei.com>
AuthorDate: Mon Nov 5 22:23:52 2018 +0800

    [SCB-1007] not support CustomGeneric<Map<String,String>> : resolve locale problem
---
 .../java/org/apache/servicecomb/it/ConsumerMain.java   |  7 +++++--
 .../servicecomb/it/testcase/base/TestGeneric.java      | 10 +++++++---
 .../apache/servicecomb/it/schema/GenericSchema.java    | 18 +++++++++---------
 3 files changed, 21 insertions(+), 14 deletions(-)

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 8b0a9b5..2209583 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
@@ -99,8 +99,7 @@ public class ConsumerMain {
     ITJUnitUtils.runWithHighwayAndRest(TestChangeTransport.class);
     ITJUnitUtils.runWithHighwayAndRest(TestDataTypePrimitive.class);
     ITJUnitUtils.runWithHighwayAndRest(TestAnnotatedAttribute.class);
-    ITJUnitUtils.runWithRest(TestGeneric.class);
-    ITJUnitUtils.run(TestGenericEdge.class);
+
     // only rest support default value feature
     ITJUnitUtils.runWithRest(TestDefaultValue.class);
 
@@ -115,6 +114,10 @@ public class ConsumerMain {
     ITJUnitUtils.runWithHighwayAndRest(TestParamCodec.class);
     ITJUnitUtils.run(TestParamCodecEdge.class);
 
+    //generic
+    ITJUnitUtils.runWithRest(TestGeneric.class);
+    ITJUnitUtils.run(TestGenericEdge.class);
+
     ITJUnitUtils.run(TestRequestBodySpringMvcSchema.class);
     ITJUnitUtils.run(TestDefaultJsonValueJaxrsSchema.class);
     ITJUnitUtils.run(TestRestController.class);
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
index bf20ccc..276bd37 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestGeneric.java
@@ -23,7 +23,9 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 
 import javax.xml.ws.Holder;
 
@@ -58,7 +60,7 @@ public class TestGeneric {
 
   private String expectUserStr = "{\"name\":\"nameA\",\"age\":100,\"index\":0,\"names\":null}";
 
-  private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+  private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
 
   @Test
   public void testHolderUser_intf() {
@@ -118,7 +120,8 @@ public class TestGeneric {
     generic.value = new Date(1001);
     Generic<Date> result = consumers.getIntf().genericDate(generic);
     assertEquals(result.value.getClass(), Date.class);
-    assertEquals("1970-01-01T08:00:01.001Z", simpleDateFormat.format(result.value));
+    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+    assertEquals("1970-01-01T00:00:01.001Z", simpleDateFormat.format(result.value));
   }
 
   @Test
@@ -128,7 +131,8 @@ public class TestGeneric {
     @SuppressWarnings("unchecked")
     Generic<Date> result = consumers.getSCBRestTemplate().postForObject("/genericDate", generic, Generic.class);
     assertEquals(result.value.getClass(), Date.class);
-    assertEquals("1970-01-01T08:00:01.001Z", simpleDateFormat.format(result.value));
+    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+    assertEquals("1970-01-01T00:00:01.001Z", simpleDateFormat.format(result.value));
   }
 
   @Test
diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java
index 42f9ce0..03bf10f 100644
--- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java
+++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/GenericSchema.java
@@ -33,42 +33,42 @@ import org.springframework.web.bind.annotation.RequestMapping;
 @RequestMapping(path = "/v1/generic")
 public class GenericSchema {
 
-  @PostMapping(path = "/holderUser")
+  @PostMapping(path = "holderUser")
   public Holder<User> holderUser(@RequestBody Holder<User> input) {
     Assert.isInstanceOf(Holder.class, input);
     Assert.isInstanceOf(User.class, input.value);
     return input;
   }
 
-  @PostMapping(path = "/genericUser")
+  @PostMapping(path = "genericUser")
   public Generic<User> genericUser(@RequestBody Generic<User> input) {
     Assert.isInstanceOf(Generic.class, input);
     Assert.isInstanceOf(User.class, input.value);
     return input;
   }
 
-  @PostMapping(path = "/genericLong")
+  @PostMapping(path = "genericLong")
   public Generic<Long> genericLong(@RequestBody Generic<Long> input) {
     Assert.isInstanceOf(Generic.class, input);
     Assert.isInstanceOf(Long.class, input.value);
     return input;
   }
 
-  @PostMapping(path = "/genericDate")
+  @PostMapping(path = "genericDate")
   public Generic<Date> genericDate(@RequestBody Generic<Date> input) {
     Assert.isInstanceOf(Generic.class, input);
     Assert.isInstanceOf(Date.class, input.value);
     return input;
   }
 
-  @PostMapping(path = "/genericEnum")
+  @PostMapping(path = "genericEnum")
   public Generic<HttpStatus> genericEnum(@RequestBody Generic<HttpStatus> input) {
     Assert.isInstanceOf(Generic.class, input);
     Assert.isInstanceOf(HttpStatus.class, input.value);
     return input;
   }
 
-  @PostMapping(path = "/genericGenericUser")
+  @PostMapping(path = "genericGenericUser")
   public Generic<Generic<User>> genericGenericUser(@RequestBody Generic<Generic<User>> input) {
     Assert.isInstanceOf(Generic.class, input);
     Assert.isInstanceOf(Generic.class, input.value);
@@ -76,14 +76,14 @@ public class GenericSchema {
     return input;
   }
 
-  @PostMapping(path = "/genericMap")
+  @PostMapping(path = "genericMap")
   public Generic<Map<String, String>> genericMap(@RequestBody Generic<Map<String, String>> mapGeneric) {
     Assert.isInstanceOf(Generic.class, mapGeneric);
     Assert.isInstanceOf(Map.class, mapGeneric.value);
     return mapGeneric;
   }
 
-  @PostMapping(path = "/genericMapList")
+  @PostMapping(path = "genericMapList")
   public Generic<Map<String, List<String>>> genericMapList(
       @RequestBody Generic<Map<String, List<String>>> mapListGeneric) {
     Assert.isInstanceOf(Generic.class, mapListGeneric);
@@ -91,7 +91,7 @@ public class GenericSchema {
     return mapListGeneric;
   }
 
-  @PostMapping(path = "/genericMapListUser")
+  @PostMapping(path = "genericMapListUser")
   public Generic<Map<String, List<User>>> genericMapListUser(
       @RequestBody Generic<Map<String, List<User>>> mapListUserGeneric) {
     Assert.isInstanceOf(Generic.class, mapListUserGeneric);