Source Code Cross Referenced for FactoryUnitTestCase.java in  » EJB-Server-JBoss-4.2.1 » ejb3 » org » jboss » ejb3 » test » standalone » flushmodenever » unit » 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 » EJB Server JBoss 4.2.1 » ejb3 » org.jboss.ejb3.test.standalone.flushmodenever.unit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.ejb3.test.standalone.flushmodenever.unit;
023:
024:        import java.util.Hashtable;
025:        import javax.naming.InitialContext;
026:        import javax.transaction.UserTransaction;
027:        import javax.persistence.EntityManagerFactory;
028:        import javax.persistence.EntityManager;
029:        import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
030:        import org.jboss.ejb3.test.standalone.flushmodenever.Entity1;
031:        import org.jboss.ejb3.test.standalone.flushmodenever.Entity2;
032:        import org.jboss.ejb3.test.standalone.flushmodenever.Session2;
033:        import org.jboss.ejb3.test.standalone.flushmodenever.Stateful1;
034:        import org.jboss.ejb3.test.standalone.flushmodenever.Util;
035:        import org.jboss.ejb3.test.standalone.flushmodenever.Session1;
036:        import junit.extensions.TestSetup;
037:        import junit.framework.Test;
038:        import junit.framework.TestCase;
039:        import junit.framework.TestSuite;
040:
041:        /**
042:         * Sample client for the jboss container.
043:         *
044:         * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
045:         * @version $Id: FactoryUnitTestCase.java 60233 2007-02-03 10:13:23Z wolfc $
046:         */
047:
048:        public class FactoryUnitTestCase extends TestCase {
049:
050:            public FactoryUnitTestCase(String name) {
051:
052:                super (name);
053:
054:            }
055:
056:            protected InitialContext getInitialContext() throws Exception {
057:                return new InitialContext(getInitialContextProperties());
058:            }
059:
060:            protected Hashtable getInitialContextProperties() {
061:                return EJB3StandaloneBootstrap.getInitialContextProperties();
062:            }
063:
064:            public void testUserTransaction() throws Exception {
065:                UserTransaction tx = (UserTransaction) getInitialContext()
066:                        .lookup("UserTransaction");
067:                EntityManagerFactory factory1 = (EntityManagerFactory) getInitialContext()
068:                        .lookup("java:/Manager1Factory");
069:
070:                tx.begin();
071:                Entity1 one = new Entity1();
072:                one.setString("UserTransaction");
073:                EntityManager em1 = factory1.createEntityManager();
074:                em1.persist(one);
075:                tx.commit();
076:                em1.close();
077:
078:                EntityManager em = factory1.createEntityManager();
079:                one = em.find(Entity1.class, one.getId());
080:                assertNotNull(one);
081:                em.close();
082:
083:            }
084:
085:            public void testMe() throws Exception {
086:                Session1 session1 = (Session1) this .getInitialContext().lookup(
087:                        "Session1Bean/remote");
088:                Session2 session2 = (Session2) this .getInitialContext().lookup(
089:                        "Session2Bean/remote");
090:
091:                int oneF = session1.create1FromFactory();
092:                int oneM = session1.create1FromManager();
093:                int twoF = session1.create2FromFactory();
094:                int twoM = session1.create2FromManager();
095:                session1.doUtil(new Util());
096:
097:                session2.find1FromFactory(oneF);
098:                assertNotNull(session2.find1FromManager(oneM));
099:                session2.find2FromFactory(twoF);
100:                assertNotNull(session2.find2FromManager(twoM));
101:                assertNotNull(session2.findUtil1FromManager(1));
102:                assertNotNull(session2.findUtil2FromManager(2));
103:
104:            }
105:
106:            public void testExtended() throws Exception {
107:                Stateful1 stateful1 = (Stateful1) this .getInitialContext()
108:                        .lookup("Stateful1Bean/remote");
109:                Session2 session2 = (Session2) this .getInitialContext().lookup(
110:                        "Session2Bean/remote");
111:
112:                int oneId = stateful1.create1();
113:                int twoId = stateful1.create2();
114:
115:                stateful1.update1();
116:                stateful1.update2();
117:
118:                {
119:                    Entity1 one = session2.find1FromManager(oneId);
120:                    assertEquals(one.getString(), "changed");
121:
122:                    Entity2 two = session2.find2FromManager(twoId);
123:                    assertEquals(two.getString(), "changed");
124:                }
125:
126:                stateful1.never();
127:
128:                {
129:                    Entity1 one = session2.find1FromManager(oneId);
130:                    assertEquals(one.getString(), "changed");
131:
132:                    Entity2 two = session2.find2FromManager(twoId);
133:                    assertEquals(two.getString(), "changed");
134:                }
135:
136:                stateful1.checkout();
137:
138:                {
139:                    Entity1 one = session2.find1FromManager(oneId);
140:                    assertEquals(one.getString(), "never");
141:
142:                    Entity2 two = session2.find2FromManager(twoId);
143:                    assertEquals(two.getString(), "never");
144:                }
145:            }
146:
147:            public void testExtended2() throws Exception {
148:                Stateful1 stateful1 = (Stateful1) this .getInitialContext()
149:                        .lookup("Stateful1Bean/remote");
150:                Session2 session2 = (Session2) this .getInitialContext().lookup(
151:                        "Session2Bean/remote");
152:
153:                int oneId = stateful1.create1();
154:                int twoId = stateful1.create2();
155:
156:                stateful1.update1();
157:                stateful1.update2();
158:
159:                Entity1 one = session2.find1FromManager(oneId);
160:                assertEquals(one.getString(), "changed");
161:
162:                Entity2 two = session2.find2FromManager(twoId);
163:                assertEquals(two.getString(), "changed");
164:                one.setString("never2");
165:                two.setString("never2");
166:                stateful1.never2(one, two);
167:
168:                {
169:                    Entity1 uno = session2.find1FromManager(oneId);
170:                    assertEquals(uno.getString(), "changed");
171:
172:                    Entity2 dos = session2.find2FromManager(twoId);
173:                    assertEquals(dos.getString(), "changed");
174:                }
175:
176:                stateful1.checkout();
177:
178:                {
179:                    Entity1 uno = session2.find1FromManager(oneId);
180:                    assertEquals(uno.getString(), "never2");
181:
182:                    Entity2 dos = session2.find2FromManager(twoId);
183:                    assertEquals(dos.getString(), "never2");
184:                }
185:            }
186:
187:            public static Test suite() throws Exception {
188:                TestSuite suite = new TestSuite();
189:                suite.addTestSuite(FactoryUnitTestCase.class);
190:
191:                // setup test so that embedded JBoss is started/stopped once for all tests here.
192:                TestSetup wrapper = new TestSetup(suite) {
193:                    protected void setUp() {
194:                        startupEmbeddedJboss();
195:                    }
196:
197:                    protected void tearDown() {
198:                        shutdownEmbeddedJboss();
199:                    }
200:                };
201:
202:                return wrapper;
203:            }
204:
205:            public static void startupEmbeddedJboss() {
206:                EJB3StandaloneBootstrap.boot(null);
207:                EJB3StandaloneBootstrap
208:                        .scanClasspath("flushmodenever-session1.jar, flushmodenever-session2.jar");
209:            }
210:
211:            public static void shutdownEmbeddedJboss() {
212:                EJB3StandaloneBootstrap.shutdown();
213:            }
214:
215:        }
w__w__w_.___j_a___va2_s.c__o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.