Code example for ConnectException

0
 
    public void testInterceptConnectionException() throws Exception { 
        IMocksControl mcClient = org.easymock.classextension.EasyMock.createControl();
        XmlRpcClient client = mcClient.createMock(XmlRpcClient.class);
        client.execute(anyRequest());
        mcClient.andThrow(new ConnectException("test"));
        mcClient.replay();
 
        XmlRpcClientInterceptor interceptor = new XmlRpcClientInterceptor();
        interceptor.setServiceInterface(TestFunctions.class);
        interceptor.setXmlRpcClient(client);
 
        TestFunctions proxy = (TestFunctions) ProxyFactory.getProxy(TestFunctions.class,
                interceptor);
 
        try { 
            proxy.multiplyTest("x", 5);
            fail("Should throw exception");
        } catch (XmlRpcRemoteException e) {
            assertEquals(0, e.getFaultCode());
            assertEquals("test", e.getMessage());