Source Code Cross Referenced for MessageManagerFactoryTest.java in  » Net » Coadunation_1.0.1 » com » rift » coad » daemon » messageservice » message » 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 » Net » Coadunation_1.0.1 » com.rift.coad.daemon.messageservice.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MessageManagerFactoryTest.java
003:         * JUnit based test
004:         *
005:         * Created on January 15, 2007, 9:31 PM
006:         */
007:
008:        package com.rift.coad.daemon.messageservice.message;
009:
010:        // java imports
011:        import com.rift.coad.lib.thread.ThreadGroupManager;
012:        import com.rift.coad.util.change.ChangeLog;
013:        import javax.naming.InitialContext;
014:        import javax.naming.Context;
015:        import java.sql.PreparedStatement;
016:        import java.sql.ResultSet;
017:        import java.sql.Statement;
018:        import javax.sql.DataSource;
019:        import java.util.Set;
020:        import java.util.HashSet;
021:        import javax.transaction.UserTransaction;
022:        import java.sql.Timestamp;
023:        import java.util.ArrayList;
024:        import java.util.Date;
025:        import java.util.Enumeration;
026:        import java.util.HashSet;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Set;
030:        import javax.transaction.xa.XAException;
031:        import javax.transaction.xa.XAResource;
032:        import javax.transaction.xa.Xid;
033:        import org.hibernate.*;
034:        import org.hibernate.cfg.*;
035:        import org.apache.log4j.Logger;
036:        import org.apache.log4j.BasicConfigurator;
037:
038:        // junit imports
039:        import junit.framework.*;
040:
041:        // object web imports
042:        import org.objectweb.jotm.Jotm;
043:
044:        // coadunation imports
045:        import com.rift.coad.lib.naming.NamingDirector;
046:        import com.rift.coad.lib.naming.ContextManager;
047:        import com.rift.coad.lib.db.DBSourceManager;
048:        import com.rift.coad.lib.common.ObjectSerializer;
049:        import com.rift.coad.lib.interceptor.InterceptorFactory;
050:        import com.rift.coad.lib.security.RoleManager;
051:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
052:        import com.rift.coad.lib.security.ThreadPermissionSession;
053:        import com.rift.coad.lib.security.UserSession;
054:        import com.rift.coad.lib.security.user.UserSessionManager;
055:        import com.rift.coad.lib.security.user.UserStoreManager;
056:        import com.rift.coad.lib.security.SessionManager;
057:        import com.rift.coad.lib.security.login.LoginManager;
058:        import com.rift.coad.lib.thread.CoadunationThreadGroup;
059:        import com.rift.coad.lib.transaction.TransactionDirector;
060:        import com.rift.coad.daemon.messageservice.Message;
061:        import com.rift.coad.daemon.messageservice.RPCMessage;
062:        import com.rift.coad.daemon.messageservice.TextMessage;
063:        import com.rift.coad.daemon.messageservice.MessageManager;
064:        import com.rift.coad.daemon.messageservice.MessageServiceException;
065:        import com.rift.coad.daemon.messageservice.MessageServiceManager;
066:        import com.rift.coad.daemon.messageservice.db.*;
067:        import com.rift.coad.daemon.messageservice.message.MessageImpl;
068:        import com.rift.coad.daemon.messageservice.message.RPCMessageImpl;
069:        import com.rift.coad.daemon.messageservice.message.TextMessageImpl;
070:        import com.rift.coad.hibernate.util.HibernateUtil;
071:        import com.rift.coad.util.lock.ObjectLockFactory;
072:        import com.rift.coad.util.transaction.TransactionManager;
073:
074:        /**
075:         *
076:         * @author mincemeat
077:         */
078:        public class MessageManagerFactoryTest extends TestCase {
079:
080:            public MessageManagerFactoryTest(String testName) {
081:                super (testName);
082:            }
083:
084:            protected void setUp() throws Exception {
085:            }
086:
087:            protected void tearDown() throws Exception {
088:            }
089:
090:            /**
091:             * Test of class com.rift.coad.daemon.messageservice.message.MessageManagerFactory.
092:             */
093:            public void testMessageManagerFactory() throws Exception {
094:                System.out.println("MessageManagerFactory");
095:
096:                Thread.currentThread().setContextClassLoader(
097:                        this .getClass().getClassLoader());
098:
099:                // init the session information
100:                ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
101:                SessionManager.init(permissions);
102:                UserStoreManager userStoreManager = new UserStoreManager();
103:                UserSessionManager sessionManager = new UserSessionManager(
104:                        permissions, userStoreManager);
105:                LoginManager.init(sessionManager, userStoreManager);
106:                // instanciate the thread manager
107:                CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(
108:                        sessionManager, userStoreManager);
109:
110:                // add a user to the session for the current thread
111:                RoleManager.getInstance();
112:
113:                InterceptorFactory.init(permissions, sessionManager,
114:                        userStoreManager);
115:
116:                // add a new user object and add to the permission
117:                Set set = new HashSet();
118:                set.add("test");
119:                UserSession user = new UserSession("test1", set);
120:                permissions.putSession(
121:                        new Long(Thread.currentThread().getId()),
122:                        new ThreadPermissionSession(new Long(Thread
123:                                .currentThread().getId()), user));
124:
125:                // instanciate the thread manager
126:                ThreadGroupManager.getInstance().initThreadGroup(threadGroup);
127:
128:                // init the naming director
129:                NamingDirector.init(threadGroup);
130:
131:                // instanciate the transaction director
132:                TransactionDirector transactionDirector = TransactionDirector
133:                        .init();
134:
135:                // init the database source
136:                DBSourceManager.init();
137:                ObjectLockFactory.init();
138:                TransactionManager.init();
139:                ChangeLog.init(MessageServiceManager.class);
140:                ChangeLog.getInstance().start();
141:
142:                Context context = new InitialContext();
143:
144:                List principals = new ArrayList(set);
145:                Date currentTime = new Date();
146:                TextMessageImpl textMessage = new TextMessageImpl("test",
147:                        "test", "test", principals, Message.UNDELIVERED);
148:                textMessage.setFrom("test");
149:                textMessage.setTextBody("test text");
150:                textMessage.setStringProperty("TESTString", "TESTvalue");
151:                textMessage.setBooleanProperty("TESTBoolean", true);
152:                textMessage.setByteProperty("TESTByte", (byte) 1);
153:                textMessage.setCorrelationId("TESTCorrelationId");
154:                textMessage.setDoubleProperty("TESTDouble", 1.1);
155:                textMessage.setFloatProperty("TESTFloat", (float) 2.2);
156:                textMessage.setFrom("test@test.com");
157:                textMessage.setIntProperty("TESTInt", 100);
158:                textMessage.setLongProperty("TESTLong", (long) 2000);
159:                textMessage.setTargetNamedQueue("QUEUEName");
160:                textMessage.setReplyNamedQueue("ReplyQUEUEName");
161:                textMessage.setNextProcessDate(currentTime);
162:                textMessage.setObjectProperty("TESTObject",
163:                        "This is a test obj");
164:                textMessage.setPriority(1000);
165:                textMessage.setProcessedDate(currentTime);
166:                textMessage.setReply(true);
167:                textMessage.setServices(new String[] { "test1", "test2",
168:                        "test3" });
169:                textMessage.setTarget("target");
170:                UserTransaction ut = (UserTransaction) context
171:                        .lookup("java:comp/UserTransaction");
172:
173:                ut.begin();
174:
175:                MessageManager instance = MessageManagerFactory.getInstance()
176:                        .getMessageManager(textMessage);
177:
178:                ut.commit();
179:
180:                Thread.sleep(30000);
181:
182:                ut.begin();
183:
184:                MessageManager instance2 = MessageManagerFactory.getInstance()
185:                        .getMessageManager("test");
186:
187:                ut.commit();
188:
189:                assertEquals(instance2.getID(), instance.getID());
190:
191:                ut.begin();
192:
193:                instance2.remove();
194:
195:                ut.commit();
196:
197:                Thread.sleep(30000);
198:
199:                ChangeLog.getInstance().terminate();
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.