Source Code Cross Referenced for PrintSessionBeanTest.java in  » Testing » mockrunner-0.4 » com » mockrunner » example » jms » 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 » Testing » mockrunner 0.4 » com.mockrunner.example.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.example.jms;
002:
003:        import javax.jms.JMSException;
004:        import javax.jms.Queue;
005:        import javax.jms.QueueConnectionFactory;
006:
007:        import org.mockejb.TransactionPolicy;
008:
009:        import com.mockrunner.ejb.EJBTestModule;
010:        import com.mockrunner.example.jms.interfaces.PrintSession;
011:        import com.mockrunner.jms.JMSTestCaseAdapter;
012:        import com.mockrunner.mock.jms.MockTextMessage;
013:
014:        /**
015:         * Example test for {@link PrintSessionBean}. Demonstrates
016:         * how to deal with EJBs in JMS tests. The sender is a session
017:         * bean, the receiver is a message driven bean. Please note
018:         * that you have to deal the the transaction methods of
019:         * {@link com.mockrunner.ejb.EJBTestModule}, because this example
020:         * uses a simulated JTA transaction.
021:         */
022:        public class PrintSessionBeanTest extends JMSTestCaseAdapter {
023:            private EJBTestModule ejbModule;
024:            private PrintSession bean;
025:
026:            protected void setUp() throws Exception {
027:                super .setUp();
028:                ejbModule = createEJBTestModule();
029:                ejbModule
030:                        .setInterfacePackage("com.mockrunner.example.jms.interfaces");
031:                ejbModule.deploySessionBean(
032:                        "com/mockrunner/example/PrintSession",
033:                        PrintSessionBean.class, TransactionPolicy.REQUIRED);
034:                bean = (PrintSession) ejbModule
035:                        .createBean("com/mockrunner/example/PrintSession");
036:                QueueConnectionFactory factory = getJMSMockObjectFactory()
037:                        .getMockQueueConnectionFactory();
038:                Queue queue = getDestinationManager().createQueue("testQueue");
039:                ejbModule.deployMessageBean("java:/ConnectionFactory",
040:                        "queue/testQueue", factory, queue,
041:                        new PrintMessageDrivenBean());
042:            }
043:
044:            //The following commented out setUp method is an alternative approach to
045:            //test a message driven bean. The message bean is not deployed to the
046:            //mock container but instantiated directly, which means that you cannot 
047:            //test JTA transactions when *receiving* the message and you cannot use the 
048:            //MockEJB interceptor framework for the onMessage method.
049:            //In this test case we only test JTA transactions while *sending* the message,
050:            //so this approach works quite well.
051:            /*protected void setUp() throws Exception
052:            {
053:                super.setUp();
054:                ejbModule = createEJBTestModule();
055:                ejbModule.bindToContext("java:/ConnectionFactory", getJMSMockObjectFactory().getMockQueueConnectionFactory());
056:                Queue queue = getDestinationManager().createQueue("testQueue");
057:                ejbModule.bindToContext("queue/testQueue", queue);
058:                registerTestMessageListenerForQueue("testQueue", new PrintMessageDrivenBean());
059:                ejbModule.setInterfacePackage("com.mockrunner.example.jms.interfaces");
060:                ejbModule.deploySessionBean("com/mockrunner/example/PrintSession", PrintSessionBean.class, TransactionPolicy.REQUIRED);
061:                bean = (PrintSession)ejbModule.createBean("com/mockrunner/example/PrintSession");
062:            }*/
063:
064:            public void testSuccessfulDelivery() throws Exception {
065:                bean.sendMessage("123");
066:                ejbModule.verifyCommitted();
067:                verifyNumberQueueSessions(1);
068:                verifyNumberQueueSenders(0, "testQueue", 1);
069:                verifyAllQueueSessionsClosed();
070:                verifyAllQueueSendersClosed(0);
071:                verifyQueueConnectionClosed();
072:                verifyNumberOfCreatedQueueTextMessages(0, 1);
073:                verifyNumberOfReceivedQueueMessages("testQueue", 1);
074:                verifyReceivedQueueMessageEquals("testQueue", 0,
075:                        new MockTextMessage("123"));
076:                verifyReceivedQueueMessageAcknowledged("testQueue", 0);
077:            }
078:
079:            public void testDeliveryMoreMessages() throws Exception {
080:                bean.sendMessage("1");
081:                ejbModule.verifyCommitted();
082:                bean.sendMessage("2");
083:                ejbModule.verifyCommitted();
084:                bean.sendMessage("3");
085:                ejbModule.verifyCommitted();
086:                verifyNumberOfReceivedQueueMessages("testQueue", 3);
087:                verifyAllReceivedQueueMessagesAcknowledged("testQueue");
088:                verifyReceivedQueueMessageEquals("testQueue", 0,
089:                        new MockTextMessage("1"));
090:                verifyReceivedQueueMessageEquals("testQueue", 1,
091:                        new MockTextMessage("2"));
092:                verifyReceivedQueueMessageEquals("testQueue", 2,
093:                        new MockTextMessage("3"));
094:            }
095:
096:            public void testFailure() throws Exception {
097:                getJMSMockObjectFactory().getMockQueueConnectionFactory()
098:                        .setJMSException(new JMSException("TestException"));
099:                bean.sendMessage("1");
100:                ejbModule.verifyNotCommitted();
101:                ejbModule.verifyRolledBack();
102:            }
103:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.