1 21 22 package org.opensubsystems; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import junit.extensions.TestSetup; 30 import junit.framework.Test; 31 import junit.framework.TestSuite; 32 33 import org.opensubsystems.core.persist.db.DatabaseTestSetup; 34 import org.opensubsystems.core.persist.db.DatabaseTestSuite; 35 import org.opensubsystems.core.util.Config; 36 import org.opensubsystems.core.util.Log; 37 38 47 public class GenericDatabaseTests 48 { 49 51 54 private static Logger s_logger = Log.getInstance(GenericDatabaseTests.class); 55 56 58 61 protected GenericDatabaseTests( 62 ) 63 { 64 super(); 65 } 66 67 69 74 public static Test suite( 75 ) 76 { 77 Config.getInstance().setPropertyFileName("osstest.properties"); 78 TestSuite suite = new DatabaseTestSuite("Test for database setup in property file."); 79 addGenericTests(suite); 80 TestSetup wrapper = new DatabaseTestSetup(suite); 81 82 return wrapper; 83 } 84 85 87 92 protected static void addGenericTests( 93 TestSuite suite 94 ) 95 { 96 addGenericTestsFromTestSuite(suite, "org.opensubsystems.portal.PortalTests"); 102 addGenericTestsFromTestSuite(suite, "org.opensubsystems.inventory.InventorySubsystemTests"); 103 addGenericTestsFromTestSuite(suite, "org.opensubsystems.search.SearchTests"); 104 addGenericTestsFromTestSuite(suite, "org.opensubsystems.preferences.PreferencesTests"); 105 addGenericTestsFromTestSuite(suite, "org.opensubsystems.security.SecurityTests"); 106 addGenericTestsFromTestSuite(suite, "org.opensubsystems.core.CoreTests"); 107 108 118 } 120 121 127 protected static void addGenericTestsFromTestSuite( 128 TestSuite suiteToAddTo, 129 String strSuiteClassToAddFrom 130 ) 131 { 132 try 133 { 134 Class suiteToAddFrom; 135 Method genericTestsMethod; 136 137 suiteToAddFrom = Class.forName(strSuiteClassToAddFrom); 138 genericTestsMethod = suiteToAddFrom.getMethod("addGenericTests", 139 new Class [] {TestSuite.class}); 140 genericTestsMethod.invoke(null, new Object [] {suiteToAddTo}); 141 s_logger.fine("Test from suite " + strSuiteClassToAddFrom 142 + " were successfully added."); 143 } 144 catch (ClassNotFoundException eNoClass) 145 { 146 s_logger.fine("Cannot find class " + strSuiteClassToAddFrom 149 + " therefore no tests will be added from this suite."); 150 } 151 catch (SecurityException eSecurity) 152 { 153 s_logger.log(Level.SEVERE, 154 "Cannot add tests from suite " + strSuiteClassToAddFrom 155 + " since method addGenericTests cannot be accessed.", 156 eSecurity); 157 } 158 catch (NoSuchMethodException eNoMethod) 159 { 160 s_logger.log(Level.SEVERE, 161 "Cannot add tests from suite " + strSuiteClassToAddFrom 162 + " since method addGenericTests cannot be found.", 163 eNoMethod); 164 } 165 catch (IllegalArgumentException eBadArg) 166 { 167 s_logger.log(Level.SEVERE, 168 "Cannot add tests from suite " + strSuiteClassToAddFrom 169 + " since method addGenericTests doesn't take TestSuite" 170 + " as a parameter.", eBadArg); 171 } 172 catch (IllegalAccessException eBadAccess) 173 { 174 s_logger.log(Level.SEVERE, 175 "Cannot add tests from suite " + strSuiteClassToAddFrom 176 + " since method addGenericTests cannot be accessed.", 177 eBadAccess); 178 } 179 catch (InvocationTargetException eCantInvoke) 180 { 181 s_logger.log(Level.SEVERE, 182 "Cannot add tests from suite " + strSuiteClassToAddFrom 183 + " since an error has occured invoking method.", 184 eCantInvoke); 185 } 186 } 187 } 188 | Popular Tags |