Source Code Cross Referenced for TestCompatability.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » db » test » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.db.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003:          [See end of file]
004:          $Id: TestCompatability.java,v 1.10 2008/01/02 12:08:14 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.db.test;
008:
009:        /**
010:         * 
011:         * This tests basic open/create operations on the modelRDB.
012:         * 
013:         * To run, you must have a mySQL database operational on
014:         * localhost with a database name of "test" and allow use
015:         * by a user named "test" with an empty password.
016:         * 
017:         * NOTE - this will generate deprecated API warnings when compiled -
018:         * this is deliberate - it is designed to test the deprecated APIs
019:         * to make sure they still work.
020:         * 
021:         * (copied from the Jena 1 RDB tests written by der).
022:         * 
023:         * The only code changes from Jena 1 ModelRDB operations are the 
024:         * in the cleanup code (it was calling getStore()).
025:         *
026:         * @author csayers
027:         * @version $Revision: 1.10 $
028:         */
029:
030:        import com.hp.hpl.jena.rdf.model.*;
031:        import com.hp.hpl.jena.db.*;
032:        import com.hp.hpl.jena.db.impl.*;
033:        import com.hp.hpl.jena.regression.*;
034:        import com.hp.hpl.jena.shared.*;
035:
036:        import junit.framework.*;
037:
038:        public class TestCompatability extends TestCase {
039:
040:            public TestCompatability(String name) {
041:                super (name);
042:            }
043:
044:            protected void setUp() throws java.lang.Exception {
045:            }
046:
047:            protected void tearDown() throws java.lang.Exception {
048:            }
049:
050:            public static TestSuite suite() {
051:                ConfigTestCaseRDB config = new ConfigTestCaseRDB(
052:                        TestPackage.M_DB_URL, TestPackage.M_DB_USER,
053:                        TestPackage.M_DB_PASSWD, "Generic", TestPackage.M_DB);
054:
055:                TestSuite suite = new TestSuite();
056:                suite.addTest(new TestCaseRDB("test0", config));
057:                suite.addTest(new TestCaseRDB("test1", config));
058:                suite.addTest(new TestCaseRDB("test2", config));
059:                suite.addTest(new TestCaseRDB("test3", config));
060:                suite.addTest(new TestCaseRDB("test4", config));
061:                suite.addTest(new TestCaseRDB("test5", config));
062:                suite.addTest(new TestCaseRDB("test6", config));
063:                suite.addTest(new TestCaseRDB("test7", config));
064:                suite.addTest(new TestCaseRDB("test8", config));
065:                suite.addTest(new TestCaseRDB("test9", config));
066:                suite.addTest(new TestCaseRDB("test10", config));
067:                suite.addTest(new TestCaseRDB("test11", config));
068:                suite.addTest(new TestCaseRDB("test12", config));
069:                suite.addTest(new TestCaseRDB("test13", config));
070:                suite.addTest(new TestCaseRDB("test14", config));
071:                suite.addTest(new TestCaseRDB("test15", config));
072:                suite.addTest(new TestCaseRDB("test16", config));
073:                suite.addTest(new TestCaseRDB("test17", config));
074:                suite.addTest(new TestCaseRDB("test18", config));
075:                suite.addTest(new TestCaseRDB("test19", config));
076:
077:                return suite;
078:
079:            }
080:
081:            /** Inner class which provides config information to TestCaseRDB */
082:
083:            protected static class ConfigTestCaseRDB {
084:
085:                /** base uri for the test databases*/
086:                String m_baseuri;
087:
088:                /** User name for access the databases */
089:                String m_user;
090:
091:                /** Password for this user */
092:                String m_password;
093:
094:                /** table layout version to test */
095:                String m_layout;
096:
097:                /** database type under test */
098:                String m_databaseType;
099:
100:                /** flag if this database config supports multiple models per database */
101:
102:                boolean supportsMultipleModels;
103:
104:                /** flag if this database config supports jena-style reification */
105:
106:                boolean supportsJenaReification;
107:
108:                /** flag if the tearDown code should leave the DB tables intact by doing a manual database cleanup */
109:
110:                boolean noReformat;
111:
112:                /** Database connection */
113:
114:                DBConnection m_dbconn = null;
115:
116:                /** Create config.		
117:                 *  Needs a base uri for the database, user name and login, format and database type to test.		
118:                 *  For databases which support multiple models given the whole database uri. For single model		
119:                 *  databases give a base uri to which the model names should be appended.	
120:                 */
121:
122:                ConfigTestCaseRDB(String baseuri, String user, String password,
123:                        String layout, String database) {
124:
125:                    m_baseuri = baseuri;
126:                    m_user = user;
127:                    m_password = password;
128:                    m_layout = layout;
129:                    m_databaseType = database;
130:
131:                    try {
132:                        Class.forName(TestPackage.M_DBDRIVER_CLASS); // ADDED  	
133:                    } catch (Exception e) {
134:                        throw new JenaException(
135:                                "Unable to instantiate  driver: "
136:                                        + TestPackage.M_DBDRIVER_CLASS);
137:                    }
138:
139:                    try {
140:                        DBConnection temp = new DBConnection(baseuri, user,
141:                                password);
142:                        IRDBDriver driver = temp.getDriver(layout, database);
143:                        supportsMultipleModels = driver
144:                                .supportsMultipleModels();
145:                        supportsJenaReification = driver
146:                                .supportsJenaReification();
147:                    } catch (RDFRDBException e) {
148:
149:                        supportsMultipleModels = false;
150:                    }
151:                    noReformat = false;
152:                }
153:
154:                /** Create config.		
155:                 *  Needs a base uri for the database, user name and login, format and database type to test.		
156:                 *  For databases which support multiple models given the whole database uri. For single model
157:                 *  databases give a base uri to which the model names should be appended.		
158:                 */
159:
160:                ConfigTestCaseRDB(String baseuri, String user, String password,
161:                        String layout, String database, boolean noReformat) {
162:                    this (baseuri, user, password, layout, database);
163:                    this .noReformat = noReformat;
164:                }
165:
166:                /** Create a model of the given name for this database config */
167:
168:                ModelRDB createModel(String name) {
169:                    if (supportsMultipleModels) {
170:                        if (m_dbconn == null) {
171:                            m_dbconn = new DBConnection(m_baseuri, m_user,
172:                                    m_password, m_databaseType);
173:                            if (!m_dbconn.isFormatOK()) {
174:                                IRDBDriver driver = m_dbconn.getDriver(
175:                                        m_layout, m_databaseType);
176:                                driver.formatDB();
177:                            }
178:                        }
179:                        if (m_dbconn.containsModel(name))
180:                            ModelRDB.deleteModel(m_dbconn, name);
181:                        return ModelRDB.createModel(m_dbconn, name);
182:                    } else {
183:                        DBConnection dbcon = new DBConnection(m_baseuri + name,
184:                                m_user, m_password);
185:                        if (m_dbconn.containsDefaultModel())
186:                            try {
187:                                m_dbconn.cleanDB();
188:                            } catch (Exception e) {
189:                            }
190:                        ;
191:                        return ModelRDB.create(dbcon, m_layout, m_databaseType);
192:                    }
193:                }
194:            } /// End of inner class ConfigTestCaseRDB
195:
196:            /** Adapt the overall jena test suite to use an RDB store */
197:
198:            protected static class TestCaseRDB extends TestCaseBasic {
199:
200:                ConfigTestCaseRDB m_config;
201:
202:                public TestCaseRDB(String name, ConfigTestCaseRDB config) {
203:                    super (name);
204:                    m_config = config;
205:                }
206:
207:                // Override set up to create RDB models instead of mem models
208:                public void setUp() {
209:                    m1 = m_config.createModel("jr1");
210:                    m2 = m_config.createModel("jr2");
211:                    m3 = m_config.createModel("jr3");
212:                    m4 = m_config.createModel("jr4");
213:                }
214:
215:                public void tearDown() {
216:                    if (m_config.supportsMultipleModels && !m_config.noReformat) {
217:                        // The brute force clean deletes the entire DB so only need to do it once
218:                        cleanModel((ModelRDB) m1);
219:                        m2.close();
220:                        m3.close();
221:                        m4.close();
222:                        // Close connection so next time it reformats the DB
223:
224:                        try {
225:                            m_config.m_dbconn.close();
226:                        } catch (java.sql.SQLException e) {
227:                            System.out
228:                                    .println("Problem during db clean up in regression test");
229:                        }
230:                        m_config.m_dbconn = null;
231:                    } else {
232:                        cleanModel((ModelRDB) m1);
233:                        cleanModel((ModelRDB) m2);
234:                        cleanModel((ModelRDB) m3);
235:                        cleanModel((ModelRDB) m4);
236:                    }
237:                }
238:
239:                private void cleanModel(ModelRDB m) {
240:                    try {
241:                        if (m_config.noReformat) {
242:                            // Do a slow, brute force manual clean to avoid the database getting reformatted
243:                            // This is needed to supporting checking of legacy formats
244:                            for (StmtIterator i = m.listStatements(); i
245:                                    .hasNext();) {
246:                                i.next();
247:                                i.remove();
248:                            }
249:                        } else {
250:                            // Turn off messages about deleting tables that aren't there any more.
251:                            //int l = Log.getInstance().getLevel();
252:                            //Log.getInstance().setLevel(Log.SEVERE);
253:                            //IRDBDriver driver = m.getStore().getDriver();
254:                            //driver.cleanDB();
255:                            //driver.close();
256:                            m.getConnection().cleanDB();
257:                            m.close();
258:                            //Log.getInstance().setLevel(l);
259:                        }
260:                    } catch (Exception e) {
261:                        assertTrue(
262:                                "Problem clearning up regression databases: "
263:                                        + e, false);
264:                    }
265:                }
266:            } // End of inner class TestCaseRDB
267:        }
268:
269:        /*
270:            (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
271:            All rights reserved.
272:        
273:            Redistribution and use in source and binary forms, with or without
274:            modification, are permitted provided that the following conditions
275:            are met:
276:        
277:            1. Redistributions of source code must retain the above copyright
278:               notice, this list of conditions and the following disclaimer.
279:        
280:            2. Redistributions in binary form must reproduce the above copyright
281:               notice, this list of conditions and the following disclaimer in the
282:               documentation and/or other materials provided with the distribution.
283:        
284:            3. The name of the author may not be used to endorse or promote products
285:               derived from this software without specific prior written permission.
286:        
287:            THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
288:            IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
289:            OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
290:            IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
291:            INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
292:            NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
293:            DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
294:            THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
295:            (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
296:            THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
297:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.