KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bindings > AbstractBindingImplTest


1 package org.objectweb.celtix.bindings;
2
3 import java.io.IOException JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.List JavaDoc;
6
7 import javax.xml.ws.handler.Handler;
8 import javax.xml.ws.handler.LogicalHandler;
9 import javax.xml.ws.handler.MessageContext;
10
11 import junit.framework.TestCase;
12
13 import org.easymock.classextension.EasyMock;
14 import org.easymock.classextension.IMocksControl;
15 import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType;
16 import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerType;
17 import org.objectweb.celtix.bus.jaxws.configuration.types.ObjectFactory;
18 import org.objectweb.celtix.bus.jaxws.configuration.types.SystemHandlerChainType;
19 import org.objectweb.celtix.common.injection.ResourceInjector;
20 import org.objectweb.celtix.configuration.Configuration;
21 import org.objectweb.celtix.context.InputStreamMessageContext;
22 import org.objectweb.celtix.context.ObjectMessageContext;
23 import org.objectweb.celtix.context.OutputStreamMessageContext;
24 import org.objectweb.celtix.context.StreamMessageContext;
25 import org.objectweb.celtix.handlers.HandlerInvoker;
26 import org.objectweb.celtix.handlers.StreamHandler;
27 import org.objectweb.celtix.handlers.SystemHandler;
28
29
30 import static org.easymock.EasyMock.expect;
31
32 public class AbstractBindingImplTest extends TestCase {
33     private Handler lhs1;
34     private Handler lhs2;
35     private Handler lhs3;
36     private Handler phs1;
37     private Handler phs2;
38     private Handler phs3;
39     
40     private Handler lh2;
41     private Handler lh1;
42     private Handler ph2;
43     private Handler ph1;
44     private Handler sh1;
45     
46     private List JavaDoc<Handler> userHandlers;
47         
48     public void setUp() {
49         
50         lhs1 = new TestLogicalSystemHandler();
51         lhs2 = new TestLogicalSystemHandler();
52         lhs3 = new TestLogicalSystemHandler();
53         phs1 = new TestProtocolSystemHandler();
54         phs2 = new TestProtocolSystemHandler();
55         phs3 = new TestProtocolSystemHandler();
56         
57         lh1 = new TestLogicalSystemHandler();
58         lh2 = new TestLogicalSystemHandler();
59         ph1 = new TestProtocolSystemHandler();
60         ph2 = new TestProtocolSystemHandler();
61         sh1 = new TestStreamHandler();
62         
63         userHandlers = new ArrayList JavaDoc<Handler>();
64         userHandlers.add(sh1);
65         userHandlers.add(ph1);
66         userHandlers.add(lh1);
67         userHandlers.add(lh2);
68         userHandlers.add(ph2);
69     }
70     
71     public void testSystemHandlerAccessors() {
72         TestBinding b = new TestBinding();
73         
74         List JavaDoc<Handler> preLogical = b.getPreLogicalSystemHandlers();
75         assertEquals(0, preLogical.size());
76         List JavaDoc<Handler> postLogical = b.getPostLogicalSystemHandlers();
77         assertEquals(0, postLogical.size());
78         List JavaDoc<Handler> preProtocol = b.getPreProtocolSystemHandlers();
79         assertEquals(0, preProtocol.size());
80         List JavaDoc<Handler> postProtocol = b.getPostProtocolSystemHandlers();
81         assertEquals(0, postProtocol.size());
82         
83         setSystemHandlers(b);
84
85         preLogical = b.getPreLogicalSystemHandlers();
86         assertEquals(2, preLogical.size());
87         postLogical = b.getPostLogicalSystemHandlers();
88         assertEquals(1, postLogical.size());
89         preProtocol = b.getPreProtocolSystemHandlers();
90         assertEquals(1, preProtocol.size());
91         postProtocol = b.getPostProtocolSystemHandlers();
92         assertEquals(2, postProtocol.size());
93     }
94     
95     public void testGetHandlerChain() {
96         TestBinding b = new TestBinding();
97         List JavaDoc<Handler> handlers;
98         
99         assertNull(b.getHandlerChain(false));
100         assertEquals(0, b.getHandlerChain(true).size());
101                
102         setSystemHandlers(b);
103         
104         assertNull(b.getHandlerChain(false));
105         handlers = b.getHandlerChain(true);
106         assertEquals(6, handlers.size());
107         assertTrue(lhs1 == handlers.get(0));
108         assertTrue(lhs2 == handlers.get(1));
109         assertTrue(lhs3 == handlers.get(2));
110         assertTrue(phs1 == handlers.get(3));
111         assertTrue(phs2 == handlers.get(4));
112         assertTrue(phs3 == handlers.get(5));
113         
114         b.setHandlerChain(userHandlers);
115         
116         assertEquals(5, b.getHandlerChain(false).size());
117         handlers = b.getHandlerChain(true);
118         assertEquals(11, handlers.size());
119         assertTrue(lhs1 == handlers.get(0));
120         assertTrue(lhs2 == handlers.get(1));
121         assertTrue(lh1 == handlers.get(2));
122         assertTrue(lh2 == handlers.get(3));
123         assertTrue(lhs3 == handlers.get(4));
124         assertTrue(phs1 == handlers.get(5));
125         assertTrue(ph1 == handlers.get(6));
126         assertTrue(ph2 == handlers.get(7));
127         assertTrue(phs2 == handlers.get(8));
128         assertTrue(phs3 == handlers.get(9));
129         assertTrue(sh1 == handlers.get(10));
130     }
131     
132     public void testConfigureSystemHandlers() {
133         IMocksControl control = EasyMock.createControl();
134         TestBinding b = new TestBinding();
135         SystemHandlerChainType shc = null;
136         Configuration c = control.createMock(Configuration.class);
137         expect(c.getObject("systemHandlerChain")).andReturn(shc);
138         control.replay();
139         
140         b.configureSystemHandlers(c);
141         assertEquals(0, b.getPreLogicalSystemHandlers().size());
142         assertEquals(0, b.getPostLogicalSystemHandlers().size());
143         assertEquals(0, b.getPreProtocolSystemHandlers().size());
144         assertEquals(0, b.getPreProtocolSystemHandlers().size());
145         
146         control.verify();
147         control.reset();
148         
149         shc = new ObjectFactory().createSystemHandlerChainType();
150         c = control.createMock(Configuration.class);
151         expect(c.getObject("systemHandlerChain")).andReturn(shc);
152         control.replay();
153         
154         b.configureSystemHandlers(c);
155         assertEquals(0, b.getPreLogicalSystemHandlers().size());
156         assertEquals(0, b.getPostLogicalSystemHandlers().size());
157         assertEquals(0, b.getPreProtocolSystemHandlers().size());
158         assertEquals(0, b.getPreProtocolSystemHandlers().size());
159         
160         control.verify();
161         control.reset();
162         
163         shc = createSystemHandlerChain();
164         c = control.createMock(Configuration.class);
165         expect(c.getObject("systemHandlerChain")).andReturn(shc);
166         control.replay();
167         
168         b.configureSystemHandlers(c);
169         assertEquals(2, b.getPreLogicalSystemHandlers().size());
170         assertEquals(1, b.getPostLogicalSystemHandlers().size());
171         assertEquals(1, b.getPreProtocolSystemHandlers().size());
172         assertEquals(2, b.getPostProtocolSystemHandlers().size());
173         
174         control.verify();
175     }
176     
177     public void testInjectSystemHandlers() {
178         IMocksControl control = EasyMock.createControl();
179         TestBinding b = new TestBinding();
180         SystemHandlerChainType shc = createSystemHandlerChain();
181         Configuration c = control.createMock(Configuration.class);
182         expect(c.getObject("systemHandlerChain")).andReturn(shc);
183         ResourceInjector ri = control.createMock(ResourceInjector.class);
184         ri.inject(EasyMock.isA(SystemHandler.class));
185         EasyMock.expectLastCall().times(6);
186         control.replay();
187         
188         b.configureSystemHandlers(c);
189         b.injectSystemHandlers(ri);
190         
191         control.verify();
192     }
193     
194     
195     private SystemHandlerChainType createSystemHandlerChain() {
196         SystemHandlerChainType shc = new ObjectFactory().createSystemHandlerChainType();
197         HandlerChainType hc = new ObjectFactory().createHandlerChainType();
198         List JavaDoc<HandlerType> handlers = hc.getHandler();
199         HandlerType h = new ObjectFactory().createHandlerType();
200         h.setHandlerName("lhs1");
201         h.setHandlerClass(TestLogicalSystemHandler.class.getName());
202         handlers.add(h);
203         h = new ObjectFactory().createHandlerType();
204         h.setHandlerName("lhs2");
205         h.setHandlerClass(TestLogicalSystemHandler.class.getName());
206         handlers.add(h);
207         shc.setPreLogical(hc);
208         
209         hc = new ObjectFactory().createHandlerChainType();
210         handlers = hc.getHandler();
211         h = new ObjectFactory().createHandlerType();
212         h.setHandlerName("lhs3");
213         h.setHandlerClass(TestLogicalSystemHandler.class.getName());
214         handlers.add(h);
215         shc.setPostLogical(hc);
216         
217         hc = new ObjectFactory().createHandlerChainType();
218         handlers = hc.getHandler();
219         h = new ObjectFactory().createHandlerType();
220         h.setHandlerName("phs1");
221         h.setHandlerClass(TestProtocolSystemHandler.class.getName());
222         handlers.add(h);
223         shc.setPreProtocol(hc);
224         
225         hc = new ObjectFactory().createHandlerChainType();
226         handlers = hc.getHandler();
227         h = new ObjectFactory().createHandlerType();
228         h.setHandlerName("phs2");
229         h.setHandlerClass(TestProtocolSystemHandler.class.getName());
230         handlers.add(h);
231         h = new ObjectFactory().createHandlerType();
232         h.setHandlerName("phs3");
233         h.setHandlerClass(TestProtocolSystemHandler.class.getName());
234         handlers.add(h);
235         shc.setPostProtocol(hc);
236         
237         return shc;
238     }
239     
240     private void setSystemHandlers(TestBinding b) {
241         b.getPreLogicalSystemHandlers().add(lhs1);
242         b.getPreLogicalSystemHandlers().add(lhs2);
243         b.getPostLogicalSystemHandlers().add(lhs3);
244         b.getPreProtocolSystemHandlers().add(phs1);
245         b.getPostProtocolSystemHandlers().add(phs2);
246         b.getPostProtocolSystemHandlers().add(phs3);
247     }
248     
249     static class TestBinding extends AbstractBindingImpl {
250
251         public MessageContext createBindingMessageContext(MessageContext orig) {
252             return null;
253         }
254
255         public HandlerInvoker createHandlerInvoker() {
256             return null;
257         }
258
259         public void marshal(ObjectMessageContext objContext, MessageContext context,
260                                DataBindingCallback callback) {
261         }
262         
263         public void marshalFault(ObjectMessageContext objContext, MessageContext context,
264                                DataBindingCallback callback) {
265         }
266
267         public void unmarshal(MessageContext context, ObjectMessageContext objContext,
268                                  DataBindingCallback callback) {
269         }
270         
271         public void unmarshalFault(MessageContext context, ObjectMessageContext objContext,
272                                       DataBindingCallback callback) {
273         }
274
275         public void read(InputStreamMessageContext inContext, MessageContext msgContext)
276             throws IOException JavaDoc {
277         }
278
279         public void write(MessageContext msgContext, OutputStreamMessageContext outContext)
280             throws IOException JavaDoc {
281         }
282
283         public boolean hasFault(MessageContext msgContext) {
284             return false;
285         }
286
287         public void updateMessageContext(MessageContext msgContext) {
288         }
289         
290         
291         
292         
293        
294     }
295     
296     public static class TestProtocolSystemHandler implements Handler, SystemHandler {
297
298         public void close(MessageContext arg0) {
299         }
300
301         public boolean handleFault(MessageContext arg0) {
302             return false;
303         }
304
305         public boolean handleMessage(MessageContext arg0) {
306             return false;
307         }
308         
309     }
310
311     public static class TestLogicalSystemHandler implements LogicalHandler, SystemHandler {
312         
313         public void close(MessageContext arg0) {
314         }
315
316         public boolean handleFault(MessageContext arg0) {
317             return false;
318         }
319
320         public boolean handleMessage(MessageContext arg0) {
321             return false;
322         }
323     }
324     
325     public static class TestStreamHandler implements StreamHandler {
326
327         public void close(MessageContext arg0) {
328         }
329
330         public boolean handleFault(StreamMessageContext arg0) {
331             return false;
332         }
333
334         public boolean handleMessage(StreamMessageContext arg0) {
335             return false;
336         }
337         
338     }
339   
340 }
341
Popular Tags