liubao68 commented on a change in pull request #627: [SCB-292] chassis support 
standard parameter validation
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/627#discussion_r180611794
 
 

 ##########
 File path: 
demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/JaxrsClient.java
 ##########
 @@ -147,4 +168,73 @@ private static void testRawJsonParam(RestTemplate 
template, String cseUrlPrefix)
     TestMgr.check("hello Tom",
         template.postForObject(cseUrlPrefix + "/compute/testrawjson", 
jsonPerson, String.class));
   }
+
+  private static void testValidatorAddFail(RestTemplate template, String 
cseUrlPrefix) {
+    Map<String, String> params = new HashMap<>();
+    params.put("a", "5");
+    params.put("b", "3");
+    boolean isExcep = false;
+    try {
+      template.postForObject(cseUrlPrefix + "add", params, Integer.class);
+    } catch (InvocationException e) {
+      isExcep = true;
+      TestMgr.check(490, e.getStatus().getStatusCode());
+    }
+
+    TestMgr.check(true, isExcep);
+  }
+
+  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");
+    } catch (InvocationException e) {
+      isExcep = true;
+      TestMgr.check(490, e.getStatus().getStatusCode());
+    }
+    TestMgr.check(true, isExcep);
+  }
+
+  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();
+    student.setName("");
+    student.setAge(25);
+    boolean isExcep = false;
+    try {
+      HttpEntity<Student> requestEntity = new HttpEntity<>(student, headers);
+      template.exchange(cseUrlPrefix + "/sayhello",
+          HttpMethod.POST,
+          requestEntity,
+          Student.class);
+    } catch (InvocationException e) {
+      isExcep = true;
+      TestMgr.check(490, e.getStatus().getStatusCode());
 
 Review comment:
   490 error code exposes that consumer logic got some bad encapsulation. Maybe 
we need to find out the cause or leave a comment here and submit an improvement 
issue to fix later.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to