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 ca933c141d41615dc04d2d55b577277aa20b78dc
Author: acsukesh <sukes...@huawei.com>
AuthorDate: Tue Apr 10 20:46:16 2018 +0530

    [SCB-292] chassis support standard parameter validation
---
 .../servicecomb/demo/jaxrs/client/JaxrsClient.java | 40 ++++++++++++++++++----
 .../servicecomb/demo/jaxrs/server/Validator.java   |  2 +-
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git 
a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
 
b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
index 8781929..6b7a8af 100644
--- 
a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
+++ 
b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
@@ -28,7 +28,7 @@ import org.apache.servicecomb.demo.CodeFirstRestTemplate;
 import org.apache.servicecomb.demo.DemoConst;
 import org.apache.servicecomb.demo.TestMgr;
 import org.apache.servicecomb.demo.compute.Person;
-import org.apache.servicecomb.demo.compute.Student;
+import org.apache.servicecomb.demo.validator.Student;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
 import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
@@ -87,9 +87,12 @@ public class JaxrsClient {
 
       String cseUrlPrefix = "cse://" + microserviceName + "/validator/";
 
-      testValidatorAdd(template, cseUrlPrefix);
-      testValidatorSayHi(template, cseUrlPrefix);
-      testValidatorExchange(template, cseUrlPrefix);
+      testValidatorAddSuccess(template, cseUrlPrefix);
+      testValidatorAddFail(template, cseUrlPrefix);
+      testValidatorSayHiSuccess(template, cseUrlPrefix);
+      testValidatorSayHiFail(template, cseUrlPrefix);
+      testValidatorExchangeSuccess(template, cseUrlPrefix);
+      testValidatorExchangeFail(template, cseUrlPrefix);
     }
   }
 
@@ -166,7 +169,7 @@ public class JaxrsClient {
         template.postForObject(cseUrlPrefix + "/compute/testrawjson", 
jsonPerson, String.class));
   }
 
-  private static void testValidatorAdd(RestTemplate template, String 
cseUrlPrefix) {
+  private static void testValidatorAddFail(RestTemplate template, String 
cseUrlPrefix) {
     Map<String, String> params = new HashMap<>();
     params.put("a", "5");
     params.put("b", "3");
@@ -181,7 +184,15 @@ public class JaxrsClient {
     TestMgr.check(true, isExcep);
   }
 
-  private static void testValidatorSayHi(RestTemplate template, String 
cseUrlPrefix) {
+  private static void testValidatorAddSuccess(RestTemplate template, String 
cseUrlPrefix) {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "20");
+    int result = template.postForObject(cseUrlPrefix + "add", params, 
Integer.class);
+    TestMgr.check(25, result);
+  }
+
+  private static void testValidatorSayHiFail(RestTemplate template, String 
cseUrlPrefix) {
     boolean isExcep = false;
     try {
       template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, 
String.class, "te");
@@ -192,7 +203,14 @@ public class JaxrsClient {
     TestMgr.check(true, isExcep);
   }
 
-  private static void testValidatorExchange(RestTemplate template, String 
cseUrlPrefix) {
+  private static void testValidatorSayHiSuccess(RestTemplate template, String 
cseUrlPrefix) {
+    ResponseEntity<String> responseEntity =
+        template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, 
String.class, "world");
+    TestMgr.check(202, responseEntity.getStatusCode());
+    TestMgr.check("world sayhi", responseEntity.getBody());
+  }
+
+  private static void testValidatorExchangeFail(RestTemplate template, String 
cseUrlPrefix) {
     HttpHeaders headers = new HttpHeaders();
     headers.add("Accept", MediaType.APPLICATION_JSON);
     Student student = new Student();
@@ -211,4 +229,12 @@ public class JaxrsClient {
     }
     TestMgr.check(true, isExcep);
   }
+
+  private static void testValidatorExchangeSuccess(RestTemplate template, 
String cseUrlPrefix) {
+    Student student = new Student();
+    student.setName("test");
+    student.setAge(15);
+    Student result = template.postForObject(cseUrlPrefix + "sayhello", 
student, Student.class);
+    TestMgr.check("hello test 15", result);
+  }
 }
diff --git 
a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
 
b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
index a87e61f..986f6a3 100644
--- 
a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
+++ 
b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/Validator.java
@@ -27,7 +27,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
-import org.apache.servicecomb.demo.compute.Student;
+import org.apache.servicecomb.demo.validator.Student;
 import org.apache.servicecomb.provider.rest.common.RestSchema;
 import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
 import org.hibernate.validator.constraints.Length;

-- 
To stop receiving notification emails like this one, please contact
liu...@apache.org.

Reply via email to