From dev-return-3648-archive-asf-public=cust-asf.ponee.io@servicecomb.apache.org Fri Apr 13 07:06:41 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id BB51A180627 for ; Fri, 13 Apr 2018 07:06:40 +0200 (CEST) Received: (qmail 38893 invoked by uid 500); 13 Apr 2018 05:06:39 -0000 Mailing-List: contact dev-help@servicecomb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@servicecomb.apache.org Delivered-To: mailing list dev@servicecomb.apache.org Received: (qmail 38882 invoked by uid 99); 13 Apr 2018 05:06:39 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Apr 2018 05:06:39 +0000 From: GitBox To: dev@servicecomb.apache.org Subject: [GitHub] acsukesh commented on a change in pull request #627: [SCB-292] chassis support standard parameter validation Message-ID: <152359599921.29515.15378136771288731635.gitbox@gitbox.apache.org> Date: Fri, 13 Apr 2018 05:06:39 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit acsukesh 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_r181286536 ########## 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 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 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 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 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: Fixed ---------------------------------------------------------------- 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