javadoc updates
[utils] / test / enterprise / src / main / java / org / wamblee / support / persistence / JpaTester.java
index 34a79750cd090d4d6858f4c9a91d96669d1a2939..26bf6bbc1d75f8c9edb43fafcb5013529c8553ef 100644 (file)
  */
 package org.wamblee.support.persistence;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.sql.DataSource;
 
 import org.dbunit.IDatabaseTester;
+import org.wamblee.support.jndi.StubInitialContextFactory;
 
 /**
  * This class is the entry point for JPA tests. Test code should construct a
@@ -80,19 +83,23 @@ public class JpaTester {
     public void start() throws Exception {
         db = DatabaseBuilder.getDatabase();
         dataSource = db.start();
+        
+        // NOTE: adding datasource to JNDI is no longer needed for 
+        //       JPA testing, but is nice to have available for other uses.
+        StubInitialContextFactory.register();
+        try {
+            InitialContext ctx = new InitialContext();
+            ctx.bind(persistenceUnit.getJndiName(), dataSource);
+        } catch (NamingException e) {
+            throw new RuntimeException("JNDI problem", e);
+        }
 
-        dbUtils = new DatabaseUtils(dataSource, persistenceUnit.getTables());
+        dbUtils = new DatabaseUtils(dataSource);
         dbUtils.start();
-        dbUtils.dropTables();
         dbUtils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
 
-        jpaBuilder = new JpaBuilder(dataSource, persistenceUnit);
+        jpaBuilder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db.getPassword(), persistenceUnit);
         jpaBuilder.start();
-
-        // db tester should be created after Jpa builder because jpa builder
-        // creates the
-        // tables that the tester looks at when it is initialized.
-        dbTester = dbUtils.createDbTester();
     }
 
     /**
@@ -110,26 +117,42 @@ public class JpaTester {
         }
     }
 
+    /**
+     * Gets the database. 
+     * @return Database. 
+     */
     public Database getDb() {
         return db;
     }
 
+    /**
+     * Gets the datasource. 
+     * @return Datasource. 
+     */
     public DataSource getDataSource() {
         return dataSource;
     }
 
-    public IDatabaseTester getDbTester() {
-        return dbTester;
-    }
-
+    /**
+     * Gets the database utilities. 
+     * @return Database utilities. 
+     */
     public DatabaseUtils getDbUtils() {
         return dbUtils;
     }
 
+    /**
+     * Gets the jpa builder. 
+     * @return JPA builder. 
+     */
     public JpaBuilder getJpaBuilder() {
         return jpaBuilder;
     }
 
+    /**
+     * Gets the persistence unit. 
+     * @return Persistence unit. 
+     */
     public PersistenceUnitDescription getPersistenceUnit() {
         return persistenceUnit;
     }