use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestResponse method testAr.
@Test
public void testAr() {
ar.success(Status.ACCEPTED, 1);
Assert.assertEquals(true, response.isSuccessed());
Assert.assertEquals(false, response.isFailed());
Assert.assertEquals(1, (int) response.getResult());
Assert.assertEquals(Status.ACCEPTED.getStatusCode(), response.getStatusCode());
Assert.assertEquals(Status.ACCEPTED.getReasonPhrase(), response.getReasonPhrase());
Assert.assertEquals(Status.ACCEPTED, response.getStatus());
ar.success(2);
Assert.assertEquals(2, (int) response.getResult());
Assert.assertEquals(Status.OK.getStatusCode(), response.getStatusCode());
Response r = Response.succResp(3);
ar.complete(r);
Assert.assertEquals(r, response);
ar.consumerFail(new Error("abc"));
CommonExceptionData data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Bad Request", data.getMessage());
Assert.assertEquals(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, response.getStatusCode());
ar.fail(InvocationType.CONSUMER, new Error("abc"));
data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Bad Request", data.getMessage());
Assert.assertEquals(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, response.getStatusCode());
InvocationException consumerException = new InvocationException(300, "abc", "def");
ar.consumerFail(consumerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(300, response.getStatusCode());
ar.fail(InvocationType.CONSUMER, consumerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(300, response.getStatusCode());
ar.producerFail(new Error("abc"));
data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
Assert.assertEquals(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, response.getStatusCode());
ar.fail(InvocationType.PRODUCER, new Error("abc"));
data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
Assert.assertEquals(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, response.getStatusCode());
InvocationException producerException = new InvocationException(500, "abc", "def");
ar.producerFail(producerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(500, response.getStatusCode());
ar.fail(InvocationType.PRODUCER, producerException);
Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData());
Assert.assertEquals(500, response.getStatusCode());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSwaggerProducerOperation method processException_normal.
@Test
public void processException_normal(@Mocked SwaggerInvocation invocation) {
Error error = new Error("abc");
Response response = swaggerProducerOperation.processException(invocation, error);
Assert.assertSame(Status.OK, response.getStatus());
Assert.assertEquals("response from error: abc", response.getResult());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSwaggerProducerOperation method processException_InvocationTargetException.
@Test
public void processException_InvocationTargetException(@Mocked SwaggerInvocation invocation) {
Error error = new Error("abc");
InvocationTargetException targetException = new InvocationTargetException(error);
Response response = swaggerProducerOperation.processException(invocation, targetException);
Assert.assertSame(Status.OK, response.getStatus());
Assert.assertEquals("response from error: abc", response.getResult());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestDefaultExceptionToResponseConverter method convert.
@Test
public void convert(@Mocked SwaggerInvocation swaggerInvocation, @Mocked Error e) {
Response response = converter.convert(swaggerInvocation, e);
Assert.assertSame(e, ((InvocationException) response.getResult()).getCause());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestInvocationExceptionToResponseConverter method convert.
@Test
public void convert(@Mocked SwaggerInvocation swaggerInvocation, @Mocked InvocationException e) {
Response response = converter.convert(swaggerInvocation, e);
Assert.assertSame(e, response.getResult());
}
Aggregations