Source Code Cross Referenced for DatabaseModuleSimpleTransactionManagerTest.java in  » Testing » unitils » org » unitils » database » 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 » unitils » org.unitils.database 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007,  Unitils.org
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.unitils.database;
017:
018:        import static org.easymock.EasyMock.*;
019:        import org.junit.After;
020:        import static org.junit.Assert.assertNotSame;
021:        import static org.junit.Assert.assertSame;
022:        import org.junit.Before;
023:        import org.junit.Test;
024:        import org.unitils.core.Unitils;
025:        import org.unitils.database.annotations.Transactional;
026:        import static org.unitils.database.util.TransactionMode.*;
027:
028:        import javax.sql.DataSource;
029:        import java.sql.Connection;
030:
031:        /**
032:         * Tests verifying whether the SimpleTransactionManager functions correctly.
033:         *
034:         * @author Filip Neven
035:         * @author Tim Ducheyne
036:         */
037:        public class DatabaseModuleSimpleTransactionManagerTest extends
038:                DatabaseModuleTransactionalTest {
039:
040:            private DatabaseModule databaseModule;
041:
042:            private TransactionsDisabledTest transactionsDisabledTest;
043:
044:            private RollbackTest rollbackTest;
045:
046:            private CommitTest commitTest;
047:
048:            /**
049:             * Initializes the test fixture.
050:             */
051:            @Before
052:            public void setUp() throws Exception {
053:                configuration.setProperty("unitils.module.spring.enabled",
054:                        "false");
055:                Unitils.getInstance().init(configuration);
056:                databaseModule = getDatabaseModule();
057:
058:                transactionsDisabledTest = new TransactionsDisabledTest();
059:                rollbackTest = new RollbackTest();
060:                commitTest = new CommitTest();
061:            }
062:
063:            /**
064:             * Cleans up test by resetting the unitils instance.
065:             */
066:            @After
067:            public void tearDown() throws Exception {
068:                Unitils.getInstance().init();
069:            }
070:
071:            /**
072:             * Tests for a test with transactions disabled
073:             */
074:            @Test
075:            public void testWithTransactionsDisabled() throws Exception {
076:                expect(mockConnection1.getAutoCommit()).andReturn(true);
077:                expect(mockConnection2.getAutoCommit()).andReturn(true);
078:                mockConnection1.close();
079:                mockConnection2.close();
080:                replay(mockConnection1, mockConnection2);
081:
082:                databaseModule.startTransaction(transactionsDisabledTest);
083:                Connection conn1 = databaseModule.getDataSource()
084:                        .getConnection();
085:                conn1.close();
086:                Connection conn2 = databaseModule.getDataSource()
087:                        .getConnection();
088:                conn2.close();
089:                assertNotSame(conn1, conn2);
090:                databaseModule.endTransaction(transactionsDisabledTest);
091:
092:                verify(mockConnection1, mockConnection2);
093:            }
094:
095:            /**
096:             * Tests with a test with transaction rollback configured
097:             */
098:            @Test
099:            public void testRollback() throws Exception {
100:                expect(mockConnection1.getAutoCommit()).andReturn(true)
101:                        .andReturn(false).anyTimes();
102:                mockConnection1.setAutoCommit(false);
103:                mockConnection1.rollback();
104:                mockConnection1.close();
105:                replay(mockConnection1, mockConnection2);
106:
107:                DataSource dataSource = databaseModule.getDataSource();
108:                databaseModule.startTransaction(rollbackTest);
109:                Connection connection1 = dataSource.getConnection();
110:                connection1.close();
111:                Connection connection2 = dataSource.getConnection();
112:                connection2.close();
113:                assertSame(connection1, connection2);
114:                databaseModule.endTransaction(rollbackTest);
115:
116:                verify(mockConnection1, mockConnection2);
117:            }
118:
119:            /**
120:             * Tests with a test with transaction commit configured
121:             */
122:            @Test
123:            public void testCommit() throws Exception {
124:                expect(mockConnection1.getAutoCommit()).andReturn(true)
125:                        .andReturn(false).anyTimes();
126:                mockConnection1.setAutoCommit(false);
127:                mockConnection1.commit();
128:                mockConnection1.close();
129:                replay(mockConnection1, mockConnection2);
130:
131:                DataSource dataSource = databaseModule.getDataSource();
132:                databaseModule.startTransaction(commitTest);
133:                Connection connection1 = dataSource.getConnection();
134:                connection1.close();
135:                Connection connection2 = dataSource.getConnection();
136:                connection2.close();
137:                assertSame(connection1, connection2);
138:                databaseModule.endTransaction(commitTest);
139:
140:                verify(mockConnection1, mockConnection2);
141:            }
142:
143:            /**
144:             * Class that plays the role of a unit test, with transactions disabled
145:             */
146:            @Transactional(DISABLED)
147:            public static class TransactionsDisabledTest {
148:
149:                public void test() {
150:                }
151:            }
152:
153:            /**
154:             * Class that plays the role of a unit test, with transaction rollback enabled (=default, so no
155:             *
156:             * @Transactional annotation required
157:             */
158:            @Transactional(ROLLBACK)
159:            public static class RollbackTest {
160:
161:                public void test() {
162:                }
163:            }
164:
165:            /**
166:             * Class that plays the role of a unit test, with transaction commit enabled
167:             */
168:            @Transactional(COMMIT)
169:            public static class CommitTest {
170:
171:                public void test() {
172:                }
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.