X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=inline;f=test%2Fenterprise%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsupport%2Fpersistence%2FJpaTester.java;h=52e284ee7e8ee073b389c892c87c9e9f282bba65;hb=17775e14ecfb286e59f67117e5cee7e21e95ab1f;hp=a6a512f125a5313b7c4da4793d97091cc98c77f1;hpb=2207a1e695ce23e79678c232cff2ceb84ebaa801;p=utils
diff --git a/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java b/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java
index a6a512f1..52e284ee 100644
--- a/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java
+++ b/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.wamblee.support.persistence;
import javax.sql.DataSource;
@@ -5,109 +20,114 @@ import javax.sql.DataSource;
import org.dbunit.IDatabaseTester;
/**
- * This class is the entry point for JPA tests. Test code should construct a JpaTester in the
- * @Before
method and call {@link #start()} on it in that method. Also, test code should
- * call {@link #stop()} on it in the @After
method.
+ * This class is the entry point for JPA tests. Test code should construct a
+ * JpaTester in the @Before
method and call {@link #start()} on it
+ * in that method. Also, test code should call {@link #stop()} on it in the
+ * @After
method.
+ *
+ * This class is constructed with a description of the persistence unit to be
+ * tested. The principle is that an existing persistence.xml
can be
+ * tested without change in unit test code.
*
- * This class is constructed with a description of the persistence unit to be tested. The principle is that
- * an existing persistence.xml
can be tested without change in unit test code.
- *
- * It then takes care of the following:
- *
JpaTester
+ * The main entry point for all this functionality is the
+ * {@link PersistenceUnitDescription} which describes the persistence unit and
+ * must be provided at construction of the JpaTester
*
- * NOTE: Persistence XML files should be explicitly configured with the classes that are part of the persistence unit
- * since scanning of classes does not work correctly in a unit test environment. This is currently the only limitation.
+ * NOTE: Persistence XML files should be explicitly configured with the classes
+ * that are part of the persistence unit since scanning of classes does not work
+ * correctly in a unit test environment. This is currently the only limitation.
*/
public class JpaTester {
- private PersistenceUnitDescription persistenceUnit;
- private Database db;
- private DataSource dataSource;
- private DatabaseUtils dbUtils;
- private JpaBuilder jpaBuilder;
- private IDatabaseTester dbTester;
-
- /**
- * Constructs the tester.
- * @param aPersistenceUnit Persistence unit under test.
- */
- public JpaTester(PersistenceUnitDescription aPersistenceUnit) {
- persistenceUnit = aPersistenceUnit;
- }
-
- /**
- * Starts the tester. This must be called prior to running the test.
- * @throws Exception
- */
- public void start() throws Exception {
- db = DatabaseBuilder.getDatabase();
- dataSource = db.start();
-
- dbUtils = new DatabaseUtils(dataSource, persistenceUnit.getTables());
- dbUtils.dropTables();
- dbUtils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
-
- jpaBuilder = new JpaBuilder(dataSource, 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();
- }
-
- /**
- * Stops the tester. This must be called after the test.
- */
- public void stop() {
- if (jpaBuilder != null) {
- jpaBuilder.stop();
- }
- if (db != null) {
- db.stop();
- }
- }
-
- public Database getDb() {
- return db;
- }
-
- public DataSource getDataSource() {
- return dataSource;
- }
-
- public IDatabaseTester getDbTester() {
- return dbTester;
- }
-
- public DatabaseUtils getDbUtils() {
- return dbUtils;
- }
-
- public JpaBuilder getJpaBuilder() {
- return jpaBuilder;
- }
-
- public PersistenceUnitDescription getPersistenceUnit() {
- return persistenceUnit;
- }
+ private PersistenceUnitDescription persistenceUnit;
+ private Database db;
+ private DataSource dataSource;
+ private DatabaseUtils dbUtils;
+ private JpaBuilder jpaBuilder;
+ private IDatabaseTester dbTester;
+
+ /**
+ * Constructs the tester.
+ *
+ * @param aPersistenceUnit
+ * Persistence unit under test.
+ */
+ public JpaTester(PersistenceUnitDescription aPersistenceUnit) {
+ persistenceUnit = aPersistenceUnit;
+ }
+
+ /**
+ * Starts the tester. This must be called prior to running the test.
+ *
+ * @throws Exception
+ */
+ public void start() throws Exception {
+ db = DatabaseBuilder.getDatabase();
+ dataSource = db.start();
+
+ dbUtils = new DatabaseUtils(dataSource, persistenceUnit.getTables());
+ dbUtils.dropTables();
+ dbUtils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
+
+ jpaBuilder = new JpaBuilder(dataSource, 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();
+ }
+
+ /**
+ * Stops the tester. This must be called after the test.
+ */
+ public void stop() {
+ if (jpaBuilder != null) {
+ jpaBuilder.stop();
+ }
+ if (db != null) {
+ db.stop();
+ }
+ }
+
+ public Database getDb() {
+ return db;
+ }
+
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ public IDatabaseTester getDbTester() {
+ return dbTester;
+ }
+
+ public DatabaseUtils getDbUtils() {
+ return dbUtils;
+ }
+
+ public JpaBuilder getJpaBuilder() {
+ return jpaBuilder;
+ }
+
+ public PersistenceUnitDescription getPersistenceUnit() {
+ return persistenceUnit;
+ }
}