Source Code Cross Referenced for MigrationTestCase.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » test » migration » 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 » Portal » jboss portal 2.6.4 » org.jboss.portal.test.migration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.test.migration;
023:
024:        import junit.framework.TestCase;
025:        import org.dbunit.database.DatabaseConfig;
026:        import org.dbunit.database.DatabaseConnection;
027:        import org.dbunit.database.IDatabaseConnection;
028:        import org.dbunit.dataset.IDataSet;
029:        import org.hibernate.Session;
030:        import org.hibernate.SessionFactory;
031:        import org.hibernate.Transaction;
032:        import org.hibernate.cfg.Configuration;
033:        import org.hibernate.tool.hbm2ddl.SchemaExport;
034:
035:        import java.sql.Connection;
036:        import java.sql.DriverManager;
037:
038:        /**
039:         * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
040:         * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
041:         * @version $Revision: 8784 $
042:         */
043:        public abstract class MigrationTestCase extends TestCase {
044:            public MigrationTestCase(String name) {
045:                super (name);
046:            }
047:
048:            protected SessionFactory fromFactory;
049:            protected SessionFactory toFactory;
050:            protected Session fromSession;
051:            protected Session toSession;
052:            protected Transaction fromTx;
053:            protected Transaction toTx;
054:
055:            //dbunit stuff
056:            //Connections to databases to easily inject data
057:            protected IDatabaseConnection fromConnection;
058:            protected IDatabaseConnection toConnection;
059:
060:            //Datasets to check if data is valid after migrations
061:            protected IDataSet fromRefDataSet;
062:            protected IDataSet toRefDataSet;
063:
064:            String cfgPath;
065:
066:            public void setUp() throws Exception {
067:                cfgPath = System.getProperty("build.resources");
068:                //Set up hibernate configuration
069:                /*Configuration fromCfg = new Configuration();
070:                Configuration toCfg = new Configuration();
071:                 */
072:                Configuration fromCfg = getFromTestConfiguration();
073:                Configuration toCfg = getToTestConfiguration();
074:
075:                //hibernate config files - we get files from abstract methods implemented in subclass
076:                /*fromCfg.configure(getFromConfigurationFile());
077:                toCfg.configure(getToConfigurationFile());
078:
079:                //hibernate mapping files
080:                fromCfg.addFile(getFromMappingFile());
081:                toCfg.addFile(getToMappingFile());*/
082:
083:                //set system properties to pass test cfg files to Migrator
084:                /*System.setProperty("org.jboss.portal.migration.schema20.cfg", cfgPath + "/test/migration/schema20/hibernate.cfg.xml");
085:                System.setProperty("org.jboss.portal.migration.schema22.cfg", cfgPath + "/test/migration/schema22/hibernate.cfg.xml");
086:                System.setProperty("org.jboss.portal.migration.schema20.mapping", cfgPath + "/migration/schema20/domain.hbm.xml");
087:                System.setProperty("org.jboss.portal.migration.schema22.mapping", cfgPath + "/migration/schema22/domain.hbm.xml");*/
088:
089:                //hibernate properties
090:                /*Properties fromProps = new Properties();
091:                fromProps.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
092:                fromProps.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
093:                fromProps.setProperty("hibernate.connection.url", "jdbc:hsqldb:TestMigrationFromDB");
094:                fromProps.setProperty("hibernate.connection.username", "sa");
095:                fromProps.setProperty("hibernate.connection.password", "");
096:                fromProps.setProperty("hibernate.connection.pool_size", "1");
097:                fromProps.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
098:                fromCfg.setProperties(fromProps);
099:
100:                Properties toProps = new Properties();
101:                toProps.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
102:                toProps.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
103:                toProps.setProperty("hibernate.connection.url", "jdbc:hsqldb:TestMigrationToDB");
104:                toProps.setProperty("hibernate.connection.username", "sa");
105:                toProps.setProperty("hibernate.connection.password", "");
106:                toProps.setProperty("hibernate.connection.pool_size", "1");
107:                toProps.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
108:                toCfg.setProperties(toProps);*/
109:
110:                //DBunit connetion setup
111:                Class driverClass = Class.forName(fromCfg
112:                        .getProperty("hibernate.connection.driver_class"));
113:                String dbURL = fromCfg.getProperty("hibernate.connection.url");
114:                String dbUser = fromCfg
115:                        .getProperty("hibernate.connection.username");
116:                String dbPassword = fromCfg
117:                        .getProperty("hibernate.connection.password");
118:
119:                Connection jdbcConnection = DriverManager.getConnection(dbURL,
120:                        dbUser, dbPassword);
121:                /*Connection jdbcConnection = DriverManager.getConnection(
122:                   "jdbc:hsqldb:TestMigrationFromDB",
123:                   "sa",
124:                   "");*/
125:
126:                fromConnection = new DatabaseConnection(jdbcConnection);
127:
128:                dbURL = toCfg.getProperty("hibernate.connection.url");
129:                dbUser = toCfg.getProperty("hibernate.connection.username");
130:                dbPassword = toCfg.getProperty("hibernate.connection.password");
131:                jdbcConnection = DriverManager.getConnection(dbURL, dbUser,
132:                        dbPassword);
133:
134:                toConnection = new DatabaseConnection(jdbcConnection);
135:
136:                //small hack for dbunit boolean bug
137:                DatabaseConfig config = fromConnection.getConfig();
138:                config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
139:                        new HsqlDataTypeFactory());
140:                config = toConnection.getConfig();
141:                config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
142:                        new HsqlDataTypeFactory());
143:
144:                //create clear db schema for init
145:                SchemaExport export = new SchemaExport(fromCfg);
146:                export.create(false, true);
147:
148:                export = new SchemaExport(toCfg);
149:                export.create(false, true);
150:
151:                //Set up SessionFactories
152:                fromFactory = fromCfg.buildSessionFactory();
153:                toFactory = toCfg.buildSessionFactory();
154:
155:                // Set up session and tx
156:                fromSession = fromFactory.openSession();
157:                fromTx = fromSession.beginTransaction();
158:
159:                toSession = toFactory.openSession();
160:                toTx = toSession.beginTransaction();
161:
162:                //DBunit reference data sets
163:                fromRefDataSet = Utils.getDataSet(getFromRefDatasetFile());
164:
165:                // Populate
166:                populate();
167:                nextFromSession();
168:                nextToSession();
169:
170:            }
171:
172:            protected void tearDown() throws Exception {
173:                fromTx.commit();
174:                fromSession.close();
175:                fromFactory.close();
176:                toTx.commit();
177:                toSession.close();
178:                toFactory.close();
179:
180:                //migrator.disconnect();
181:            }
182:
183:            protected void nextFromSession() throws Exception {
184:                fromTx.commit();
185:                fromSession.close();
186:                fromSession = fromFactory.openSession();
187:                fromTx = fromSession.beginTransaction();
188:            }
189:
190:            protected void nextToSession() throws Exception {
191:                toTx.commit();
192:                toSession.close();
193:                toSession = toFactory.openSession();
194:                toTx = toSession.beginTransaction();
195:            }
196:
197:            protected void populate() throws Exception {
198:
199:            }
200:
201:            /*protected abstract File getFromMappingFile();
202:
203:            protected abstract File getToMappingFile();
204:
205:            protected abstract File getFromConfigurationFile();
206:
207:            protected abstract File getToConfigurationFile();*/
208:
209:            protected abstract Configuration getFromTestConfiguration();
210:
211:            protected abstract Configuration getToTestConfiguration();
212:
213:            protected abstract String getFromRefDatasetFile();
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.