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()));
}
Aggregations