Search in sources :

Example 11 with CommonExceptionData

use of io.servicecomb.core.exception.CommonExceptionData in project java-chassis by ServiceComb.

the class TestException method testInvocationException.

@Test
public void testInvocationException() {
    InvocationException oExceptionIn = new InvocationException(Status.OK, "I am gone now");
    oExceptionIn = ExceptionFactory.convertConsumerException(new Throwable());
    Assert.assertEquals(490, oExceptionIn.getStatusCode());
    oExceptionIn = ExceptionFactory.convertConsumerException(new Throwable(), "abc");
    Assert.assertEquals(490, oExceptionIn.getStatusCode());
    Assert.assertEquals("abc", ((CommonExceptionData) oExceptionIn.getErrorData()).getMessage());
    oExceptionIn = ExceptionFactory.convertProducerException(new Throwable());
    Assert.assertEquals(590, oExceptionIn.getStatusCode());
    oExceptionIn = ExceptionFactory.convertProducerException(new Throwable(), "abcd");
    Assert.assertEquals(590, oExceptionIn.getStatusCode());
    Assert.assertEquals("abcd", ((CommonExceptionData) oExceptionIn.getErrorData()).getMessage());
    oExceptionIn = ExceptionFactory.convertConsumerException(new InvocationException(Status.OK, new String("fake-object")));
    Assert.assertEquals(200, oExceptionIn.getStatusCode());
    oExceptionIn = ExceptionFactory.convertConsumerException(new InvocationTargetException(new Throwable()));
    Assert.assertNotEquals("java.lang.Throwable", oExceptionIn.getMessage());
    InvocationException oTemp = new InvocationException(Status.OK, new CommonExceptionData("testObject"));
    Assert.assertEquals("OK", oTemp.getReasonPhrase());
    Assert.assertEquals("CommonExceptionData [message=testObject]", (oTemp.getErrorData().toString()));
}
Also used : InvocationException(io.servicecomb.core.exception.InvocationException) CommonExceptionData(io.servicecomb.core.exception.CommonExceptionData) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Aggregations

CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)11 InvocationException (io.servicecomb.core.exception.InvocationException)8 Test (org.junit.Test)7 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 Invocation (io.servicecomb.core.Invocation)2 Response (io.servicecomb.core.Response)2 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)2 OperationMeta (io.servicecomb.core.definition.OperationMeta)2 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)1 RestParam (io.servicecomb.common.rest.definition.RestParam)1 AsyncResponse (io.servicecomb.core.AsyncResponse)1 Endpoint (io.servicecomb.core.Endpoint)1 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)1 ProducerOperation (io.servicecomb.core.provider.producer.ProducerOperation)1 TestRequest (io.servicecomb.demo.server.TestRequest)1 User (io.servicecomb.demo.server.User)1 ResponseMeta (io.servicecomb.swagger.invocation.response.ResponseMeta)1 HttpClientResponse (io.vertx.core.http.HttpClientResponse)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1