use of org.apache.servicecomb.demo.multiErrorCode.MultiResponse200 in project java-chassis by ServiceComb.
the class MultiErrorCodeServiceClient method testErrorCodeWithHeaderJAXRS.
private static void testErrorCodeWithHeaderJAXRS() {
MultiRequest request = new MultiRequest();
request.setCode(200);
request.setMessage("success result");
ResponseEntity<MultiResponse200> result = template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeaderJAXRS", 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);
request.setMessage("bad request");
MultiResponse400 t400 = null;
try {
template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeaderJAXRS", 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);
request.setMessage("internal error");
MultiResponse500 t500 = null;
try {
template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeaderJAXRS", 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");
}
use of org.apache.servicecomb.demo.multiErrorCode.MultiResponse200 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");
}
use of org.apache.servicecomb.demo.multiErrorCode.MultiResponse200 in project java-chassis by ServiceComb.
the class MultiErrorCodeServiceClient method testErrorCodeWrongType.
private static void testErrorCodeWrongType() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String body = "{\"message\":\"hello\",\"code\":\"wrongType\"";
HttpEntity<String> entity = new HttpEntity<>(body, headers);
ResponseEntity<MultiResponse200> result;
try {
template.postForEntity(serverDirectURL + "/MultiErrorCodeService/errorCode", entity, MultiResponse200.class);
} catch (HttpClientErrorException e) {
TestMgr.check(e.getRawStatusCode(), 400);
TestMgr.check(e.getMessage(), "400 Bad Request: \"{\"message\":\"Parameter is not valid for operation [jaxrs.MultiErrorCodeService.errorCode]." + " Parameter is [request]. Processor is [body].\"}\"");
}
entity = new HttpEntity<>(null, headers);
try {
result = template.postForEntity(serverDirectURL + "/MultiErrorCodeService/errorCode", entity, MultiResponse200.class);
TestMgr.check(590, 200);
} catch (HttpServerErrorException e) {
TestMgr.check(e.getRawStatusCode(), 500);
}
// not recommend
body = "{\"message\":\"hello\",\"code\":\"200\"}";
entity = new HttpEntity<>(body, headers);
result = template.postForEntity(serverDirectURL + "/MultiErrorCodeService/errorCode", entity, MultiResponse200.class);
TestMgr.check(result.getStatusCodeValue(), 200);
TestMgr.check(result.getBody().getMessage(), "success result");
}
Aggregations