Source Code Cross Referenced for BaseSessionBeanFixture.java in  » Testing » Ejb3Unit » com » bm » testsuite » 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 » Ejb3Unit » com.bm.testsuite 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bm.testsuite;
002:
003:        import javax.persistence.EntityManager;
004:        import javax.persistence.EntityTransaction;
005:
006:        import com.bm.creators.SessionBeanFactory;
007:        import com.bm.introspectors.AbstractIntrospector;
008:        import com.bm.introspectors.SessionBeanIntrospector;
009:        import com.bm.jndi.Ejb3UnitJndiBinder;
010:        import com.bm.testsuite.dataloader.EntityInitialDataSet;
011:        import com.bm.testsuite.dataloader.InitialDataSet;
012:
013:        /**
014:         * This is the base class for all JUnit test - testing stateless/statefull
015:         * SessionBeans (EJB 3.0 Specification conform).
016:         * 
017:         * @author Daniel Wiese
018:         * @param <T> -
019:         *            the type of the session bean to test
020:         * @since 16.10.2005
021:         */
022:        public abstract class BaseSessionBeanFixture<T> extends BaseTest {
023:
024:            private final SessionBeanFactory<T> sbFactory;
025:
026:            private final Ejb3UnitJndiBinder jndiBinder;
027:
028:            private final Class<T> beanClass;
029:
030:            private T beanToTest = null;
031:
032:            private InitialDataSet[] initalDataSets = null;
033:
034:            /**
035:             * Constructor.
036:             * 
037:             * @param sessionBeanToTest -
038:             *            the class of the session bean to test
039:             * @param usedEntityBeans -
040:             *            the used entity bens
041:             */
042:            public BaseSessionBeanFixture(Class<T> sessionBeanToTest,
043:                    Class[] usedEntityBeans) {
044:                super ();
045:                AbstractIntrospector<T> intro = new SessionBeanIntrospector<T>(
046:                        sessionBeanToTest);
047:                this .sbFactory = new SessionBeanFactory<T>(intro,
048:                        usedEntityBeans);
049:                this .beanClass = sessionBeanToTest;
050:                this .jndiBinder = new Ejb3UnitJndiBinder(usedEntityBeans);
051:
052:            }
053:
054:            /**
055:             * Constructor.
056:             * 
057:             * @param sessionBeanToTest -
058:             *            the class of the session bean to test
059:             * @param usedEntityBeans -
060:             *            the used entity beans
061:             * @param initialData -
062:             *            the inital data to create in the db
063:             */
064:            public BaseSessionBeanFixture(Class<T> sessionBeanToTest,
065:                    Class[] usedEntityBeans, InitialDataSet... initialData) {
066:                this (sessionBeanToTest, usedEntityBeans);
067:                this .initalDataSets = initialData;
068:            }
069:
070:            /**
071:             * Protected Constructor> possible to pass another introspector
072:             * 
073:             * @param sessionBeanToTest -
074:             *            the class of the session bean to test
075:             * @param intro -
076:             *            the introspector
077:             * @param usedEntityBeans -
078:             *            the used entity bens
079:             * @param initialData -
080:             *            the inital data to create in the db
081:             */
082:            protected BaseSessionBeanFixture(Class<T> sessionBeanToTest,
083:                    AbstractIntrospector<T> intro, Class[] usedEntityBeans,
084:                    InitialDataSet... initialData) {
085:                super ();
086:                this .sbFactory = new SessionBeanFactory<T>(intro,
087:                        usedEntityBeans);
088:                this .beanClass = sessionBeanToTest;
089:                this .initalDataSets = initialData;
090:                this .jndiBinder = new Ejb3UnitJndiBinder(usedEntityBeans);
091:            }
092:
093:            /**
094:             * Sets a CSV inital data set to prepopylate the database with data.
095:             * 
096:             * @param initalDataSets
097:             *            the array of initial data sets
098:             */
099:            public void setInitalDataSets(InitialDataSet... initalDataSets) {
100:                this .initalDataSets = initalDataSets;
101:            }
102:
103:            /**
104:             * @author Daniel Wiese
105:             * @since 16.10.2005
106:             * @see junit.framework.TestCase#setUp()
107:             */
108:            @Override
109:            protected void setUp() throws Exception {
110:                super .setUp();
111:                this .jndiBinder.bind();
112:                // the creation process is expensive, do it once per test
113:                if (this .beanToTest == null) {
114:                    this .beanToTest = this .sbFactory
115:                            .createSessionBean(this .beanClass);
116:                }
117:
118:                if (this .initalDataSets != null) {
119:                    EntityManager em = this .getEntityManager();
120:
121:                    for (InitialDataSet current : this .initalDataSets) {
122:                        // insert entity manager
123:                        if (current instanceof  EntityInitialDataSet) {
124:                            EntityInitialDataSet curentEntDs = (EntityInitialDataSet) current;
125:                            curentEntDs.setEntityManager(em);
126:                            EntityTransaction tx = em.getTransaction();
127:                            tx.begin();
128:                            current.create();
129:                            tx.commit();
130:                        } else {
131:                            current.create();
132:                        }
133:                    }
134:                }
135:            }
136:
137:            /**
138:             * @author Daniel Wiese
139:             * @since 16.10.2005
140:             * @see junit.framework.TestCase#tearDown()
141:             */
142:            @Override
143:            protected void tearDown() throws Exception {
144:                super .tearDown();
145:
146:                // delete all objects (faster than shutdown and restart everything)
147:                final EntityManager em = this .getEntityManager();
148:                if (this .initalDataSets != null) {
149:                    // tear down in reverse order, otherwise foreign key constraints may be violated 
150:                    for (int i = this .initalDataSets.length - 1; i >= 0; i--) {
151:                        this .initalDataSets[i].cleanup(em);
152:                    }
153:                }
154:
155:            }
156:
157:            /**
158:             * Returns the beanClass.
159:             * 
160:             * @return Returns the beanClass.
161:             */
162:            public Class<T> getBeanClass() {
163:                return this .beanClass;
164:            }
165:
166:            /**
167:             * Returns the beanToTest.
168:             * 
169:             * @return Returns the beanToTest.
170:             */
171:            public T getBeanToTest() {
172:                return this .beanToTest;
173:            }
174:
175:            /**
176:             * Returns a isntance of a EntityManager.
177:             * 
178:             * @author Daniel Wiese
179:             * @since 12.11.2005
180:             * @return - a instance of an entity manager
181:             */
182:            public EntityManager getEntityManager() {
183:                return this .sbFactory.getEntityManager();
184:            }
185:
186:            /**
187:             * Returns the sbFactory.
188:             * 
189:             * @return Returns the sbFactory.
190:             */
191:            public SessionBeanFactory<T> getSbFactory() {
192:                return this.sbFactory;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.