1 6 7 package com.hp.hpl.jena.db.test; 8 9 29 30 import com.hp.hpl.jena.rdf.model.*; 31 import com.hp.hpl.jena.db.*; 32 import com.hp.hpl.jena.db.impl.*; 33 import com.hp.hpl.jena.regression.*; 34 import com.hp.hpl.jena.shared.*; 35 36 import junit.framework.*; 37 38 39 public class TestCompatability extends TestCase { 40 41 public TestCompatability( String name ) 42 { super( name ); } 43 44 protected void setUp() throws java.lang.Exception { 45 } 46 47 protected void tearDown() throws java.lang.Exception { 48 } 49 50 51 public static TestSuite suite() { 52 ConfigTestCaseRDB config = new ConfigTestCaseRDB(TestPackage.M_DB_URL, TestPackage.M_DB_USER, TestPackage.M_DB_PASSWD, "Generic", TestPackage.M_DB ); 53 54 TestSuite suite = new TestSuite(); 55 suite.addTest(new TestCaseRDB("test0", config)); 56 suite.addTest(new TestCaseRDB("test1", config)); 57 suite.addTest(new TestCaseRDB("test2", config)); 58 suite.addTest(new TestCaseRDB("test3", config)); 59 suite.addTest(new TestCaseRDB("test4", config)); 60 suite.addTest(new TestCaseRDB("test5", config)); 61 suite.addTest(new TestCaseRDB("test6", config)); 62 suite.addTest(new TestCaseRDB("test7", config)); 63 suite.addTest(new TestCaseRDB("test8", config)); 64 suite.addTest(new TestCaseRDB("test9", config)); 65 suite.addTest(new TestCaseRDB("test10", config)); 66 suite.addTest(new TestCaseRDB("test11", config)); 67 suite.addTest(new TestCaseRDB("test12", config)); 68 suite.addTest(new TestCaseRDB("test13", config)); 69 suite.addTest(new TestCaseRDB("test14", config)); 70 suite.addTest(new TestCaseRDB("test15", config)); 71 suite.addTest(new TestCaseRDB("test16", config)); 72 suite.addTest(new TestCaseRDB("test17", config)); 73 suite.addTest(new TestCaseRDB("test18", config)); 74 suite.addTest(new TestCaseRDB("test19", config)); 75 76 return suite; 77 78 } 79 80 81 82 83 84 protected static class ConfigTestCaseRDB { 85 86 87 String m_baseuri; 88 89 90 String m_user; 91 92 93 String m_password; 94 95 96 String m_layout; 97 98 99 String m_databaseType; 100 101 102 103 boolean supportsMultipleModels; 104 105 106 107 boolean supportsJenaReification; 108 109 110 111 boolean noReformat; 112 113 114 115 DBConnection m_dbconn = null; 116 117 122 123 ConfigTestCaseRDB(String baseuri, String user, String password, 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); } catch (Exception e) { 134 throw new JenaException("Unable to instantiate driver: " + TestPackage.M_DBDRIVER_CLASS); 135 } 136 137 try { 138 DBConnection temp = new DBConnection(baseuri, user, password); 139 IRDBDriver driver = temp.getDriver(layout, database); 140 supportsMultipleModels = driver.supportsMultipleModels(); 141 supportsJenaReification = driver.supportsJenaReification(); 142 } catch (RDFRDBException e) { 143 144 supportsMultipleModels = false; 145 } 146 noReformat = false; 147 } 148 149 154 155 ConfigTestCaseRDB( 156 String baseuri, 157 String user, 158 String password, 159 String layout, 160 String database, 161 boolean noReformat) { 162 this(baseuri, user, password, layout, database); 163 this.noReformat = noReformat; 164 } 165 166 167 168 ModelRDB createModel(String name) { 169 if (supportsMultipleModels) { 170 if (m_dbconn == null) { 171 m_dbconn = new DBConnection(m_baseuri, m_user, m_password, m_databaseType); 172 if (!m_dbconn.isFormatOK()) { 173 IRDBDriver driver = m_dbconn.getDriver(m_layout, m_databaseType); 174 driver.formatDB(); 175 } 176 } 177 if ( m_dbconn.containsModel(name) ) 178 ModelRDB.deleteModel(m_dbconn,name); 179 return ModelRDB.createModel(m_dbconn, name); 180 } else { 181 DBConnection dbcon = new DBConnection(m_baseuri + name, m_user, m_password); 182 if ( m_dbconn.containsDefaultModel() ) 183 try {m_dbconn.cleanDB(); } catch (Exception e) {}; 184 return ModelRDB.create(dbcon, m_layout, m_databaseType); 185 } 186 } 187 } 189 190 191 protected static class TestCaseRDB extends TestCaseBasic { 192 193 ConfigTestCaseRDB m_config; 194 195 public TestCaseRDB(String name, ConfigTestCaseRDB config) { 196 super(name); 197 m_config = config; 198 } 199 200 public void setUp() { 202 m1 = m_config.createModel("jr1"); 203 m2 = m_config.createModel("jr2"); 204 m3 = m_config.createModel("jr3"); 205 m4 = m_config.createModel("jr4"); 206 } 207 208 public void tearDown() { 209 if (m_config.supportsMultipleModels && !m_config.noReformat) { 210 cleanModel((ModelRDB) m1); 212 m2.close(); 213 m3.close(); 214 m4.close(); 215 217 try { 218 m_config.m_dbconn.close(); 219 } catch (java.sql.SQLException e) { 220 System.out.println("Problem during db clean up in regression test"); 221 } 222 m_config.m_dbconn = null; 223 } else { 224 cleanModel((ModelRDB) m1); 225 cleanModel((ModelRDB) m2); 226 cleanModel((ModelRDB) m3); 227 cleanModel((ModelRDB) m4); 228 } 229 } 230 231 private void cleanModel(ModelRDB m) { 232 try { 233 if (m_config.noReformat) { 234 for (StmtIterator i = m.listStatements(); i.hasNext();) { 237 i.next(); 238 i.remove(); 239 } 240 } else { 241 m.getConnection().cleanDB(); 248 m.close(); 249 } 251 } catch (Exception e) { 252 assertTrue("Problem clearning up regression databases: " + e, false); 253 } 254 } 255 } } 257 258 287 | Popular Tags |