private void doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh( Class<?> rmiExceptionClass, Class<?> springExceptionClass) throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.setRefreshStubOnConnectFailure(true); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IBusinessBean); IBusinessBean proxy = (IBusinessBean) factory.getObject(); assertFalse(proxy instanceof IRemoteBean); try { proxy.setName(rmiExceptionClass.getName()); fail("Should have thrown " + rmiExceptionClass.getName()); } catch (Exception ex) { if (springExceptionClass.isInstance(ex)) { // expected } else { throw ex; } } if (RemoteConnectFailureException.class.isAssignableFrom(springExceptionClass)) { assertEquals(2, factory.counter); } else { assertEquals(1, factory.counter); } }
private void doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException( Class<?> rmiExceptionClass, Class<?> springExceptionClass) throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IBusinessBean); IBusinessBean proxy = (IBusinessBean) factory.getObject(); assertFalse(proxy instanceof IRemoteBean); try { proxy.setName(rmiExceptionClass.getName()); fail("Should have thrown " + rmiExceptionClass.getName()); } catch (Exception ex) { if (springExceptionClass.isInstance(ex)) { // expected } else { throw ex; } } assertEquals(1, factory.counter); }
private void doTestRmiProxyFactoryBeanWithException(Class<?> exceptionClass) throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IRemoteBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IRemoteBean); IRemoteBean proxy = (IRemoteBean) factory.getObject(); try { proxy.setName(exceptionClass.getName()); fail("Should have thrown " + exceptionClass.getName()); } catch (Exception ex) { if (exceptionClass.isInstance(ex)) { // expected } else { throw ex; } } assertEquals(1, factory.counter); }
@Test public void rmiProxyFactoryBeanWithWrongBusinessInterface() throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IWrongBusinessBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IWrongBusinessBean); IWrongBusinessBean proxy = (IWrongBusinessBean) factory.getObject(); assertFalse(proxy instanceof IRemoteBean); try { proxy.setOtherName("name"); fail("Should have thrown RemoteProxyFailureException"); } catch (RemoteProxyFailureException ex) { assertTrue(ex.getCause() instanceof NoSuchMethodException); assertTrue(ex.getMessage().contains("setOtherName")); assertTrue(ex.getMessage().contains("IWrongBusinessBean")); } assertEquals(1, factory.counter); }
private void doTestRmiProxyFactoryBeanWithExceptionAndRefresh(Class<?> exceptionClass) throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IRemoteBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.setRefreshStubOnConnectFailure(true); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IRemoteBean); IRemoteBean proxy = (IRemoteBean) factory.getObject(); try { proxy.setName(exceptionClass.getName()); fail("Should have thrown " + exceptionClass.getName()); } catch (Exception ex) { if (exceptionClass.isInstance(ex)) { // expected } else { throw ex; } } assertEquals(2, factory.counter); }
@Test public void rmiProxyFactoryBean() throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IRemoteBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue("Correct singleton value", factory.isSingleton()); assertTrue(factory.getObject() instanceof IRemoteBean); IRemoteBean proxy = (IRemoteBean) factory.getObject(); proxy.setName("myName"); assertEquals("myName", RemoteBean.name); assertEquals(1, factory.counter); }
@Test public void rmiProxyFactoryBeanWithBusinessInterface() throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IBusinessBean); IBusinessBean proxy = (IBusinessBean) factory.getObject(); assertFalse(proxy instanceof IRemoteBean); proxy.setName("myName"); assertEquals("myName", RemoteBean.name); assertEquals(1, factory.counter); }