KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > remoting > caucho > CauchoRemotingTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
28  * @author Juergen Hoeller
29  * @since 16.05.2003
30  */

31 public class CauchoRemotingTests extends TestCase {
32
33     public void testHessianProxyFactoryBeanWithAccessError() throws Exception JavaDoc {
34         HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
35         try {
36             factory.setServiceInterface(TestBean.class);
37             fail("Should have thrown IllegalArgumentException");
38         }
39         catch (IllegalArgumentException JavaDoc ex) {
40             // expected
41
}
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             // expected
56
}
57     }
58
59     public void testHessianProxyFactoryBeanWithAuthenticationAndAccessError() throws Exception JavaDoc {
60         HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
61         try {
62             factory.setServiceInterface(TestBean.class);
63             fail("Should have thrown IllegalArgumentException");
64         }
65         catch (IllegalArgumentException JavaDoc ex) {
66             // expected
67
}
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             // expected
85
}
86     }
87
88     public void testHessianProxyFactoryBeanWithCustomProxyFactory() throws Exception JavaDoc {
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             // expected
112
}
113     }
114
115     public void testBurlapProxyFactoryBeanWithAccessError() throws Exception JavaDoc {
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             // expected
131
}
132     }
133
134     public void testBurlapProxyFactoryBeanWithAuthenticationAndAccessError() throws Exception JavaDoc {
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             // expected
153
}
154     }
155
156     public void testBurlapProxyFactoryBeanWithCustomProxyFactory() throws Exception JavaDoc {
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             // expected
181
}
182     }
183
184
185     private static class TestHessianProxyFactory extends HessianProxyFactory {
186
187         private String JavaDoc user;
188         private String JavaDoc password;
189         private boolean overloadEnabled;
190
191         public void setUser(String JavaDoc user) {
192             this.user = user;
193         }
194
195         public void setPassword(String JavaDoc 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 JavaDoc user;
208         private String JavaDoc password;
209         private boolean overloadEnabled;
210
211         public void setUser(String JavaDoc user) {
212             this.user = user;
213         }
214
215         public void setPassword(String JavaDoc password) {
216             this.password = password;
217         }
218
219         public void setOverloadEnabled(boolean overloadEnabled) {
220             this.overloadEnabled = overloadEnabled;
221         }
222     }
223
224 }
225
Popular Tags