Source Code Cross Referenced for RMManagerTest.java in  » Web-Services-apache-cxf-2.0.1 » ws-rm » org » apache » cxf » ws » rm » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services apache cxf 2.0.1 » ws rm » org.apache.cxf.ws.rm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf.ws.rm;
019:
020:        import java.lang.reflect.Method;
021:        import java.math.BigInteger;
022:        import java.util.ArrayList;
023:        import java.util.Collection;
024:        import java.util.Date;
025:        import java.util.HashMap;
026:        import java.util.List;
027:        import java.util.TimerTask;
028:
029:        import javax.xml.namespace.QName;
030:
031:        import org.apache.cxf.Bus;
032:        import org.apache.cxf.binding.Binding;
033:        import org.apache.cxf.binding.soap.SoapBinding;
034:        import org.apache.cxf.bus.spring.SpringBusFactory;
035:        import org.apache.cxf.endpoint.Client;
036:        import org.apache.cxf.endpoint.Endpoint;
037:        import org.apache.cxf.endpoint.Server;
038:        import org.apache.cxf.message.Exchange;
039:        import org.apache.cxf.message.Message;
040:        import org.apache.cxf.service.Service;
041:        import org.apache.cxf.service.model.BindingInfo;
042:        import org.apache.cxf.service.model.EndpointInfo;
043:        import org.apache.cxf.service.model.InterfaceInfo;
044:        import org.apache.cxf.service.model.ServiceInfo;
045:        import org.apache.cxf.transport.Conduit;
046:        import org.apache.cxf.ws.addressing.AddressingProperties;
047:        import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
048:        import org.apache.cxf.ws.addressing.AttributedURIType;
049:        import org.apache.cxf.ws.addressing.EndpointReferenceType;
050:        import org.apache.cxf.ws.addressing.JAXWSAConstants;
051:        import org.apache.cxf.ws.addressing.RelatesToType;
052:        import org.apache.cxf.ws.rm.manager.SequenceTerminationPolicyType;
053:        import org.apache.cxf.ws.rm.manager.SourcePolicyType;
054:        import org.apache.cxf.ws.rm.persistence.RMMessage;
055:        import org.apache.cxf.ws.rm.persistence.RMStore;
056:        import org.apache.cxf.ws.rm.policy.RMAssertion;
057:        import org.easymock.classextension.EasyMock;
058:        import org.easymock.classextension.IMocksControl;
059:        import org.junit.Assert;
060:        import org.junit.Before;
061:        import org.junit.Test;
062:
063:        public class RMManagerTest extends Assert {
064:
065:            private MyControl control;
066:            private RMManager manager;
067:
068:            @Before
069:            public void setUp() {
070:                // control = EasyMock.createNiceControl();
071:                control = new MyControl();
072:            }
073:
074:            @Test
075:            public void testAccessors() {
076:                manager = new RMManager();
077:                assertNull(manager.getBus());
078:                assertNull(manager.getStore());
079:                assertNull(manager.getRetransmissionQueue());
080:                assertNotNull(manager.getTimer());
081:
082:                Bus bus = control.createMock(Bus.class);
083:                RMStore store = control.createMock(RMStore.class);
084:                RetransmissionQueue queue = control
085:                        .createMock(RetransmissionQueue.class);
086:
087:                manager.setBus(bus);
088:                manager.setStore(store);
089:                manager.setRetransmissionQueue(queue);
090:                assertSame(bus, manager.getBus());
091:                assertSame(store, manager.getStore());
092:                assertSame(queue, manager.getRetransmissionQueue());
093:                control.replay();
094:                control.verify();
095:            }
096:
097:            @Test
098:            public void testInitialisation() {
099:                manager = new RMManager();
100:                assertNull("RMAssertion is set.", manager.getRMAssertion());
101:                assertNull("sourcePolicy is set.", manager.getSourcePolicy());
102:                assertNull("destinationPolicy is set.", manager
103:                        .getDestinationPolicy());
104:                assertNull("deliveryAssirance is set.", manager
105:                        .getDeliveryAssurance());
106:
107:                manager.initialise();
108:
109:                assertNotNull("RMAssertion is not set.", manager
110:                        .getRMAssertion());
111:                assertNotNull("sourcePolicy is not set.", manager
112:                        .getSourcePolicy());
113:                assertNotNull("destinationPolicy is not set.", manager
114:                        .getDestinationPolicy());
115:                assertNotNull("deliveryAssirance is not set.", manager
116:                        .getDeliveryAssurance());
117:
118:                RMAssertion rma = manager.getRMAssertion();
119:                assertTrue(rma.isSetExponentialBackoff());
120:                assertEquals(3000L, rma.getBaseRetransmissionInterval()
121:                        .getMilliseconds().longValue());
122:                assertTrue(!rma.isSetAcknowledgementInterval());
123:                assertTrue(!rma.isSetInactivityTimeout());
124:
125:                SourcePolicyType sp = manager.getSourcePolicy();
126:                assertEquals(0L, sp.getSequenceExpiration().getTimeInMillis(
127:                        new Date()));
128:                assertEquals(0L, sp.getOfferedSequenceExpiration()
129:                        .getTimeInMillis(new Date()));
130:                assertNull(sp.getAcksTo());
131:                assertTrue(sp.isIncludeOffer());
132:                SequenceTerminationPolicyType stp = sp
133:                        .getSequenceTerminationPolicy();
134:                assertEquals(0, stp.getMaxRanges());
135:                assertEquals(0, stp.getMaxUnacknowledged());
136:                assertTrue(!stp.isTerminateOnShutdown());
137:                assertEquals(BigInteger.ZERO, stp.getMaxLength());
138:            }
139:
140:            @Test
141:            public void testStartServer() throws NoSuchMethodException {
142:                Method m = RMManager.class.getDeclaredMethod(
143:                        "recoverReliableEndpoint", new Class[] {
144:                                Endpoint.class, Conduit.class });
145:                manager = control.createMock(RMManager.class,
146:                        new Method[] { m });
147:                Server s = control.createMock(Server.class);
148:                Endpoint e = control.createMock(Endpoint.class);
149:                EasyMock.expect(s.getEndpoint()).andReturn(e);
150:                manager.recoverReliableEndpoint(e, null);
151:                EasyMock.expectLastCall();
152:                control.replay();
153:                manager.startServer(s);
154:                control.verify();
155:            }
156:
157:            @Test
158:            public void testStopServer() throws NoSuchMethodException {
159:                Method m = RMManager.class.getDeclaredMethod(
160:                        "shutdownReliableEndpoint",
161:                        new Class[] { Endpoint.class });
162:                manager = control.createMock(RMManager.class,
163:                        new Method[] { m });
164:                Server s = control.createMock(Server.class);
165:                Endpoint e = control.createMock(Endpoint.class);
166:                EasyMock.expect(s.getEndpoint()).andReturn(e);
167:                manager.shutdownReliableEndpoint(e);
168:                EasyMock.expectLastCall();
169:                control.replay();
170:                manager.stopServer(s);
171:                control.verify();
172:            }
173:
174:            @Test
175:            public void testClientCreated() throws NoSuchMethodException {
176:                Method m = RMManager.class.getDeclaredMethod(
177:                        "recoverReliableEndpoint", new Class[] {
178:                                Endpoint.class, Conduit.class });
179:                manager = control.createMock(RMManager.class,
180:                        new Method[] { m });
181:                Client client = control.createMock(Client.class);
182:                Endpoint endpoint = control.createMock(Endpoint.class);
183:                EasyMock.expect(client.getEndpoint()).andReturn(endpoint);
184:                Conduit conduit = control.createMock(Conduit.class);
185:                EasyMock.expect(client.getConduit()).andReturn(conduit);
186:                manager.recoverReliableEndpoint(endpoint, conduit);
187:                EasyMock.expectLastCall();
188:                control.replay();
189:                manager.clientCreated(client);
190:                control.verify();
191:            }
192:
193:            @Test
194:            public void testClientDestroyed() throws NoSuchMethodException {
195:                Method m = RMManager.class.getDeclaredMethod(
196:                        "shutdownReliableEndpoint",
197:                        new Class[] { Endpoint.class });
198:                manager = control.createMock(RMManager.class,
199:                        new Method[] { m });
200:                Client c = control.createMock(Client.class);
201:                Endpoint e = control.createMock(Endpoint.class);
202:                EasyMock.expect(c.getEndpoint()).andReturn(e);
203:                manager.shutdownReliableEndpoint(e);
204:                EasyMock.expectLastCall();
205:                control.replay();
206:                manager.clientDestroyed(c);
207:                control.verify();
208:            }
209:
210:            @Test
211:            public void testGetBindingFaultFactory() {
212:                SoapBinding binding = control.createMock(SoapBinding.class);
213:                assertNotNull(new RMManager().getBindingFaultFactory(binding));
214:            }
215:
216:            @Test
217:            public void testGetReliableEndpointServerSideCreate()
218:                    throws NoSuchMethodException {
219:                Method m = RMManager.class.getDeclaredMethod(
220:                        "createReliableEndpoint",
221:                        new Class[] { Endpoint.class });
222:                manager = control.createMock(RMManager.class,
223:                        new Method[] { m });
224:                manager
225:                        .setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
226:                Message message = control.createMock(Message.class);
227:                Exchange exchange = control.createMock(Exchange.class);
228:                EasyMock.expect(message.getExchange()).andReturn(exchange)
229:                        .times(3);
230:                WrappedEndpoint wre = control.createMock(WrappedEndpoint.class);
231:                EasyMock.expect(exchange.get(Endpoint.class)).andReturn(wre);
232:                EndpointInfo ei = control.createMock(EndpointInfo.class);
233:                EasyMock.expect(wre.getEndpointInfo()).andReturn(ei);
234:                QName name = RMConstants.getPortName();
235:                EasyMock.expect(ei.getName()).andReturn(name);
236:                Endpoint e = control.createMock(Endpoint.class);
237:                EasyMock.expect(wre.getWrappedEndpoint()).andReturn(e);
238:                RMEndpoint rme = control.createMock(RMEndpoint.class);
239:                EasyMock.expect(manager.createReliableEndpoint(e)).andReturn(
240:                        rme);
241:                org.apache.cxf.transport.Destination destination = control
242:                        .createMock(org.apache.cxf.transport.Destination.class);
243:                EasyMock.expect(exchange.getDestination()).andReturn(
244:                        destination);
245:                AddressingPropertiesImpl maps = control
246:                        .createMock(AddressingPropertiesImpl.class);
247:                EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(
248:                        null);
249:                EasyMock
250:                        .expect(
251:                                message
252:                                        .get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND))
253:                        .andReturn(maps);
254:                EndpointReferenceType replyTo = RMUtils
255:                        .createAnonymousReference();
256:                EasyMock.expect(maps.getReplyTo()).andReturn(replyTo);
257:                EasyMock.expect(exchange.getConduit(message)).andReturn(null);
258:                rme.initialise(null, replyTo);
259:                EasyMock.expectLastCall();
260:
261:                control.replay();
262:                assertSame(rme, manager.getReliableEndpoint(message));
263:                control.verify();
264:
265:                control.reset();
266:                EasyMock.expect(message.getExchange()).andReturn(exchange);
267:                EasyMock.expect(exchange.get(Endpoint.class)).andReturn(wre);
268:                EasyMock.expect(wre.getEndpointInfo()).andReturn(ei);
269:                EasyMock.expect(ei.getName()).andReturn(name);
270:                EasyMock.expect(wre.getWrappedEndpoint()).andReturn(e);
271:
272:                control.replay();
273:                assertSame(rme, manager.getReliableEndpoint(message));
274:                control.verify();
275:            }
276:
277:            @Test
278:            public void testGetReliableEndpointClientSideCreate()
279:                    throws NoSuchMethodException {
280:                Method m = RMManager.class.getDeclaredMethod(
281:                        "createReliableEndpoint",
282:                        new Class[] { Endpoint.class });
283:                manager = control.createMock(RMManager.class,
284:                        new Method[] { m });
285:                manager
286:                        .setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
287:                Message message = control.createMock(Message.class);
288:                Exchange exchange = control.createMock(Exchange.class);
289:                EasyMock.expect(message.getExchange()).andReturn(exchange)
290:                        .times(3);
291:                Endpoint endpoint = control.createMock(Endpoint.class);
292:                EasyMock.expect(exchange.get(Endpoint.class)).andReturn(
293:                        endpoint);
294:                EndpointInfo ei = control.createMock(EndpointInfo.class);
295:                EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
296:                QName name = new QName("http://x.y.z/a", "GreeterPort");
297:                EasyMock.expect(ei.getName()).andReturn(name);
298:                RMEndpoint rme = control.createMock(RMEndpoint.class);
299:                EasyMock.expect(manager.createReliableEndpoint(endpoint))
300:                        .andReturn(rme);
301:                EasyMock.expect(exchange.getDestination()).andReturn(null);
302:                Conduit conduit = control.createMock(Conduit.class);
303:                EasyMock.expect(exchange.getConduit(message))
304:                        .andReturn(conduit);
305:                rme.initialise(conduit, null);
306:                EasyMock.expectLastCall();
307:
308:                control.replay();
309:                assertSame(rme, manager.getReliableEndpoint(message));
310:                control.verify();
311:
312:                control.reset();
313:                EasyMock.expect(message.getExchange()).andReturn(exchange);
314:                EasyMock.expect(exchange.get(Endpoint.class)).andReturn(
315:                        endpoint);
316:                EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
317:                EasyMock.expect(ei.getName()).andReturn(name);
318:
319:                control.replay();
320:                assertSame(rme, manager.getReliableEndpoint(message));
321:                control.verify();
322:            }
323:
324:            @Test
325:            public void testGetReliableEndpointExisting()
326:                    throws NoSuchMethodException {
327:                Method m = RMManager.class.getDeclaredMethod(
328:                        "createReliableEndpoint",
329:                        new Class[] { Endpoint.class });
330:                manager = control.createMock(RMManager.class,
331:                        new Method[] { m });
332:                manager
333:                        .setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
334:                Message message = control.createMock(Message.class);
335:                Exchange exchange = control.createMock(Exchange.class);
336:                EasyMock.expect(message.getExchange()).andReturn(exchange);
337:                Endpoint endpoint = control.createMock(Endpoint.class);
338:                EasyMock.expect(exchange.get(Endpoint.class)).andReturn(
339:                        endpoint);
340:                EndpointInfo ei = control.createMock(EndpointInfo.class);
341:                EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
342:                QName name = new QName("http://x.y.z/a", "GreeterPort");
343:                EasyMock.expect(ei.getName()).andReturn(name);
344:                RMEndpoint rme = control.createMock(RMEndpoint.class);
345:                manager.getReliableEndpointsMap().put(endpoint, rme);
346:
347:                control.replay();
348:                assertSame(rme, manager.getReliableEndpoint(message));
349:                control.verify();
350:            }
351:
352:            @Test
353:            public void testGetDestination() throws NoSuchMethodException {
354:                Method m = RMManager.class.getDeclaredMethod(
355:                        "getReliableEndpoint", new Class[] { Message.class });
356:                manager = control.createMock(RMManager.class,
357:                        new Method[] { m });
358:                Message message = control.createMock(Message.class);
359:                RMEndpoint rme = control.createMock(RMEndpoint.class);
360:                EasyMock.expect(manager.getReliableEndpoint(message))
361:                        .andReturn(rme);
362:                Destination destination = control.createMock(Destination.class);
363:                EasyMock.expect(rme.getDestination()).andReturn(destination);
364:
365:                control.replay();
366:                assertSame(destination, manager.getDestination(message));
367:                control.verify();
368:
369:                control.reset();
370:                EasyMock.expect(manager.getReliableEndpoint(message))
371:                        .andReturn(null);
372:                control.replay();
373:                assertNull(manager.getDestination(message));
374:                control.verify();
375:            }
376:
377:            @Test
378:            public void testGetSource() throws NoSuchMethodException {
379:                Method m = RMManager.class.getDeclaredMethod(
380:                        "getReliableEndpoint", new Class[] { Message.class });
381:                manager = control.createMock(RMManager.class,
382:                        new Method[] { m });
383:                Message message = control.createMock(Message.class);
384:                RMEndpoint rme = control.createMock(RMEndpoint.class);
385:                EasyMock.expect(manager.getReliableEndpoint(message))
386:                        .andReturn(rme);
387:                Source source = control.createMock(Source.class);
388:                EasyMock.expect(rme.getSource()).andReturn(source);
389:
390:                control.replay();
391:                assertSame(source, manager.getSource(message));
392:                control.verify();
393:
394:                control.reset();
395:                EasyMock.expect(manager.getReliableEndpoint(message))
396:                        .andReturn(null);
397:                control.replay();
398:                assertNull(manager.getSource(message));
399:                control.verify();
400:            }
401:
402:            @Test
403:            public void testGetExistingSequence() throws NoSuchMethodException,
404:                    SequenceFault, RMException {
405:                Method m = RMManager.class.getDeclaredMethod("getSource",
406:                        new Class[] { Message.class });
407:                manager = control.createMock(RMManager.class,
408:                        new Method[] { m });
409:                Message message = control.createMock(Message.class);
410:                Identifier inSid = control.createMock(Identifier.class);
411:
412:                Source source = control.createMock(Source.class);
413:                EasyMock.expect(manager.getSource(message)).andReturn(source);
414:                SourceSequence sseq = control.createMock(SourceSequence.class);
415:                EasyMock.expect(source.getCurrent(inSid)).andReturn(sseq);
416:                control.replay();
417:                assertSame(sseq, manager.getSequence(inSid, message, null));
418:                control.verify();
419:            }
420:
421:            @Test
422:            public void testGetNewSequence() throws NoSuchMethodException,
423:                    SequenceFault, RMException {
424:                Method m = RMManager.class.getDeclaredMethod("getSource",
425:                        new Class[] { Message.class });
426:                manager = control.createMock(RMManager.class,
427:                        new Method[] { m });
428:                Message message = control.createMock(Message.class);
429:                Exchange exchange = control.createMock(Exchange.class);
430:                EasyMock.expect(message.getExchange()).andReturn(exchange)
431:                        .anyTimes();
432:                EasyMock.expect(exchange.getOutMessage()).andReturn(message)
433:                        .anyTimes();
434:                EasyMock.expect(exchange.getInMessage()).andReturn(null)
435:                        .anyTimes();
436:                EasyMock.expect(exchange.getOutFaultMessage()).andReturn(null)
437:                        .anyTimes();
438:                Conduit conduit = control.createMock(Conduit.class);
439:                EasyMock.expect(exchange.getConduit(message))
440:                        .andReturn(conduit).anyTimes();
441:                EasyMock.expect(conduit.getBackChannel()).andReturn(null)
442:                        .anyTimes();
443:                Identifier inSid = control.createMock(Identifier.class);
444:                AddressingProperties maps = control
445:                        .createMock(AddressingProperties.class);
446:                Source source = control.createMock(Source.class);
447:                EasyMock.expect(manager.getSource(message)).andReturn(source);
448:                EasyMock.expect(source.getCurrent(inSid)).andReturn(null);
449:                AttributedURIType uri = control
450:                        .createMock(AttributedURIType.class);
451:                EasyMock.expect(maps.getTo()).andReturn(uri);
452:                EasyMock.expect(uri.getValue()).andReturn(
453:                        "http://localhost:9001/TestPort");
454:                EndpointReferenceType epr = RMUtils.createNoneReference();
455:                EasyMock.expect(maps.getReplyTo()).andReturn(epr);
456:                RMEndpoint rme = control.createMock(RMEndpoint.class);
457:                EasyMock.expect(source.getReliableEndpoint()).andReturn(rme)
458:                        .times(2);
459:                Proxy proxy = control.createMock(Proxy.class);
460:                EasyMock.expect(rme.getProxy()).andReturn(proxy);
461:                CreateSequenceResponseType createResponse = control
462:                        .createMock(CreateSequenceResponseType.class);
463:                proxy
464:                        .createSequence(
465:                                EasyMock
466:                                        .isA(org.apache.cxf.ws.addressing.v200408.EndpointReferenceType.class),
467:                                (RelatesToType) EasyMock.isNull(), EasyMock
468:                                        .eq(false));
469:                EasyMock.expectLastCall().andReturn(createResponse);
470:                Servant servant = control.createMock(Servant.class);
471:                EasyMock.expect(rme.getServant()).andReturn(servant);
472:                servant.createSequenceResponse(createResponse);
473:                EasyMock.expectLastCall();
474:                SourceSequence sseq = control.createMock(SourceSequence.class);
475:                EasyMock.expect(source.awaitCurrent(inSid)).andReturn(sseq);
476:                sseq.setTarget(EasyMock.isA(EndpointReferenceType.class));
477:                EasyMock.expectLastCall();
478:
479:                control.replay();
480:                assertSame(sseq, manager.getSequence(inSid, message, maps));
481:                control.verify();
482:            }
483:
484:            @Test
485:            public void testShutdown() {
486:                Bus bus = new SpringBusFactory().createBus(
487:                        "org/apache/cxf/ws/rm/rmmanager.xml", false);
488:                manager = bus.getExtension(RMManager.class);
489:                Endpoint e = control.createMock(Endpoint.class);
490:                RMEndpoint rme = control.createMock(RMEndpoint.class);
491:                manager.getReliableEndpointsMap().put(e, rme);
492:                rme.shutdown();
493:                EasyMock.expectLastCall();
494:                assertNotNull(manager);
495:                class TestTask extends TimerTask {
496:                    public void run() {
497:                    }
498:                }
499:                control.replay();
500:                bus.shutdown(true);
501:                try {
502:                    manager.getTimer().schedule(new TestTask(), 5000);
503:                    fail("Timer has not been cancelled.");
504:                } catch (IllegalStateException ex) {
505:                    // expected
506:                }
507:                control.verify();
508:            }
509:
510:            @Test
511:            public void testShutdownReliableEndpoint() {
512:                manager = new RMManager();
513:                Endpoint e = control.createMock(Endpoint.class);
514:                RMEndpoint rme = control.createMock(RMEndpoint.class);
515:                control.replay();
516:                manager.shutdownReliableEndpoint(e);
517:                control.verify();
518:
519:                control.reset();
520:                manager.getReliableEndpointsMap().put(e, rme);
521:                rme.shutdown();
522:                EasyMock.expectLastCall();
523:                control.replay();
524:                manager.shutdownReliableEndpoint(e);
525:                assertNull(manager.getReliableEndpointsMap().get(e));
526:                control.verify();
527:            }
528:
529:            @Test
530:            public void testRecoverReliableEndpoint() {
531:                manager = new RMManager();
532:                Endpoint endpoint = control.createMock(Endpoint.class);
533:                Conduit conduit = control.createMock(Conduit.class);
534:
535:                control.replay();
536:                manager.recoverReliableEndpoint(endpoint, conduit);
537:                control.verify();
538:
539:                control.reset();
540:
541:                RMStore store = control.createMock(RMStore.class);
542:                manager.setStore(store);
543:
544:                control.replay();
545:                manager.recoverReliableEndpoint(endpoint, conduit);
546:                control.verify();
547:            }
548:
549:            @Test
550:            public void testRecoverReliableClientEndpoint()
551:                    throws NoSuchMethodException {
552:                Method method = RMManager.class.getDeclaredMethod(
553:                        "createReliableEndpoint",
554:                        new Class[] { Endpoint.class });
555:                manager = control.createMock(RMManager.class,
556:                        new Method[] { method });
557:                Endpoint endpoint = control.createMock(Endpoint.class);
558:                EndpointInfo ei = control.createMock(EndpointInfo.class);
559:                ServiceInfo si = control.createMock(ServiceInfo.class);
560:                BindingInfo bi = control.createMock(BindingInfo.class);
561:                InterfaceInfo ii = control.createMock(InterfaceInfo.class);
562:                setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
563:                Conduit conduit = control.createMock(Conduit.class);
564:                setUpRecoverReliableEndpoint(endpoint, conduit, null, null);
565:                control.replay();
566:                manager.recoverReliableEndpoint(endpoint, conduit);
567:                control.verify();
568:
569:                control.reset();
570:                setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
571:                SourceSequence ss = control.createMock(SourceSequence.class);
572:                setUpRecoverReliableEndpoint(endpoint, conduit, ss, null);
573:                control.replay();
574:                manager.recoverReliableEndpoint(endpoint, conduit);
575:                control.verify();
576:
577:                control.reset();
578:                setUpEndpointForRecovery(endpoint, ei, si, bi, ii);
579:                RMMessage m = control.createMock(RMMessage.class);
580:                setUpRecoverReliableEndpoint(endpoint, conduit, ss, m);
581:                control.replay();
582:                manager.recoverReliableEndpoint(endpoint, conduit);
583:                control.verify();
584:            }
585:
586:            Endpoint setUpEndpointForRecovery(Endpoint endpoint,
587:                    EndpointInfo ei, ServiceInfo si, BindingInfo bi,
588:                    InterfaceInfo ii) {
589:                EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei)
590:                        .anyTimes();
591:                EasyMock.expect(ei.getService()).andReturn(si).anyTimes();
592:                EasyMock.expect(si.getName()).andReturn(new QName("S", "s"))
593:                        .anyTimes();
594:                EasyMock.expect(ei.getName()).andReturn(new QName("P", "p"))
595:                        .anyTimes();
596:                EasyMock.expect(si.getInterface()).andReturn(ii).anyTimes();
597:                return endpoint;
598:            }
599:
600:            void setUpRecoverReliableEndpoint(Endpoint endpoint,
601:                    Conduit conduit, SourceSequence ss, RMMessage m) {
602:                RMStore store = control.createMock(RMStore.class);
603:                RetransmissionQueue queue = control
604:                        .createMock(RetransmissionQueue.class);
605:                manager.setStore(store);
606:                manager.setRetransmissionQueue(queue);
607:
608:                Collection<SourceSequence> sss = new ArrayList<SourceSequence>();
609:                if (null != ss) {
610:                    sss.add(ss);
611:                }
612:                EasyMock.expect(store.getSourceSequences("{S}s.{P}p"))
613:                        .andReturn(sss);
614:                if (null == ss) {
615:                    return;
616:                }
617:
618:                Collection<RMMessage> ms = new ArrayList<RMMessage>();
619:                if (null != m) {
620:                    ms.add(m);
621:                }
622:                Identifier id = new Identifier();
623:                id.setValue("S1");
624:                EasyMock.expect(ss.getIdentifier()).andReturn(id).times(
625:                        null == m ? 1 : 2);
626:                EasyMock.expect(store.getMessages(id, true)).andReturn(ms);
627:                if (null == m) {
628:                    return;
629:                }
630:
631:                manager
632:                        .setReliableEndpointsMap(new HashMap<Endpoint, RMEndpoint>());
633:                RMEndpoint rme = control.createMock(RMEndpoint.class);
634:                EasyMock.expect(manager.createReliableEndpoint(endpoint))
635:                        .andReturn(rme);
636:                Source source = control.createMock(Source.class);
637:                EasyMock.expect(rme.getSource()).andReturn(source);
638:                source.addSequence(ss, false);
639:                EasyMock.expectLastCall();
640:
641:                Service service = control.createMock(Service.class);
642:                EasyMock.expect(endpoint.getService()).andReturn(service);
643:                Binding binding = control.createMock(Binding.class);
644:                EasyMock.expect(endpoint.getBinding()).andReturn(binding);
645:
646:                EasyMock.expect(ss.isLastMessage()).andReturn(true);
647:                EasyMock.expect(ss.getCurrentMessageNr()).andReturn(
648:                        BigInteger.TEN);
649:                EasyMock.expect(m.getMessageNumber()).andReturn(BigInteger.TEN)
650:                        .times(2);
651:                if (null == conduit) {
652:                    EasyMock.expect(m.getTo()).andReturn("toAddress");
653:                }
654:                byte[] content = new byte[] { 'x', '9' };
655:                EasyMock.expect(m.getContent()).andReturn(content);
656:                queue.addUnacknowledged(EasyMock.isA(Message.class));
657:                EasyMock.expectLastCall();
658:                queue.start();
659:                EasyMock.expectLastCall();
660:            }
661:
662:            @Test
663:            public void testDefaultSequenceIdentifierGenerator() {
664:                manager = new RMManager();
665:                assertNull(manager.getIdGenerator());
666:                SequenceIdentifierGenerator generator = manager.new DefaultSequenceIdentifierGenerator();
667:                manager.setIdGenerator(generator);
668:                assertSame(generator, manager.getIdGenerator());
669:                Identifier id1 = generator.generateSequenceIdentifier();
670:                assertNotNull(id1);
671:                assertNotNull(id1.getValue());
672:                Identifier id2 = generator.generateSequenceIdentifier();
673:                assertTrue(id1 != id2);
674:                assertTrue(!id1.getValue().equals(id2.getValue()));
675:                control.replay();
676:            }
677:
678:            class MyControl {
679:                private IMocksControl c;
680:                private List<Object> mocks;
681:
682:                MyControl() {
683:                    c = EasyMock.createNiceControl();
684:                    mocks = new ArrayList<Object>();
685:                }
686:
687:                void replay() {
688:                    c.replay();
689:                }
690:
691:                void reset() {
692:                    c.reset();
693:                }
694:
695:                void verify() {
696:                    c.verify();
697:                }
698:
699:                <T> T createMock(Class<T> cls) {
700:                    T mock = c.createMock(cls);
701:                    mocks.add(mock);
702:                    return mock;
703:                }
704:
705:                <T> T createMock(Class<T> cls, Method[] m) {
706:                    T mock = c.createMock(cls, m);
707:                    mocks.add(mock);
708:                    return mock;
709:                }
710:
711:            }
712:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.