use of org.apache.servicecomb.demo.multiErrorCode.MultiResponse500 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");
}
Aggregations