Source Code Cross Referenced for NewsSubscriberTest.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) 


01:        package com.mockrunner.example.jms;
02:
03:        import javax.jms.JMSException;
04:        import javax.jms.Session;
05:        import javax.jms.Topic;
06:        import javax.jms.TopicConnection;
07:        import javax.jms.TopicPublisher;
08:        import javax.jms.TopicSession;
09:
10:        import com.mockrunner.ejb.EJBTestModule;
11:        import com.mockrunner.jms.JMSTestCaseAdapter;
12:        import com.mockrunner.mock.jms.MockTextMessage;
13:
14:        /**
15:         * Example test for {@link NewsSubscriber}. Demonstrates
16:         * message selector usage. Only messages with the <code>subject</code>
17:         * property <code>Java</code> will be received by {@link NewsSubscriber}.
18:         * There's one problem with {@link NewsSubscriber}. It blocks the current
19:         * thread. To get around of this, we can use a simple trick. We call the 
20:         * main method of {@link NewsSubscriber} from a different thread and interrupt 
21:         * it immediately. Then we can send messages from the main thread, that are 
22:         * received synchronously by {@link NewsSubscriber}.
23:         * Please note, that the JMS test framework is not thread safe at the moment
24:         * and should not be accessed by multiple threads concurrently. In this test
25:         * the <code>TestNewsSubscriberThread</code> and the main thread do not run
26:         * concurrently, so it's ok.
27:         */
28:        public class NewsSubscriberTest extends JMSTestCaseAdapter {
29:            private EJBTestModule ejbModule;
30:
31:            protected void setUp() throws Exception {
32:                super .setUp();
33:                ejbModule = createEJBTestModule();
34:                ejbModule.bindToContext("ConnectionFactory",
35:                        getJMSMockObjectFactory()
36:                                .getMockTopicConnectionFactory());
37:                Topic topic = getDestinationManager().createTopic("topic");
38:                ejbModule.bindToContext("topic/newsTopic", topic);
39:            }
40:
41:            public void testMain() throws Exception {
42:                callMain("Java");
43:                TopicPublisher publisher = createTestPublisher();
44:                MockTextMessage message1 = new MockTextMessage("message1");
45:                message1.setStringProperty("subject", "C++");
46:                MockTextMessage message2 = new MockTextMessage("message2");
47:                message2.setStringProperty("subject", "Java");
48:                publisher.publish(message1);
49:                publisher.publish(message2);
50:                verifyNumberOfReceivedTopicMessages("topic", 2);
51:                verifyNumberOfCurrentTopicMessages("topic", 1);
52:            }
53:
54:            private TopicPublisher createTestPublisher() throws JMSException {
55:                TopicConnection connection = getJMSMockObjectFactory()
56:                        .getMockTopicConnectionFactory()
57:                        .createTopicConnection();
58:                TopicSession session = connection.createTopicSession(false,
59:                        Session.AUTO_ACKNOWLEDGE);
60:                return session.createPublisher(getDestinationManager()
61:                        .getTopic("topic"));
62:            }
63:
64:            private void callMain(String subject) throws Exception {
65:                String contextFactory = "org.mockejb.jndi.MockContextFactory";
66:                String providerURL = "org.mockejb.jndi";
67:                TestNewsSubscriberThread thread = new TestNewsSubscriberThread(
68:                        contextFactory, providerURL, subject);
69:                thread.start();
70:                thread.interrupt();
71:                thread.join();
72:            }
73:
74:            private class TestNewsSubscriberThread extends Thread {
75:                private String contextFactory;
76:                private String providerURL;
77:                private String subject;
78:
79:                public TestNewsSubscriberThread(String contextFactory,
80:                        String providerURL, String subject) {
81:                    this .contextFactory = contextFactory;
82:                    this .providerURL = providerURL;
83:                    this .subject = subject;
84:                }
85:
86:                public void run() {
87:                    try {
88:                        NewsSubscriber.main(new String[] { contextFactory,
89:                                providerURL, subject });
90:                    } catch (RuntimeException exc) {
91:
92:                    }
93:                }
94:            }
95:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.