Search in sources :

Example 6 with MultiResponse400

use of org.apache.servicecomb.demo.multiErrorCode.MultiResponse400 in project java-chassis by ServiceComb.

the class MultiErrorCodeServiceClient method testErrorCodeWithHeader.

private static void testErrorCodeWithHeader() {
    MultiRequest request = new MultiRequest();
    request.setCode(200);
    ResponseEntity<MultiResponse200> result = template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeader", request, MultiResponse200.class);
    TestMgr.check(result.getStatusCodeValue(), 200);
    TestMgr.check(result.getBody().getMessage(), "success result");
    TestMgr.check(result.getBody().getCode(), 200);
    TestMgr.check(result.getHeaders().getFirst("x-code"), 200);
    request.setCode(400);
    MultiResponse400 t400 = null;
    try {
        template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeader", request, MultiResponse400.class);
    } catch (InvocationException e) {
        t400 = (MultiResponse400) e.getErrorData();
        TestMgr.check(e.getStatus().getStatusCode(), Status.BAD_REQUEST.getStatusCode());
    }
    TestMgr.check(t400.getCode(), 400);
    TestMgr.check(t400.getMessage(), "bad request");
    request.setCode(500);
    MultiResponse500 t500 = null;
    try {
        template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeader", request, MultiResponse400.class);
    } catch (InvocationException e) {
        t500 = (MultiResponse500) e.getErrorData();
        TestMgr.check(e.getStatus().getStatusCode(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    TestMgr.check(t500.getCode(), 500);
    TestMgr.check(t500.getMessage(), "internal error");
}
Also used : MultiRequest(org.apache.servicecomb.demo.multiErrorCode.MultiRequest) MultiResponse200(org.apache.servicecomb.demo.multiErrorCode.MultiResponse200) MultiResponse400(org.apache.servicecomb.demo.multiErrorCode.MultiResponse400) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) MultiResponse500(org.apache.servicecomb.demo.multiErrorCode.MultiResponse500)

Aggregations

MultiResponse200 (org.apache.servicecomb.demo.multiErrorCode.MultiResponse200)6 MultiResponse400 (org.apache.servicecomb.demo.multiErrorCode.MultiResponse400)6 MultiResponse500 (org.apache.servicecomb.demo.multiErrorCode.MultiResponse500)6 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)6 ApiResponses (io.swagger.annotations.ApiResponses)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 MultiRequest (org.apache.servicecomb.demo.multiErrorCode.MultiRequest)3 ResponseHeaders (org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders)2 ApiResponse (io.swagger.annotations.ApiResponse)1 Response (org.apache.servicecomb.swagger.invocation.Response)1