Source Code Cross Referenced for RMTxStoreTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » bus » ws » rm » persistence » jdbc » 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 » ESB » celtix 1.0 » org.objectweb.celtix.bus.ws.rm.persistence.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.bus.ws.rm.persistence.jdbc;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.IOException;
005:        import java.io.InputStream;
006:        import java.math.BigInteger;
007:        import java.sql.Connection;
008:        import java.sql.SQLException;
009:        import java.util.ArrayList;
010:        import java.util.Collection;
011:        import java.util.Date;
012:        import java.util.HashMap;
013:        import java.util.Map;
014:
015:        import javax.xml.soap.SOAPException;
016:        import javax.xml.soap.SOAPMessage;
017:        import javax.xml.ws.handler.MessageContext;
018:
019:        import org.w3c.dom.Node;
020:
021:        import junit.extensions.TestSetup;
022:        import junit.framework.Test;
023:        import junit.framework.TestCase;
024:        import junit.framework.TestSuite;
025:
026:        import org.easymock.classextension.EasyMock;
027:        import org.easymock.classextension.IMocksControl;
028:        import org.objectweb.celtix.bus.bindings.soap.SOAPBindingImpl;
029:        import org.objectweb.celtix.bus.ws.rm.DestinationSequence;
030:        import org.objectweb.celtix.bus.ws.rm.Names;
031:        import org.objectweb.celtix.bus.ws.rm.RMHandlerTest;
032:        import org.objectweb.celtix.bus.ws.rm.RMUtils;
033:        import org.objectweb.celtix.bus.ws.rm.SourceSequence;
034:        import org.objectweb.celtix.bus.ws.rm.persistence.RMStoreException;
035:        import org.objectweb.celtix.context.GenericMessageContext;
036:        import org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType;
037:        import org.objectweb.celtix.ws.rm.Identifier;
038:        import org.objectweb.celtix.ws.rm.SequenceAcknowledgement;
039:        import org.objectweb.celtix.ws.rm.SequenceAcknowledgement.AcknowledgementRange;
040:        import org.objectweb.celtix.ws.rm.persistence.RMDestinationSequence;
041:        import org.objectweb.celtix.ws.rm.persistence.RMMessage;
042:        import org.objectweb.celtix.ws.rm.persistence.RMSourceSequence;
043:
044:        public class RMTxStoreTest extends TestCase {
045:
046:            private static final String CLIENT_ENDPOINT_ID = "celtix.{http://celtix.objectweb.org/greeter_control}GreeterService/GreeterPort";
047:            private static final String SERVER_ENDPOINT_ID = "celtix.{http://celtix.objectweb.org/greeter_control}GreeterService";
048:            private static final String NON_ANON_ACKS_TO = "http://localhost:9999/decoupled_endpoint";
049:            private static final String SOAP_MSG_KEY = "org.objectweb.celtix.bindings.soap.message";
050:
051:            private RMTxStore store;
052:
053:            public static Test suite() throws Exception {
054:
055:                TestSuite suite = new TestSuite(RMTxStoreTest.class);
056:                class RMTxStoreTestSetup extends TestSetup {
057:                    public RMTxStoreTestSetup(Test test) {
058:                        super (test);
059:                    }
060:
061:                    protected void setUp() {
062:                        RMTxStore.deleteDatabaseFiles("rmdb", true);
063:                    }
064:
065:                    protected void tearDown() {
066:                        RMTxStore st = new RMTxStore();
067:                        Map<String, String> params = new HashMap<String, String>();
068:                        params.put(RMTxStore.CONNECTION_URL_PROPERTY,
069:                                "jdbc:derby:rmdb;create=true");
070:                        st.init(params);
071:                        Connection c = st.getConnection();
072:                        try {
073:                            c.close();
074:                        } catch (SQLException ex) {
075:                            // ignore
076:                        }
077:                        RMTxStore.deleteDatabaseFiles("rmdb", false);
078:                    }
079:                }
080:                return new RMTxStoreTestSetup(suite);
081:            }
082:
083:            public void setUp() {
084:                store = new RMTxStore();
085:                Map<String, String> params = new HashMap<String, String>();
086:                params.put(RMTxStore.DRIVER_CLASS_NAME_PROPERTY,
087:                        "org.apache.derby.jdbc.EmbeddedDriver");
088:                params.put(RMTxStore.CONNECTION_URL_PROPERTY,
089:                        "jdbc:derby:rmdb;create=true");
090:                store.init(params);
091:
092:            }
093:
094:            public void testCreateTables() throws SQLException {
095:                // tables should  have been created during initialisation
096:                // but verify the operation is idempotent
097:                store.createTables();
098:            }
099:
100:            public void testCreateDeleteSrcSequences() {
101:                IMocksControl control = EasyMock.createNiceControl();
102:                RMSourceSequence seq = control
103:                        .createMock(RMSourceSequence.class);
104:                Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
105:                sid1.setValue("sequence1");
106:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
107:                EasyMock.expect(seq.getExpiry()).andReturn(null);
108:                EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(
109:                        null);
110:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
111:                        CLIENT_ENDPOINT_ID);
112:
113:                control.replay();
114:                store.createSourceSequence(seq);
115:                control.verify();
116:
117:                control.reset();
118:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
119:                EasyMock.expect(seq.getExpiry()).andReturn(null);
120:                EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(
121:                        null);
122:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
123:                        CLIENT_ENDPOINT_ID);
124:
125:                control.replay();
126:                try {
127:                    store.createSourceSequence(seq);
128:                    fail("Expected RMStoreException was not thrown.");
129:                } catch (RMStoreException ex) {
130:                    SQLException se = (SQLException) ex.getCause();
131:                    // duplicate key value 
132:                    assertEquals("23505", se.getSQLState());
133:                }
134:                control.verify();
135:
136:                control.reset();
137:                Identifier sid2 = RMUtils.getWSRMFactory().createIdentifier();
138:                sid2.setValue("sequence2");
139:                EasyMock.expect(seq.getIdentifier()).andReturn(sid2);
140:                EasyMock.expect(seq.getExpiry()).andReturn(new Date());
141:                Identifier sid3 = RMUtils.getWSRMFactory().createIdentifier();
142:                sid3.setValue("offeringSequence3");
143:                EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(
144:                        sid3);
145:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
146:                        SERVER_ENDPOINT_ID);
147:
148:                control.replay();
149:                store.createSourceSequence(seq);
150:                control.verify();
151:
152:                store.removeSourceSequence(sid1);
153:                store.removeSourceSequence(sid2);
154:
155:                // deleting once again is a no-op
156:                store.removeSourceSequence(sid2);
157:
158:            }
159:
160:            public void testCreateDeleteDestSequences() {
161:                IMocksControl control = EasyMock.createNiceControl();
162:                RMDestinationSequence seq = control
163:                        .createMock(RMDestinationSequence.class);
164:                Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
165:                sid1.setValue("sequence1");
166:                EndpointReferenceType epr = RMUtils
167:                        .createReference(Names.WSA_ANONYMOUS_ADDRESS);
168:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
169:                EasyMock.expect(seq.getAcksTo()).andReturn(epr);
170:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
171:                        SERVER_ENDPOINT_ID);
172:
173:                control.replay();
174:                store.createDestinationSequence(seq);
175:                control.verify();
176:
177:                control.reset();
178:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
179:                EasyMock.expect(seq.getAcksTo()).andReturn(epr);
180:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
181:                        SERVER_ENDPOINT_ID);
182:
183:                control.replay();
184:                try {
185:                    store.createDestinationSequence(seq);
186:                    fail("Expected RMStoreException was not thrown.");
187:                } catch (RMStoreException ex) {
188:                    SQLException se = (SQLException) ex.getCause();
189:                    // duplicate key value 
190:                    assertEquals("23505", se.getSQLState());
191:                }
192:                control.verify();
193:
194:                control.reset();
195:                Identifier sid2 = RMUtils.getWSRMFactory().createIdentifier();
196:                sid2.setValue("sequence2");
197:                EasyMock.expect(seq.getIdentifier()).andReturn(sid2);
198:                epr = RMUtils.createReference(NON_ANON_ACKS_TO);
199:                EasyMock.expect(seq.getAcksTo()).andReturn(epr);
200:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
201:                        CLIENT_ENDPOINT_ID);
202:
203:                control.replay();
204:                store.createDestinationSequence(seq);
205:                control.verify();
206:
207:                store.removeDestinationSequence(sid1);
208:                store.removeDestinationSequence(sid2);
209:
210:                // deleting once again is a no-op
211:                store.removeDestinationSequence(sid2);
212:
213:            }
214:
215:            public void testCreateDeleteMessages() throws IOException,
216:                    SQLException {
217:                IMocksControl control = EasyMock.createNiceControl();
218:                RMMessage msg = control.createMock(RMMessage.class);
219:                Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
220:                sid1.setValue("sequence1");
221:                EasyMock.expect(msg.getMessageNr()).andReturn(BigInteger.ONE)
222:                        .times(2);
223:                InputStream is = new ByteArrayInputStream(new byte[89]);
224:                EasyMock.expect(msg.getContextAsStream()).andReturn(is)
225:                        .times(2);
226:
227:                control.replay();
228:                store.beginTransaction();
229:                store.storeMessage(sid1, msg, true);
230:                store.storeMessage(sid1, msg, false);
231:                store.commit();
232:                control.verify();
233:
234:                control.reset();
235:                EasyMock.expect(msg.getMessageNr()).andReturn(BigInteger.ONE);
236:                EasyMock.expect(msg.getContextAsStream()).andReturn(is);
237:
238:                control.replay();
239:                store.beginTransaction();
240:                try {
241:                    store.storeMessage(sid1, msg, true);
242:                } catch (SQLException ex) {
243:                    assertEquals("23505", ex.getSQLState());
244:                }
245:                store.abort();
246:                control.verify();
247:
248:                control.reset();
249:                EasyMock.expect(msg.getMessageNr()).andReturn(BigInteger.TEN)
250:                        .times(2);
251:                EasyMock.expect(msg.getContextAsStream()).andReturn(is)
252:                        .times(2);
253:
254:                control.replay();
255:                store.beginTransaction();
256:                store.storeMessage(sid1, msg, true);
257:                store.storeMessage(sid1, msg, false);
258:                store.commit();
259:                control.verify();
260:
261:                Collection<BigInteger> messageNrs = new ArrayList<BigInteger>();
262:                messageNrs.add(BigInteger.ZERO);
263:                messageNrs.add(BigInteger.TEN);
264:                messageNrs.add(BigInteger.ONE);
265:                messageNrs.add(BigInteger.TEN);
266:
267:                store.removeMessages(sid1, messageNrs, true);
268:                store.removeMessages(sid1, messageNrs, false);
269:
270:                Identifier sid2 = RMUtils.getWSRMFactory().createIdentifier();
271:                sid1.setValue("sequence2");
272:                store.removeMessages(sid2, messageNrs, true);
273:            }
274:
275:            public void testUpdateDestinationSequence() throws SQLException,
276:                    IOException {
277:                IMocksControl control = EasyMock.createNiceControl();
278:                RMDestinationSequence seq = control
279:                        .createMock(RMDestinationSequence.class);
280:                Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
281:                sid1.setValue("sequence1");
282:                EndpointReferenceType epr = RMUtils
283:                        .createReference(Names.WSA_ANONYMOUS_ADDRESS);
284:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
285:                EasyMock.expect(seq.getAcksTo()).andReturn(epr);
286:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
287:                        SERVER_ENDPOINT_ID);
288:
289:                control.replay();
290:                store.createDestinationSequence(seq);
291:                control.verify();
292:
293:                control.reset();
294:                EasyMock.expect(seq.getLastMessageNr()).andReturn(null);
295:                InputStream is = new ByteArrayInputStream(new byte[32]);
296:                EasyMock.expect(seq.getAcknowledgmentAsStream()).andReturn(is);
297:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
298:
299:                control.replay();
300:                store.beginTransaction();
301:                store.updateDestinationSequence(seq);
302:                store.abort();
303:
304:                control.reset();
305:                EasyMock.expect(seq.getLastMessageNr()).andReturn(
306:                        BigInteger.TEN);
307:                EasyMock.expect(seq.getAcknowledgmentAsStream()).andReturn(is);
308:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
309:
310:                control.replay();
311:                store.beginTransaction();
312:                store.updateDestinationSequence(seq);
313:                store.abort();
314:
315:                store.removeDestinationSequence(sid1);
316:            }
317:
318:            public void testUpdateSourceSequence() throws SQLException {
319:                IMocksControl control = EasyMock.createNiceControl();
320:                RMSourceSequence seq = control
321:                        .createMock(RMSourceSequence.class);
322:                Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
323:                sid1.setValue("sequence1");
324:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
325:                EasyMock.expect(seq.getExpiry()).andReturn(null);
326:                EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(
327:                        null);
328:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
329:                        CLIENT_ENDPOINT_ID);
330:
331:                control.replay();
332:                store.createSourceSequence(seq);
333:                control.verify();
334:
335:                control.reset();
336:                EasyMock.expect(seq.getCurrentMessageNr()).andReturn(
337:                        BigInteger.ONE);
338:                EasyMock.expect(seq.isLastMessage()).andReturn(false);
339:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
340:
341:                control.replay();
342:                store.beginTransaction();
343:                store.updateSourceSequence(seq);
344:                store.abort();
345:
346:                control.reset();
347:                EasyMock.expect(seq.getCurrentMessageNr()).andReturn(
348:                        BigInteger.TEN);
349:                EasyMock.expect(seq.isLastMessage()).andReturn(true);
350:                EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
351:
352:                control.replay();
353:                store.beginTransaction();
354:                store.updateSourceSequence(seq);
355:                store.abort();
356:
357:                store.removeSourceSequence(sid1);
358:
359:            }
360:
361:            public void testGetDestinationSequences() throws SQLException,
362:                    IOException {
363:
364:                Identifier sid1 = null;
365:                Identifier sid2 = null;
366:
367:                Collection<RMDestinationSequence> seqs = store
368:                        .getDestinationSequences("unknown");
369:                assertEquals(0, seqs.size());
370:
371:                try {
372:                    sid1 = setupDestinationSequence("sequence1");
373:
374:                    seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
375:                    assertEquals(1, seqs.size());
376:                    checkRecoveredDestinationSequences(seqs);
377:
378:                    sid2 = setupDestinationSequence("sequence2");
379:                    seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
380:                    assertEquals(2, seqs.size());
381:                    checkRecoveredDestinationSequences(seqs);
382:                } finally {
383:                    if (null != sid1) {
384:                        store.removeDestinationSequence(sid1);
385:                    }
386:                    if (null != sid2) {
387:                        store.removeDestinationSequence(sid2);
388:                    }
389:                }
390:            }
391:
392:            public void testGetSourceSequences() throws SQLException,
393:                    IOException {
394:
395:                Identifier sid1 = null;
396:                Identifier sid2 = null;
397:
398:                Collection<RMSourceSequence> seqs = store
399:                        .getSourceSequences("unknown");
400:                assertEquals(0, seqs.size());
401:
402:                try {
403:                    sid1 = setupSourceSequence("sequence1");
404:
405:                    seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
406:                    assertEquals(1, seqs.size());
407:                    checkRecoveredSourceSequences(seqs);
408:
409:                    sid2 = setupSourceSequence("sequence2");
410:                    seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
411:                    assertEquals(2, seqs.size());
412:                    checkRecoveredSourceSequences(seqs);
413:                } finally {
414:                    if (null != sid1) {
415:                        store.removeSourceSequence(sid1);
416:                    }
417:                    if (null != sid2) {
418:                        store.removeSourceSequence(sid2);
419:                    }
420:                }
421:            }
422:
423:            public void testGetMessages() throws SQLException, IOException,
424:                    SOAPException {
425:
426:                Identifier sid1 = RMUtils.getWSRMFactory().createIdentifier();
427:                sid1.setValue("sequence1");
428:                Identifier sid2 = RMUtils.getWSRMFactory().createIdentifier();
429:                sid2.setValue("sequence2");
430:
431:                Collection<RMMessage> out = store.getMessages(sid1, true);
432:                assertEquals(0, out.size());
433:                Collection<RMMessage> in = store.getMessages(sid1, false);
434:                assertEquals(0, out.size());
435:
436:                try {
437:                    setupMessage(sid1, BigInteger.ONE, true);
438:                    setupMessage(sid1, BigInteger.ONE, false);
439:
440:                    out = store.getMessages(sid1, true);
441:                    assertEquals(1, out.size());
442:                    checkRecoveredMessages(out);
443:
444:                    in = store.getMessages(sid1, false);
445:                    assertEquals(1, in.size());
446:                    checkRecoveredMessages(in);
447:
448:                    setupMessage(sid1, BigInteger.TEN, true);
449:                    setupMessage(sid1, BigInteger.TEN, false);
450:
451:                    out = store.getMessages(sid1, true);
452:                    assertEquals(2, out.size());
453:                    checkRecoveredMessages(out);
454:
455:                    in = store.getMessages(sid1, false);
456:                    assertEquals(2, in.size());
457:                    checkRecoveredMessages(in);
458:                } finally {
459:                    Collection<BigInteger> msgNrs = new ArrayList<BigInteger>();
460:                    msgNrs.add(BigInteger.ONE);
461:                    msgNrs.add(BigInteger.TEN);
462:
463:                    store.removeMessages(sid1, msgNrs, true);
464:                    store.removeMessages(sid1, msgNrs, false);
465:                }
466:            }
467:
468:            private Identifier setupDestinationSequence(String s)
469:                    throws IOException, SQLException {
470:                IMocksControl control = EasyMock.createNiceControl();
471:                DestinationSequence seq = control
472:                        .createMock(DestinationSequence.class);
473:
474:                Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
475:                sid.setValue(s);
476:                EndpointReferenceType epr = RMUtils
477:                        .createReference(Names.WSA_ANONYMOUS_ADDRESS);
478:
479:                SequenceAcknowledgement ack = RMUtils.getWSRMFactory()
480:                        .createSequenceAcknowledgement();
481:                AcknowledgementRange range = RMUtils.getWSRMFactory()
482:                        .createSequenceAcknowledgementAcknowledgementRange();
483:                range.setLower(BigInteger.ONE);
484:                range.setUpper(BigInteger.ONE);
485:                ack.getAcknowledgementRange().add(range);
486:                BigInteger lmn = null;
487:
488:                if ("sequence2".equals(s)) {
489:                    range = RMUtils
490:                            .getWSRMFactory()
491:                            .createSequenceAcknowledgementAcknowledgementRange();
492:                    range.setLower(new BigInteger("3"));
493:                    range.setUpper(BigInteger.TEN);
494:                    ack.getAcknowledgementRange().add(range);
495:                    lmn = BigInteger.TEN;
496:                }
497:
498:                EasyMock.expect(seq.getIdentifier()).andReturn(sid);
499:                EasyMock.expect(seq.getAcksTo()).andReturn(epr);
500:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
501:                        SERVER_ENDPOINT_ID);
502:                EasyMock.expect(seq.getLastMessageNr()).andReturn(lmn);
503:                InputStream is = RMUtils.getPersistenceUtils()
504:                        .getAcknowledgementAsInputStream(ack);
505:                EasyMock.expect(seq.getAcknowledgmentAsStream()).andReturn(is);
506:                EasyMock.expect(seq.getIdentifier()).andReturn(sid);
507:
508:                control.replay();
509:                store.createDestinationSequence(seq);
510:                store.beginTransaction();
511:                store.updateDestinationSequence(seq);
512:
513:                store.commit();
514:
515:                return sid;
516:            }
517:
518:            private Identifier setupSourceSequence(String s)
519:                    throws IOException, SQLException {
520:                IMocksControl control = EasyMock.createNiceControl();
521:                SourceSequence seq = control.createMock(SourceSequence.class);
522:
523:                Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
524:                sid.setValue(s);
525:
526:                Date expiry = null;
527:                Identifier osid = null;
528:                BigInteger cmn = BigInteger.ONE;
529:                boolean lm = false;
530:
531:                if ("sequence2".equals(s)) {
532:                    expiry = new Date(System.currentTimeMillis() + 3600 * 1000);
533:                    osid = RMUtils.getWSRMFactory().createIdentifier();
534:                    osid.setValue("offeringSequence");
535:                    cmn = BigInteger.TEN;
536:                    lm = true;
537:                }
538:
539:                EasyMock.expect(seq.getIdentifier()).andReturn(sid);
540:                EasyMock.expect(seq.getExpiry()).andReturn(expiry);
541:                EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(
542:                        osid);
543:                EasyMock.expect(seq.getEndpointIdentifier()).andReturn(
544:                        CLIENT_ENDPOINT_ID);
545:                EasyMock.expect(seq.getCurrentMessageNr()).andReturn(cmn);
546:                EasyMock.expect(seq.isLastMessage()).andReturn(lm);
547:                EasyMock.expect(seq.getIdentifier()).andReturn(sid);
548:
549:                control.replay();
550:                store.createSourceSequence(seq);
551:                store.beginTransaction();
552:                store.updateSourceSequence(seq);
553:                store.commit();
554:
555:                return sid;
556:            }
557:
558:            public void setupMessage(Identifier sid, BigInteger mn,
559:                    boolean outbound) throws IOException, SQLException,
560:                    SOAPException {
561:                IMocksControl control = EasyMock.createNiceControl();
562:                RMMessage msg = control.createMock(RMMessage.class);
563:                EasyMock.expect(msg.getMessageNr()).andReturn(mn);
564:
565:                MessageContext ctx = new GenericMessageContext();
566:                ctx.put("a", "astring");
567:                ctx.put("b", Boolean.TRUE);
568:                ctx.put("c", new Integer(Integer.MIN_VALUE));
569:                ctx.put("d", mn);
570:                ctx.put("e", this );
571:                InputStream mis = RMHandlerTest.class
572:                        .getResourceAsStream("resources/GreetMeDocLiteralRequest.xml");
573:                SOAPBindingImpl binding = new SOAPBindingImpl(false);
574:                SOAPMessage smsg = binding.getMessageFactory().createMessage(
575:                        null, mis);
576:                ctx.put(SOAP_MSG_KEY, smsg);
577:                InputStream cis = RMUtils.getPersistenceUtils()
578:                        .getContextAsInputStream(ctx);
579:                EasyMock.expect(msg.getContextAsStream()).andReturn(cis);
580:
581:                control.replay();
582:                store.beginTransaction();
583:                store.storeMessage(sid, msg, outbound);
584:                store.commit();
585:            }
586:
587:            private void checkRecoveredDestinationSequences(
588:                    Collection<RMDestinationSequence> seqs) {
589:
590:                for (RMDestinationSequence recovered : seqs) {
591:                    assertTrue("sequence1".equals(recovered.getIdentifier()
592:                            .getValue())
593:                            || "sequence2".equals(recovered.getIdentifier()
594:                                    .getValue()));
595:                    assertEquals(Names.WSA_ANONYMOUS_ADDRESS, recovered
596:                            .getAcksTo().getAddress().getValue());
597:                    assertNull(recovered.getEndpointIdentifier());
598:                    if ("sequence1"
599:                            .equals(recovered.getIdentifier().getValue())) {
600:                        assertNull(recovered.getLastMessageNr());
601:                        assertEquals(1, recovered.getAcknowledgment()
602:                                .getAcknowledgementRange().size());
603:                        AcknowledgementRange r = recovered.getAcknowledgment()
604:                                .getAcknowledgementRange().get(0);
605:                        assertEquals(BigInteger.ONE, r.getLower());
606:                        assertEquals(BigInteger.ONE, r.getUpper());
607:                    } else {
608:                        assertEquals(BigInteger.TEN, recovered
609:                                .getLastMessageNr());
610:                        assertEquals(2, recovered.getAcknowledgment()
611:                                .getAcknowledgementRange().size());
612:                        AcknowledgementRange r = recovered.getAcknowledgment()
613:                                .getAcknowledgementRange().get(0);
614:                        assertEquals(BigInteger.ONE, r.getLower());
615:                        assertEquals(BigInteger.ONE, r.getUpper());
616:                        r = recovered.getAcknowledgment()
617:                                .getAcknowledgementRange().get(1);
618:                        assertEquals(new BigInteger("3"), r.getLower());
619:                        assertEquals(BigInteger.TEN, r.getUpper());
620:                    }
621:                }
622:            }
623:
624:            private void checkRecoveredSourceSequences(
625:                    Collection<RMSourceSequence> seqs) {
626:
627:                for (RMSourceSequence recovered : seqs) {
628:                    assertTrue("sequence1".equals(recovered.getIdentifier()
629:                            .getValue())
630:                            || "sequence2".equals(recovered.getIdentifier()
631:                                    .getValue()));
632:                    assertNull(recovered.getEndpointIdentifier());
633:                    if ("sequence1"
634:                            .equals(recovered.getIdentifier().getValue())) {
635:                        assertFalse(recovered.isLastMessage());
636:                        assertEquals(BigInteger.ONE, recovered
637:                                .getCurrentMessageNr());
638:                        assertNull(recovered.getExpiry());
639:                        assertNull(recovered.getOfferingSequenceIdentifier());
640:                    } else {
641:                        assertTrue(recovered.isLastMessage());
642:                        assertEquals(BigInteger.TEN, recovered
643:                                .getCurrentMessageNr());
644:                        assertNotNull(recovered.getExpiry());
645:                        assertEquals("offeringSequence", recovered
646:                                .getOfferingSequenceIdentifier().getValue());
647:                    }
648:                }
649:            }
650:
651:            public void checkRecoveredMessages(Collection<RMMessage> msgs)
652:                    throws SOAPException {
653:                for (RMMessage msg : msgs) {
654:                    BigInteger mn = msg.getMessageNr();
655:                    assertTrue(BigInteger.ONE.equals(mn)
656:                            || BigInteger.TEN.equals(mn));
657:                    MessageContext mc = msg.getContext();
658:                    assertEquals("astring", mc.get("a"));
659:                    assertTrue((Boolean) mc.get("b"));
660:                    assertEquals(Integer.MIN_VALUE, ((Integer) mc.get("c"))
661:                            .intValue());
662:                    assertEquals(mn, (BigInteger) mc.get("d"));
663:                    assertNull(mc.get("e"));
664:                    SOAPMessage smsg = (SOAPMessage) mc.get(SOAP_MSG_KEY);
665:                    for (int i = 0; i < smsg.getSOAPBody().getChildNodes()
666:                            .getLength(); i++) {
667:                        Node node = smsg.getSOAPBody().getChildNodes().item(i);
668:                        if (Node.ELEMENT_NODE == node.getNodeType()) {
669:                            assertEquals("greetMeRequest", node.getLocalName());
670:                        }
671:                    }
672:                }
673:            }
674:        }
w__w___w___.___j___a___v_a_2__s.__co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.