Search in sources :

Example 1 with HessianException

use of com.alibaba.com.caucho.hessian.HessianException in project dubbo by alibaba.

the class ExceptionFilterTest method testConvertToRunTimeException.

@SuppressWarnings("unchecked")
@Test
public void testConvertToRunTimeException() throws Exception {
    ExceptionFilter exceptionFilter = new ExceptionFilter();
    RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
    AppResponse mockRpcResult = new AppResponse();
    mockRpcResult.setException(new HessianException("hessian"));
    Result mockAsyncResult = AsyncRpcResult.newDefaultAsyncResult(mockRpcResult, invocation);
    Invoker<DemoService> invoker = mock(Invoker.class);
    when(invoker.invoke(invocation)).thenReturn(mockAsyncResult);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result asyncResult = exceptionFilter.invoke(invoker, invocation);
    AppResponse appResponse = (AppResponse) asyncResult.get();
    exceptionFilter.onResponse(appResponse, invoker, invocation);
    Assertions.assertFalse(appResponse.getException() instanceof HessianException);
    Assertions.assertEquals(appResponse.getException().getClass(), RuntimeException.class);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.support.DemoService) HessianException(com.alibaba.com.caucho.hessian.HessianException) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Aggregations

HessianException (com.alibaba.com.caucho.hessian.HessianException)1 AppResponse (org.apache.dubbo.rpc.AppResponse)1 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)1 Result (org.apache.dubbo.rpc.Result)1 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)1 DemoService (org.apache.dubbo.rpc.support.DemoService)1 Test (org.junit.jupiter.api.Test)1