1 16 17 package org.springframework.remoting.caucho; 18 19 import com.caucho.hessian.client.HessianProxyFactory; 20 import com.caucho.burlap.client.BurlapProxyFactory; 21 import junit.framework.TestCase; 22 23 import org.springframework.beans.ITestBean; 24 import org.springframework.beans.TestBean; 25 import org.springframework.remoting.RemoteAccessException; 26 27 31 public class CauchoRemotingTests extends TestCase { 32 33 public void testHessianProxyFactoryBeanWithAccessError() throws Exception { 34 HessianProxyFactoryBean factory = new HessianProxyFactoryBean(); 35 try { 36 factory.setServiceInterface(TestBean.class); 37 fail("Should have thrown IllegalArgumentException"); 38 } 39 catch (IllegalArgumentException ex) { 40 } 42 factory.setServiceInterface(ITestBean.class); 43 factory.setServiceUrl("http://localhosta/testbean"); 44 factory.afterPropertiesSet(); 45 46 assertTrue("Correct singleton value", factory.isSingleton()); 47 assertTrue(factory.getObject() instanceof ITestBean); 48 ITestBean bean = (ITestBean) factory.getObject(); 49 50 try { 51 bean.setName("test"); 52 fail("Should have thrown RemoteAccessException"); 53 } 54 catch (RemoteAccessException ex) { 55 } 57 } 58 59 public void testHessianProxyFactoryBeanWithAuthenticationAndAccessError() throws Exception { 60 HessianProxyFactoryBean factory = new HessianProxyFactoryBean(); 61 try { 62 factory.setServiceInterface(TestBean.class); 63 fail("Should have thrown IllegalArgumentException"); 64 } 65 catch (IllegalArgumentException ex) { 66 } 68 factory.setServiceInterface(ITestBean.class); 69 factory.setServiceUrl("http://localhosta/testbean"); 70 factory.setUsername("test"); 71 factory.setPassword("bean"); 72 factory.setOverloadEnabled(true); 73 factory.afterPropertiesSet(); 74 75 assertTrue("Correct singleton value", factory.isSingleton()); 76 assertTrue(factory.getObject() instanceof ITestBean); 77 ITestBean bean = (ITestBean) factory.getObject(); 78 79 try { 80 bean.setName("test"); 81 fail("Should have thrown RemoteAccessException"); 82 } 83 catch (RemoteAccessException ex) { 84 } 86 } 87 88 public void testHessianProxyFactoryBeanWithCustomProxyFactory() throws Exception { 89 TestHessianProxyFactory proxyFactory = new TestHessianProxyFactory(); 90 HessianProxyFactoryBean factory = new HessianProxyFactoryBean(); 91 factory.setServiceInterface(ITestBean.class); 92 factory.setServiceUrl("http://localhosta/testbean"); 93 factory.setUsername("test"); 94 factory.setPassword("bean"); 95 factory.setProxyFactory(proxyFactory); 96 factory.setOverloadEnabled(true); 97 factory.afterPropertiesSet(); 98 assertTrue("Correct singleton value", factory.isSingleton()); 99 assertTrue(factory.getObject() instanceof ITestBean); 100 ITestBean bean = (ITestBean) factory.getObject(); 101 102 assertEquals(proxyFactory.user, "test"); 103 assertEquals(proxyFactory.password, "bean"); 104 assertTrue(proxyFactory.overloadEnabled); 105 106 try { 107 bean.setName("test"); 108 fail("Should have thrown RemoteAccessException"); 109 } 110 catch (RemoteAccessException ex) { 111 } 113 } 114 115 public void testBurlapProxyFactoryBeanWithAccessError() throws Exception { 116 BurlapProxyFactoryBean factory = new BurlapProxyFactoryBean(); 117 factory.setServiceInterface(ITestBean.class); 118 factory.setServiceUrl("http://localhosta/testbean"); 119 factory.afterPropertiesSet(); 120 121 assertTrue("Correct singleton value", factory.isSingleton()); 122 assertTrue(factory.getObject() instanceof ITestBean); 123 ITestBean bean = (ITestBean) factory.getObject(); 124 125 try { 126 bean.setName("test"); 127 fail("Should have thrown RemoteAccessException"); 128 } 129 catch (RemoteAccessException ex) { 130 } 132 } 133 134 public void testBurlapProxyFactoryBeanWithAuthenticationAndAccessError() throws Exception { 135 BurlapProxyFactoryBean factory = new BurlapProxyFactoryBean(); 136 factory.setServiceInterface(ITestBean.class); 137 factory.setServiceUrl("http://localhosta/testbean"); 138 factory.setUsername("test"); 139 factory.setPassword("bean"); 140 factory.setOverloadEnabled(true); 141 factory.afterPropertiesSet(); 142 143 assertTrue("Correct singleton value", factory.isSingleton()); 144 assertTrue(factory.getObject() instanceof ITestBean); 145 ITestBean bean = (ITestBean) factory.getObject(); 146 147 try { 148 bean.setName("test"); 149 fail("Should have thrown RemoteAccessException"); 150 } 151 catch (RemoteAccessException ex) { 152 } 154 } 155 156 public void testBurlapProxyFactoryBeanWithCustomProxyFactory() throws Exception { 157 TestBurlapProxyFactory proxyFactory = new TestBurlapProxyFactory(); 158 BurlapProxyFactoryBean factory = new BurlapProxyFactoryBean(); 159 factory.setServiceInterface(ITestBean.class); 160 factory.setServiceUrl("http://localhosta/testbean"); 161 factory.setUsername("test"); 162 factory.setPassword("bean"); 163 factory.setProxyFactory(proxyFactory); 164 factory.setOverloadEnabled(true); 165 factory.afterPropertiesSet(); 166 167 assertTrue("Correct singleton value", factory.isSingleton()); 168 assertTrue(factory.getObject() instanceof ITestBean); 169 ITestBean bean = (ITestBean) factory.getObject(); 170 171 assertEquals(proxyFactory.user, "test"); 172 assertEquals(proxyFactory.password, "bean"); 173 assertTrue(proxyFactory.overloadEnabled); 174 175 try { 176 bean.setName("test"); 177 fail("Should have thrown RemoteAccessException"); 178 } 179 catch (RemoteAccessException ex) { 180 } 182 } 183 184 185 private static class TestHessianProxyFactory extends HessianProxyFactory { 186 187 private String user; 188 private String password; 189 private boolean overloadEnabled; 190 191 public void setUser(String user) { 192 this.user = user; 193 } 194 195 public void setPassword(String password) { 196 this.password = password; 197 } 198 199 public void setOverloadEnabled(boolean overloadEnabled) { 200 this.overloadEnabled = overloadEnabled; 201 } 202 } 203 204 205 private static class TestBurlapProxyFactory extends BurlapProxyFactory { 206 207 private String user; 208 private String password; 209 private boolean overloadEnabled; 210 211 public void setUser(String user) { 212 this.user = user; 213 } 214 215 public void setPassword(String password) { 216 this.password = password; 217 } 218 219 public void setOverloadEnabled(boolean overloadEnabled) { 220 this.overloadEnabled = overloadEnabled; 221 } 222 } 223 224 } 225 | Popular Tags |