use of org.apache.servicecomb.demo.multiErrorCode.MultiRequest in project java-chassis by ServiceComb.
the class MultiErrorCodeServiceClient method testErrorCode.
private static void testErrorCode() {
MultiRequest request = new MultiRequest();
request.setCode(200);
ResponseEntity<MultiResponse200> result = template.postForEntity(SERVER + "/MultiErrorCodeService/errorCode", request, MultiResponse200.class);
TestMgr.check(result.getStatusCodeValue(), 200);
TestMgr.check(result.getBody().getMessage(), "success result");
request.setCode(400);
MultiResponse400 t400 = null;
try {
template.postForEntity(SERVER + "/MultiErrorCodeService/errorCode", request, MultiResponse400.class);
} catch (InvocationException e) {
t400 = (MultiResponse400) e.getErrorData();
}
TestMgr.check(t400.getCode(), 400);
TestMgr.check(t400.getMessage(), "bad request");
request.setCode(500);
MultiResponse500 t500 = null;
try {
template.postForEntity(SERVER + "/MultiErrorCodeService/errorCode", request, MultiResponse400.class);
} catch (InvocationException e) {
t500 = (MultiResponse500) e.getErrorData();
}
TestMgr.check(t500.getCode(), 500);
TestMgr.check(t500.getMessage(), "internal error");
}
use of org.apache.servicecomb.demo.multiErrorCode.MultiRequest in project java-chassis by ServiceComb.
the class MultiErrorCodeServiceClient method testErrorCodeWithHeaderJAXRSUsingRowType.
private static void testErrorCodeWithHeaderJAXRSUsingRowType() {
JsonObject requestJson = new JsonObject();
requestJson.put("code", 200);
requestJson.put("message", "test message");
ResponseEntity<MultiResponse200> result = template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeaderJAXRS", requestJson, MultiResponse200.class);
TestMgr.check(result.getStatusCodeValue(), 200);
TestMgr.check(result.getBody().getMessage(), "test message");
TestMgr.check(result.getBody().getCode(), 200);
TestMgr.check(result.getHeaders().getFirst("x-code"), 200);
MultiRequest request = new MultiRequest();
request.setCode(200);
request.setMessage("test message");
String stringRequest = Json.encode(request);
// wrap request to JsonObject
result = template.postForEntity(SERVER + "/MultiErrorCodeService/errorCodeWithHeaderJAXRS", new JsonObject(stringRequest), MultiResponse200.class);
TestMgr.check(result.getStatusCodeValue(), 200);
TestMgr.check(result.getBody().getMessage(), "test message");
TestMgr.check(result.getBody().getCode(), 200);
TestMgr.check(result.getHeaders().getFirst("x-code"), 200);
}
use of org.apache.servicecomb.demo.multiErrorCode.MultiRequest 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.MultiRequest 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