(no commit message)
[utils] / support / test / org / wamblee / test / SpringTestCase.java
index 8b436215d16c0838540694d6c58c5a56d08c90bf..8b563b68e8e4ddebe0a50c2190bdf4abb2a6d995 100644 (file)
@@ -63,11 +63,11 @@ import org.wamblee.general.BeanKernel;
 import org.wamblee.persistence.hibernate.HibernateMappingFiles;
 
 /**
- * Test case support class for spring tests. 
+ * Test case support class for spring tests.
  */
 public class SpringTestCase extends MockObjectTestCase {
 
-    private Log LOG = LogFactory.getLog(SpringTestCase.class);
+    private static final Log LOG = LogFactory.getLog(SpringTestCase.class);
 
     /**
      * Session factory bean name.
@@ -94,22 +94,22 @@ public class SpringTestCase extends MockObjectTestCase {
      * Schema pattern.
      */
     private static final String SCHEMA_PATTERN = "%";
-   
+
     /**
      * List of (String) configuration file locations for spring.
      */
     private String[] _configLocations;
-    
+
     /**
      * Application context for storing bean definitions that vary on a test by
      * test basis and cannot be hardcoded in the spring configuration files.
      */
     private GenericApplicationContext _parentContext;
-    
+
     /**
-     * Cached spring application context. 
+     * Cached spring application context.
      */
-    private ApplicationContext _context; 
+    private ApplicationContext _context;
 
     public SpringTestCase(Class<? extends SpringConfigFiles> aSpringFiles,
             Class<? extends HibernateMappingFiles> aMappingFiles) {
@@ -117,9 +117,10 @@ public class SpringTestCase extends MockObjectTestCase {
             SpringConfigFiles springFiles = aSpringFiles.newInstance();
             _configLocations = springFiles.toArray(new String[0]);
         } catch (Exception e) {
-            fail("Could not construct spring config files class '" + aSpringFiles.getName() + "'"); 
+            fail("Could not construct spring config files class '"
+                    + aSpringFiles.getName() + "'");
         }
-   
+
         // Register the Hibernate mapping files as a bean.
         _parentContext = new GenericApplicationContext();
         BeanDefinition lDefinition = new RootBeanDefinition(aMappingFiles);
@@ -135,35 +136,37 @@ public class SpringTestCase extends MockObjectTestCase {
      * @return Spring context.
      */
     protected synchronized ApplicationContext getSpringContext() {
-        if ( _context == null ) { 
+        if (_context == null) {
             _context = new ClassPathXmlApplicationContext(
-                (String[]) _configLocations, _parentContext);
+                    (String[]) _configLocations, _parentContext);
             assertNotNull(_context);
         }
-        return _context; 
+        return _context;
     }
 
     /**
      * @return Hibernate session factory.
      */
     protected SessionFactory getSessionFactory() {
-        SessionFactory factory = (SessionFactory) getSpringContext().getBean(SESSION_FACTORY);
-        assertNotNull(factory); 
-        return factory; 
+        SessionFactory factory = (SessionFactory) getSpringContext().getBean(
+                SESSION_FACTORY);
+        assertNotNull(factory);
+        return factory;
     }
 
     protected void setUp() throws Exception {
         LOG.info("Performing setUp()");
 
         super.setUp();
-        
-        _context = null;  // make sure we get a new application context for every
-                          // new test. 
 
-        BeanKernel
-                .overrideBeanFactory(new TestSpringBeanFactory(getSpringContext()));
-  
-        cleanDatabase(); 
+        _context = null; // make sure we get a new application context for
+        // every
+        // new test.
+
+        BeanKernel.overrideBeanFactory(new TestSpringBeanFactory(
+                getSpringContext()));
+
+        cleanDatabase();
     }
 
     /*
@@ -185,9 +188,9 @@ public class SpringTestCase extends MockObjectTestCase {
      */
     protected PlatformTransactionManager getTransactionManager() {
         PlatformTransactionManager manager = (PlatformTransactionManager) getSpringContext()
-        .getBean(TRANSACTION_MANAGER);
-        assertNotNull(manager); 
-        return manager; 
+                .getBean(TRANSACTION_MANAGER);
+        assertNotNull(manager);
+        return manager;
     }
 
     /**
@@ -207,9 +210,10 @@ public class SpringTestCase extends MockObjectTestCase {
      * @return Hibernate template.
      */
     protected HibernateTemplate getTemplate() {
-        HibernateTemplate template = (HibernateTemplate) getSpringContext().getBean(HibernateTemplate.class.getName());
-        assertNotNull(template); 
-        return template; 
+        HibernateTemplate template = (HibernateTemplate) getSpringContext()
+                .getBean(HibernateTemplate.class.getName());
+        assertNotNull(template);
+        return template;
     }
 
     /**
@@ -254,11 +258,11 @@ public class SpringTestCase extends MockObjectTestCase {
     }
 
     public void cleanDatabase() throws SQLException {
-        
-        if (! isDatabaseConfigured() ) {
-            return; 
+
+        if (!isDatabaseConfigured()) {
+            return;
         }
-        
+
         String[] tables = getTableNames();
 
         try {
@@ -273,7 +277,7 @@ public class SpringTestCase extends MockObjectTestCase {
             SQLException exc = new SQLException(e.getMessage());
             exc.initCause(e);
             throw exc;
-        } 
+        }
     }
 
     /**
@@ -370,7 +374,7 @@ public class SpringTestCase extends MockObjectTestCase {
                 JdbcTemplate template = new JdbcTemplate(getDataSource());
                 int result = template.update(aSql, aArgs);
 
-                Map map = new TreeMap();
+                Map<String, Integer> map = new TreeMap<String, Integer>();
                 map.put("result", new Integer(result));
 
                 return map;
@@ -548,23 +552,24 @@ public class SpringTestCase extends MockObjectTestCase {
                     + " statement: " + aStatement);
         }
     }
-    
-    private boolean isDatabaseConfigured() { 
-        try { 
-            getDataSource(); 
-        } catch (NoSuchBeanDefinitionException e ) { 
-            return false; 
+
+    private boolean isDatabaseConfigured() {
+        try {
+            getDataSource();
+        } catch (NoSuchBeanDefinitionException e) {
+            return false;
         }
-        return true; 
+        return true;
     }
 
     /**
      * @return Returns the dataSource.
      */
     public DataSource getDataSource() {
-        DataSource ds = (DriverManagerDataSource) getSpringContext().getBean(DATA_SOURCE);
-        assertNotNull(ds); 
-        return ds; 
+        DataSource ds = (DriverManagerDataSource) getSpringContext().getBean(
+                DATA_SOURCE);
+        assertNotNull(ds);
+        return ds;
     }
 
     /**
@@ -581,8 +586,8 @@ public class SpringTestCase extends MockObjectTestCase {
 
         return count;
     }
-    
-    protected int countResultSet(ResultSet aResultSet) throws SQLException { 
+
+    protected int countResultSet(ResultSet aResultSet) throws SQLException {
         int count = 0;
 
         while (aResultSet.next()) {