(no commit message)
authorErik Brakkee <erik@brakkee.org>
Sat, 31 Jul 2010 17:33:39 +0000 (17:33 +0000)
committerErik Brakkee <erik@brakkee.org>
Sat, 31 Jul 2010 17:33:39 +0000 (17:33 +0000)
51 files changed:
test/enterprise/src/main/java/org/wamblee/test/inject/Binding.java
test/enterprise/src/main/java/org/wamblee/test/inject/JavaEETestInjector.java
test/enterprise/src/main/java/org/wamblee/test/inject/JavaEETestInjectorFactory.java
test/enterprise/src/main/java/org/wamblee/test/jndi/StubInitialContext.java
test/enterprise/src/main/java/org/wamblee/test/jndi/StubInitialContextFactory.java
test/enterprise/src/main/java/org/wamblee/test/jndi/package-info.java
test/enterprise/src/main/java/org/wamblee/test/persistence/AbstractDatabase.java
test/enterprise/src/main/java/org/wamblee/test/persistence/AbstractDatabaseProvider.java
test/enterprise/src/main/java/org/wamblee/test/persistence/CompositeJpaCustomizer.java
test/enterprise/src/main/java/org/wamblee/test/persistence/CompositeJpaTables.java
test/enterprise/src/main/java/org/wamblee/test/persistence/Database.java
test/enterprise/src/main/java/org/wamblee/test/persistence/DatabaseBuilder.java
test/enterprise/src/main/java/org/wamblee/test/persistence/DatabaseDescription.java
test/enterprise/src/main/java/org/wamblee/test/persistence/DatabaseProvider.java
test/enterprise/src/main/java/org/wamblee/test/persistence/DatabaseStarter.java
test/enterprise/src/main/java/org/wamblee/test/persistence/DatabaseUtils.java
test/enterprise/src/main/java/org/wamblee/test/persistence/DerbyDatabaseProvider.java
test/enterprise/src/main/java/org/wamblee/test/persistence/ExternalDatabase.java
test/enterprise/src/main/java/org/wamblee/test/persistence/ExternalDatabaseProvider.java
test/enterprise/src/main/java/org/wamblee/test/persistence/JpaBuilder.java
test/enterprise/src/main/java/org/wamblee/test/persistence/JpaCustomizer.java
test/enterprise/src/main/java/org/wamblee/test/persistence/JpaCustomizerBuilder.java
test/enterprise/src/main/java/org/wamblee/test/persistence/JpaTester.java
test/enterprise/src/main/java/org/wamblee/test/persistence/LoggingTransactionResultCallback.java
test/enterprise/src/main/java/org/wamblee/test/persistence/PersistenceUnitDescription.java
test/enterprise/src/main/java/org/wamblee/test/persistence/RequireTransactionStatus.java
test/enterprise/src/main/java/org/wamblee/test/persistence/TransactionResultCallback.java
test/enterprise/src/main/java/org/wamblee/test/persistence/package-info.java
test/enterprise/src/main/java/org/wamblee/test/transactions/DefaultUserTransactionFactory.java
test/enterprise/src/main/java/org/wamblee/test/transactions/SimpleTransactionManager.java
test/enterprise/src/main/java/org/wamblee/test/transactions/SimpleUserTransaction.java
test/enterprise/src/main/java/org/wamblee/test/transactions/TransactionProxyFactory.java
test/enterprise/src/main/java/org/wamblee/test/transactions/TransactionResource.java
test/enterprise/src/main/java/org/wamblee/test/transactions/TransactionResult.java
test/enterprise/src/main/java/org/wamblee/test/transactions/UserTransactionCallback.java
test/enterprise/src/main/java/org/wamblee/test/transactions/UserTransactionFactory.java
test/enterprise/src/main/java/org/wamblee/test/transactions/package-info.java
test/enterprise/src/test/java/org/wamblee/test/inject/JavaEETestInjectorFactoryTest.java
test/enterprise/src/test/java/org/wamblee/test/jndi/StubInitiaContextFactoryTest.java
test/enterprise/src/test/java/org/wamblee/test/persistence/DatabaseBuilderTest.java
test/enterprise/src/test/java/org/wamblee/test/persistence/DatabaseUtilsLeakTest.java
test/enterprise/src/test/java/org/wamblee/test/persistence/DatabaseUtilsTestBase.java
test/enterprise/src/test/java/org/wamblee/test/persistence/DerbyDatabaseTest.java
test/enterprise/src/test/java/org/wamblee/test/persistence/ExternalDatabaseTest.java
test/enterprise/src/test/java/org/wamblee/test/persistence/MyEntity.java
test/enterprise/src/test/java/org/wamblee/test/persistence/MyPersistenceUnit.java
test/enterprise/src/test/java/org/wamblee/test/persistence/MyTables.java
test/enterprise/src/test/java/org/wamblee/test/persistence/RequireTransactionStatusTest.java
test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java
test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerTest.java
test/enterprise/src/test/java/org/wamblee/test/transactions/TransactionProxyFactoryTestBase.java

index 14e620a32583f6386b3b841584a1153ac5d97a1a..e9b27b98329a0252cecf537ab28701bf1ddbfdd3 100644 (file)
@@ -24,12 +24,13 @@ import org.wamblee.reflection.Accessor;
 import org.wamblee.reflection.AnnotationUtils;
 
 /**
- * This class represents an injection binding. It provides injection of a defined object (typically mock or stub)
- * into other objects. The binding is defined by the required annotation that must be on the field, the field type, 
- * and the object to be injected. 
+ * This class represents an injection binding. It provides injection of a
+ * defined object (typically mock or stub) into other objects. The binding is
+ * defined by the required annotation that must be on the field, the field type,
+ * and the object to be injected.
  * 
  * @author Erik Brakkee
- *
+ * 
  * @param <T>
  */
 public class Binding<T> {
@@ -39,10 +40,14 @@ public class Binding<T> {
     private Map<Class, List<Accessor>> accessorCache;
 
     /**
-     * Constructs the binding. 
-     * @param aClass Required type of the field injected into. 
-     * @param aAnnotation Annotation that must be present on the field.
-     * @param aValue Value of the annotation. 
+     * Constructs the binding.
+     * 
+     * @param aClass
+     *            Required type of the field injected into.
+     * @param aAnnotation
+     *            Annotation that must be present on the field.
+     * @param aValue
+     *            Value of the annotation.
      */
     public Binding(Class<T> aClass, Class<? extends Annotation> aAnnotation,
         Object aValue) {
index 8fe52ac10203de9030c599709c430d8b4fd85584..853d312c893cbdd8099e8c5c2d9c943e0f6509ee 100644 (file)
@@ -37,10 +37,11 @@ import org.wamblee.reflection.ObjectTraversal.ObjectVisitor;
  * </p>
  * 
  * <p>
- * It works by first delegating to the default injector (typically CDI). Afterwards it traverses the
- * object graph of the injected object and performs custom injection of test objects as specified by the
- * {@link Binding} class. This approach makes sure that test dependencies also find their way into 
- * objects that were created by the injection framework. 
+ * It works by first delegating to the default injector (typically CDI).
+ * Afterwards it traverses the object graph of the injected object and performs
+ * custom injection of test objects as specified by the {@link Binding} class.
+ * This approach makes sure that test dependencies also find their way into
+ * objects that were created by the injection framework.
  * </p>
  * 
  * @author Erik Brakkee
@@ -50,37 +51,44 @@ public class JavaEETestInjector implements Injector {
     private class InjectionVisitor implements ObjectVisitor {
         @Override
         public boolean mustVisit(Class aClass) {
-            if (EntityManager.class.isAssignableFrom(aClass)) { 
+            if (EntityManager.class.isAssignableFrom(aClass)) {
                 return false;
             }
             return true;
         }
+
         @Override
         public boolean mustVisit(Field aField) {
             // just process any field with annotations
-            return aField.getAnnotations().length > 0;  
+            return aField.getAnnotations().length > 0;
         }
+
         @Override
         public boolean mustVisit(Method aMethod) {
             return false;
         }
+
         @Override
         public boolean visitArray(Object aArray) {
             return true;
         }
+
         @Override
         public boolean visitList(List aObject) {
             return true;
         }
+
         @Override
         public boolean visitMap(Map aObject) {
             return true;
         }
+
         @Override
         public boolean visitPlainObject(Object aObject) {
             performTestInjections(aObject);
             return true;
         }
+
         @Override
         public boolean visitSet(Set aSet) {
             return true;
@@ -110,7 +118,7 @@ public class JavaEETestInjector implements Injector {
     public void inject(Object aComponent) {
         // basic injection
         delegate.inject(aComponent);
-        
+
         // Now perform test injections.
         ObjectTraversal traversal = new ObjectTraversal(new InjectionVisitor());
         traversal.accept(aComponent);
index fdfb84a782ba71993d92788075515677590274ce..f5814981064a369c26929b034732c976c233f13f 100644 (file)
@@ -28,65 +28,76 @@ import org.wamblee.test.persistence.JpaBuilder;
 
 /**
  * <p>
- * The test injector factory provides dependency injection of a contextual entity manager
- * using the support/inject mini framework. It supports dependency injection of fields
- * annoted with <code>&#064;PersistenceContext</code>. It only supports one persistence context
- * at the moment. This injector can be easily used together with {@link JpaBuilder#getContextualEntityManager()}
- * for obtaining an entity manager in unit test. 
+ * The test injector factory provides dependency injection of a contextual
+ * entity manager using the support/inject mini framework. It supports
+ * dependency injection of fields annoted with
+ * <code>&#064;PersistenceContext</code>. It only supports one persistence
+ * context at the moment. This injector can be easily used together with
+ * {@link JpaBuilder#getContextualEntityManager()} for obtaining an entity
+ * manager in unit test.
  * </p>
  * 
  * <p>
- * The reason it is needed is because standard injection mechanisms (such as weld CDI) do not support
- * entity manager injection in a Java SE environment out of the box.  
+ * The reason it is needed is because standard injection mechanisms (such as
+ * weld CDI) do not support entity manager injection in a Java SE environment
+ * out of the box.
  * </p>
- *
+ * 
  * <p>
- * To use it, construct the factory using one of the available constructors and set 
- * <code>InjectorBuilder.setInjectorFactory(InjectorFactory)</code>.
+ * To use it, construct the factory using one of the available constructors and
+ * set <code>InjectorBuilder.setInjectorFactory(InjectorFactory)</code>.
  * </p>
  * 
  * @author Erik Brakkee
- *
+ * 
  */
 public class JavaEETestInjectorFactory implements InjectorFactory {
 
     private List<Binding> bindings;
     private InjectorFactory delegate;
-    
+
     /**
-     * Constructs the factory. 
-     * @param aInjectorFactory Injector factory to delegate to. 
+     * Constructs the factory.
+     * 
+     * @param aInjectorFactory
+     *            Injector factory to delegate to.
      */
     public JavaEETestInjectorFactory(InjectorFactory aInjectorFactory) {
-        bindings = new ArrayList<Binding>();        
+        bindings = new ArrayList<Binding>();
         delegate = aInjectorFactory;
     }
 
     /**
-     * Adds default entity manager binding. Any field annotated with @PersistenceContext and of type 
-     * entity manager will get injected.
-     * @param aEntityManager Entitymanager object to inject.
+     * Adds default entity manager binding. Any field annotated with @PersistenceContext
+     * and of type entity manager will get injected.
+     * 
+     * @param aEntityManager
+     *            Entitymanager object to inject.
      * @return Factory to allow chaining.
      */
-    public JavaEETestInjectorFactory addEntityManagerBinding(EntityManager aEntityManager) {
-        Binding em = new Binding(EntityManager.class, PersistenceContext.class, aEntityManager);
+    public JavaEETestInjectorFactory addEntityManagerBinding(
+        EntityManager aEntityManager) {
+        Binding em = new Binding(EntityManager.class, PersistenceContext.class,
+            aEntityManager);
         addBinding(em);
         return this;
     }
-    
+
     /**
-     * Adds another custom injection binding. 
-     * @param aBinding Injection binding to use. 
+     * Adds another custom injection binding.
+     * 
+     * @param aBinding
+     *            Injection binding to use.
      * @return the factoryto allow chaining.
      */
-    public JavaEETestInjectorFactory addBinding(Binding aBinding) { 
+    public JavaEETestInjectorFactory addBinding(Binding aBinding) {
         bindings.add(aBinding);
-        return this; 
+        return this;
     }
 
     /**
-     * Constructs the factory with the default injector factory obtained from 
-     * {@link InjectorBuilder#getInjector()}. 
+     * Constructs the factory with the default injector factory obtained from
+     * {@link InjectorBuilder#getInjector()}.
      */
     public JavaEETestInjectorFactory() {
         this(getDefaultInjectorFactory());
@@ -99,7 +110,6 @@ public class JavaEETestInjectorFactory implements InjectorFactory {
 
     @Override
     public Injector create(Class aClass) {
-        return new JavaEETestInjector(aClass, bindings, delegate
-            .create(aClass));
+        return new JavaEETestInjector(aClass, bindings, delegate.create(aClass));
     }
 }
index f527770345370767c72d7d1946578ed9f2d1e74f..e185d506c3976fad77e28e30f7535b964a605133 100644 (file)
@@ -24,7 +24,7 @@ import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 
 /**
- * Initial context implementation. 
+ * Initial context implementation.
  * 
  * @author Erik Brakkee
  */
@@ -39,7 +39,7 @@ class StubInitialContext extends InitialContext {
     public void bind(String aName, Object aObj) throws NamingException {
         bindings.put(aName, aObj);
     }
-    
+
     @Override
     public void unbind(String aName) throws NamingException {
         bindings.remove(aName);
@@ -53,12 +53,12 @@ class StubInitialContext extends InitialContext {
         }
         return value;
     }
-    
+
     @Override
     public void bind(Name aName, Object aObj) throws NamingException {
         bind(aName.toString(), aObj);
     }
-    
+
     @Override
     public void unbind(Name aName) throws NamingException {
         unbind(aName.toString());
index 09389ef10059036d956705401d43a053614b70b7..023e77773a14009b46e7224292c2a0ec12f8242e 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.jndi;
 
 import java.util.Hashtable;
@@ -27,17 +27,18 @@ import javax.naming.spi.InitialContextFactory;
  * 
  * See {@link #bind(String, Object)} to resp. register the initial context.
  * 
- * To start mocking the JNDI tree, call {@link #register()}. 
+ * To start mocking the JNDI tree, call {@link #register()}.
+ * 
+ * To bind objects in the JNDI tree simply use the standard JNDI api:
  * 
- * To bind objects in the JNDI tree simply use the standard JNDI api: 
  * <pre>
  *   InitialContext context = new InitialContext();
  *   MyClass myObj = ...; 
- *   context.bind("a/b", myObj); 
+ *   context.bind("a/b", myObj);
  * </pre>
  * 
- * When finished with a test case, call {@link #unregister()} to unregister the 
- * JNDI tree again. 
+ * When finished with a test case, call {@link #unregister()} to unregister the
+ * JNDI tree again.
  */
 public class StubInitialContextFactory implements InitialContextFactory {
 
index 7fd7ddbc8bf2e4337855627701aba08fc779982f..acbc06e23c28700041af8d72d9b6400b5892a39c 100644 (file)
@@ -12,7 +12,7 @@
  * 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.
- */ 
+ */
 /**
  * This package provides utilities for JNDI testing.  
  * 
index df5cb75f44810f4a318f1de694f8bc2f3f384c4d..11fda933ba14ac36a1913e47bb734c90c1d05d63 100644 (file)
@@ -29,12 +29,12 @@ import org.apache.commons.dbcp.PoolingDataSource;
 import org.apache.commons.pool.impl.GenericObjectPool;
 
 /**
- * Abstract database class providing the creation of the datasource, 
- * preventing duplicate starts of the same database, and checking
- * for connection leaks when the database is stopped. 
+ * Abstract database class providing the creation of the datasource, preventing
+ * duplicate starts of the same database, and checking for connection leaks when
+ * the database is stopped.
  * 
  * @author Erik Brakkee
- *
+ * 
  */
 public abstract class AbstractDatabase implements Database {
 
@@ -56,19 +56,19 @@ public abstract class AbstractDatabase implements Database {
     private boolean started;
 
     /**
-     * Constructs the database. 
+     * Constructs the database.
      */
     protected AbstractDatabase() {
         started = false;
     }
 
     /**
-     * To be implemented by subclasses to start the database. 
+     * To be implemented by subclasses to start the database.
      */
     protected abstract void doStart();
 
     /**
-     * To be implemented by subclasses to stop the database. 
+     * To be implemented by subclasses to stop the database.
      */
     protected abstract void doStop();
 
@@ -101,7 +101,7 @@ public abstract class AbstractDatabase implements Database {
     // / BELOW THIS LINE IS NOT OF INTEREST TO SUBCLASSES.
 
     /**
-     * Starts the database. 
+     * Starts the database.
      */
     public final DataSource start() {
         if (started) {
@@ -113,9 +113,9 @@ public abstract class AbstractDatabase implements Database {
     }
 
     /**
-     * Stops the database and tests for connection leaks. 
-     * In cast the system property with the name given by {@link #IGNORE_CONNECTION_LEAK_PROPERTY}
-     * is set then the connection leaks are  not checked. 
+     * Stops the database and tests for connection leaks. In cast the system
+     * property with the name given by {@link #IGNORE_CONNECTION_LEAK_PROPERTY}
+     * is set then the connection leaks are not checked.
      */
     public final void stop() {
         if (!started) {
@@ -127,8 +127,9 @@ public abstract class AbstractDatabase implements Database {
                 String msg = "JDBC connection pool still has " +
                     connectionPool.getNumActive() +
                     " active connection(s), this is a potential resource leak in the code\n";
-                // backdoor to ignore connection leaks. Use this system property only if you 
-                // can safely ignore the connection leaks. 
+                // backdoor to ignore connection leaks. Use this system property
+                // only if you
+                // can safely ignore the connection leaks.
                 if (System.getProperty(IGNORE_CONNECTION_LEAK_PROPERTY) == null) {
                     Assert.fail(msg);
                 }
index 9bfa30f18a25ad41d8f8a7efc9d87896a7f63e90..321a8c1e9464880fd19fb867e914041b5744e8f0 100644 (file)
  * 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.test.persistence;
 
 import java.util.List;
+
 /**
- * Base class for database providers. 
+ * Base class for database providers.
  * 
  * @author Erik Brakkee
  */
 public abstract class AbstractDatabaseProvider implements DatabaseProvider {
 
     /**
-     * @return List of database capabilities. 
+     * @return List of database capabilities.
      */
     protected abstract List<String> getCapabilities();
 
     /**
-     * Standard implementation of the capabalities check. 
+     * Standard implementation of the capabalities check.
      */
     public final boolean supportsCapabilities(String[] aCapabilities) {
         for (String capability : aCapabilities) {
index 08de725c217b182bb9d2ba0261034d2c226fc6fb..e766b9fea134b401868601d5e1488e13580f9211 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.util.List;
@@ -21,8 +21,8 @@ import java.util.Map;
 import org.dbunit.dataset.filter.ITableFilterSimple;
 
 /**
- * Composite JPA customizer that applies the customizations from several
- * JPA customizers. 
+ * Composite JPA customizer that applies the customizations from several JPA
+ * customizers.
  * 
  * @author Erik Brakkee
  */
@@ -32,8 +32,10 @@ public class CompositeJpaCustomizer implements JpaCustomizer {
     private CompositeJpaTables tables;
 
     /**
-     * Construcst the customizer. 
-     * @param aCustomizers List of customizers. 
+     * Construcst the customizer.
+     * 
+     * @param aCustomizers
+     *            List of customizers.
      */
     public CompositeJpaCustomizer(List<JpaCustomizer> aCustomizers) {
         customizers = aCustomizers;
index 23db6d29e39aec2547f64d366acab984c4c8a75e..d1d2d3acb8abfdb9da3b992cca7ab4244598f5ec 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.util.ArrayList;
@@ -22,7 +22,7 @@ import org.dbunit.dataset.DataSetException;
 import org.dbunit.dataset.filter.ITableFilterSimple;
 
 /**
- * Composite JPA tables. Implements the logical or of several table filters. 
+ * Composite JPA tables. Implements the logical or of several table filters.
  * 
  * @author Erik Brakkee
  */
@@ -31,15 +31,17 @@ public class CompositeJpaTables implements ITableFilterSimple {
     private List<ITableFilterSimple> tables;
 
     /**
-     * Construcst the tables. 
+     * Construcst the tables.
      */
     public CompositeJpaTables() {
         tables = new ArrayList<ITableFilterSimple>();
     }
 
     /**
-     * Adds a table filter. 
-     * @param aFilter filter. 
+     * Adds a table filter.
+     * 
+     * @param aFilter
+     *            filter.
      */
     public void add(ITableFilterSimple aFilter) {
         tables.add(aFilter);
index da8ff158ab0e6160f6a5db1174f5d9229503436e..6627343294affe0b49ef6421a012e2ee3a184a5c 100755 (executable)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import javax.sql.DataSource;
@@ -29,13 +29,14 @@ public interface Database {
      * database has been started.
      */
     DataSource start();
-    
+
     /**
-     * Gets the number of active connections from the pool. This is useful for 
-     * determining resource leaks. 
-     * @return Active connections. 
+     * Gets the number of active connections from the pool. This is useful for
+     * determining resource leaks.
+     * 
+     * @return Active connections.
      */
-    int getActiveConnections(); 
+    int getActiveConnections();
 
     /**
      * Gets the Jdbc Url to connect to this database.
index f8ae4a99e559e33d53e9551d9f5cd56381b3e400..e966d456062f2f086dbe3f7e760381027789dc14 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.util.ArrayList;
@@ -62,11 +62,11 @@ public class DatabaseBuilder {
      */
     public static final String DB_CAPABILITIES_PROP = "TEST_DB_CAPABILITIES";
 
-    private static ServiceLoader<DatabaseProvider> LOADER = 
-        ServiceLoader.load(DatabaseProvider.class);
+    private static ServiceLoader<DatabaseProvider> LOADER = ServiceLoader
+        .load(DatabaseProvider.class);
 
     /**
-     * Constructs the database builder. 
+     * Constructs the database builder.
      */
     private DatabaseBuilder() {
         // Empty.
index 8f44094aa282825602d7b53a85249955b60f6ede..aa9966e78fd480719c25b6cb012d74fc088de84e 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 /**
@@ -52,7 +52,7 @@ public class DatabaseDescription {
         for (int i = 0; i < itsCapabilities.length; i++) {
             res.append(itsCapabilities[i]);
             if (i < itsCapabilities.length - 1) {
-                res.append(", "); 
+                res.append(", ");
             }
         }
         return res.toString();
index 21699ed80812e4f352c57751a5ebed01a4fbebbe..9b78363cbad749ed934b071714996aa4a4d09f07 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 /**
index 8be5ff7c3829093636cecbbf1ff95e41409b736f..92b6a521999e6f4844afb7c98ade82299f511cd4 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 /**
index c4e38f4d0a6e1c89325b3cbd1a675894675ac0ed..dc7c040445a890ea0412c7ce1a3a31251abd285d 100644 (file)
@@ -47,7 +47,7 @@ public class DatabaseUtils {
 
     /**
      * Represents a set of tables.
-     *  
+     * 
      * @author Erik Brakkee
      */
     public static interface TableSet {
@@ -58,29 +58,33 @@ public class DatabaseUtils {
      * Represents a unit of work (transaction).
      * 
      * @author Erik Brakkee
-     *
-     * @param <T> Type of return value. 
+     * 
+     * @param <T>
+     *            Type of return value.
      */
     public static interface JdbcUnitOfWork<T> {
         /**
-         * Executes statement within a transaction. 
-         * @param aConnection Connection. 
-         * @return Result of the work. 
+         * Executes statement within a transaction.
+         * 
+         * @param aConnection
+         *            Connection.
+         * @return Result of the work.
          * @throws Exception
          */
         T execute(Connection aConnection) throws Exception;
     }
 
     /**
-     * Operation to be executed on a set of tables for each table 
-     * individually. 
+     * Operation to be executed on a set of tables for each table individually.
      * 
      * @author Erik Brakkee
      */
     public static interface TableSetOperation {
         /**
-         * Executes on a table. 
-         * @param aTable Table name. 
+         * Executes on a table.
+         * 
+         * @param aTable
+         *            Table name.
          * @throws Exception
          */
         void execute(String aTable) throws Exception;
@@ -97,37 +101,39 @@ public class DatabaseUtils {
 
     private IDatabaseTester dbtester;
     /**
-     * List of connections that were created for dbtesters. 
-     * This list will be closed in the {@link #stop()} method. 
+     * List of connections that were created for dbtesters. This list will be
+     * closed in the {@link #stop()} method.
      */
-    private List<IDatabaseConnection> connections; 
-    
+    private List<IDatabaseConnection> connections;
+
     /**
-     * Constructs the database utils. 
-     * Before use, {@link #start()} must be called. 
-     * @param aDataSource Datasource.  
+     * Constructs the database utils. Before use, {@link #start()} must be
+     * called.
+     * 
+     * @param aDataSource
+     *            Datasource.
      */
     public DatabaseUtils(DataSource aDataSource) {
         dataSource = aDataSource;
         dbtester = new DataSourceDatabaseTester(dataSource);
-        connections = new ArrayList<IDatabaseConnection>(); 
+        connections = new ArrayList<IDatabaseConnection>();
     }
 
     /**
-     * Starts the database utils. 
+     * Starts the database utils.
      */
-    public void start() { 
-        // Empty. No operation currently. 
+    public void start() {
+        // Empty. No operation currently.
     }
 
     /**
      * Stops the database utils, closing any JDBC connections that were created
-     * by this utility. Note that connections obtained from the datasource directly 
-     * must still be closed by the user. The involved connections are only those that
-     * are created by this utility. 
+     * by this utility. Note that connections obtained from the datasource
+     * directly must still be closed by the user. The involved connections are
+     * only those that are created by this utility.
      */
     public void stop() {
-        for (IDatabaseConnection connection: connections) { 
+        for (IDatabaseConnection connection : connections) {
             try {
                 connection.close();
             } catch (SQLException e) {
@@ -138,19 +144,24 @@ public class DatabaseUtils {
     }
 
     /**
-     * Creates database tester. 
-     * @param aTables Tables to create the tester for. 
-     * @return Database tester. 
+     * Creates database tester.
+     * 
+     * @param aTables
+     *            Tables to create the tester for.
+     * @return Database tester.
      * @throws Exception
      */
-    public IDatabaseTester createDbTester(ITableFilterSimple aTables) throws Exception {
+    public IDatabaseTester createDbTester(ITableFilterSimple aTables)
+        throws Exception {
         return createDbTester(getTableNames(aTables));
     }
-    
+
     /**
-     * Creates database tester. 
-     * @param aTables Tables to create the tester for. 
-     * @return Database tester. 
+     * Creates database tester.
+     * 
+     * @param aTables
+     *            Tables to create the tester for.
+     * @return Database tester.
      * @throws Exception
      */
     public IDatabaseTester createDbTester(String[] aTables) throws Exception {
@@ -161,9 +172,12 @@ public class DatabaseUtils {
     }
 
     /**
-     * Executes an operation on a set of tables. 
-     * @param aTables Tables. 
-     * @param aOperation Operation. 
+     * Executes an operation on a set of tables.
+     * 
+     * @param aTables
+     *            Tables.
+     * @param aOperation
+     *            Operation.
      * @throws Exception
      */
     public void executeOnTables(ITableFilterSimple aTables,
@@ -180,9 +194,12 @@ public class DatabaseUtils {
     }
 
     /**
-     * Cleans a number of database tables. This means deleting the content not dropping the tables. 
-     * This may fail in case of cyclic dependencies between the tables (current limitation). 
-     * @param aSelection Tables.
+     * Cleans a number of database tables. This means deleting the content not
+     * dropping the tables. This may fail in case of cyclic dependencies between
+     * the tables (current limitation).
+     * 
+     * @param aSelection
+     *            Tables.
      * @throws Exception
      */
     public void cleanDatabase(ITableFilterSimple aSelection) throws Exception {
@@ -205,14 +222,16 @@ public class DatabaseUtils {
     }
 
     /**
-     * Executes a unit of work within a transaction. 
-     * @param <T> Result type of th ework. 
-     * @param aWork Unit of work. 
+     * Executes a unit of work within a transaction.
+     * 
+     * @param <T>
+     *            Result type of th ework.
+     * @param aWork
+     *            Unit of work.
      * @return
      * @throws Exception
      */
-    public <T> T executeInTransaction(JdbcUnitOfWork<T> aWork)
-        throws Exception {
+    public <T> T executeInTransaction(JdbcUnitOfWork<T> aWork) throws Exception {
         Connection connection = dataSource.getConnection();
         connection.setAutoCommit(false);
         try {
@@ -223,11 +242,13 @@ public class DatabaseUtils {
             connection.close();
         }
     }
-    
+
     /**
-     * Returns table names based on a table filter. 
-     * @param aSelection Table filter. 
-     * @return Table names. 
+     * Returns table names based on a table filter.
+     * 
+     * @param aSelection
+     *            Table filter.
+     * @return Table names.
      * @throws Exception
      */
     public String[] getTableNames(ITableFilterSimple aSelection)
@@ -254,7 +275,7 @@ public class DatabaseUtils {
     }
 
     /**
-     * Use {@link #cleanDatabase(ITableFilterSimple)} instead. 
+     * Use {@link #cleanDatabase(ITableFilterSimple)} instead.
      */
     @Deprecated
     public void emptyTables(final ITableFilterSimple aSelection)
@@ -267,7 +288,7 @@ public class DatabaseUtils {
     }
 
     /**
-     * User {@link #cleanDatabase(ITableFilterSimple)} instead. 
+     * User {@link #cleanDatabase(ITableFilterSimple)} instead.
      */
     @Deprecated
     public void emptyTable(String aTable) throws Exception {
@@ -275,8 +296,11 @@ public class DatabaseUtils {
     }
 
     /**
-     * Drops tables. This only works if there are no cyclic dependencies between the tables. 
-     * @param aTables Tables to drop. 
+     * Drops tables. This only works if there are no cyclic dependencies between
+     * the tables.
+     * 
+     * @param aTables
+     *            Tables to drop.
      * @throws Exception
      */
     public void dropTables(ITableFilterSimple aTables) throws Exception {
@@ -299,8 +323,10 @@ public class DatabaseUtils {
     }
 
     /**
-     * Drops a table. 
-     * @param aTable Table to drop. 
+     * Drops a table.
+     * 
+     * @param aTable
+     *            Table to drop.
      * @throws Exception
      */
     public void dropTable(final String aTable) throws Exception {
@@ -413,11 +439,15 @@ public class DatabaseUtils {
     }
 
     /**
-     * Executes an update. 
-     * @param aConnection Connection to use. 
-     * @param aSql SQL update to use. 
-     * @param aArgs Arguments to the update. 
-     * @return Number of rows updated. 
+     * Executes an update.
+     * 
+     * @param aConnection
+     *            Connection to use.
+     * @param aSql
+     *            SQL update to use.
+     * @param aArgs
+     *            Arguments to the update.
+     * @return Number of rows updated.
      */
     public int executeUpdate(Connection aConnection, final String aSql,
         final Object... aArgs) {
@@ -476,9 +506,11 @@ public class DatabaseUtils {
     }
 
     /**
-     * Gets the table size. 
-     * @param aTable Table. 
-     * @return Table size. 
+     * Gets the table size.
+     * 
+     * @param aTable
+     *            Table.
+     * @return Table size.
      * @throws SQLException
      */
     public int getTableSize(final String aTable) throws Exception {
@@ -494,9 +526,11 @@ public class DatabaseUtils {
     }
 
     /**
-     * Counts the results in a result set. 
-     * @param aResultSet Resultset. 
-     * @return Number of rows in the set. 
+     * Counts the results in a result set.
+     * 
+     * @param aResultSet
+     *            Resultset.
+     * @return Number of rows in the set.
      * @throws SQLException
      */
     public int countResultSet(ResultSet aResultSet) throws SQLException {
index 26387962b17ffab39958bb49953b851eab81480d..fdab8804c573a93b1127ca4cd73c948d702b05af 100644 (file)
  * 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.test.persistence;
 
 import java.util.Arrays;
 import java.util.List;
 
 /**
- * Derby database provider. 
+ * Derby database provider.
  * 
  * @author Erik Brakkee
  */
index a3044576f9f3afb7fc21ae0380d87dba4d960462..00ea47e46cc8cf03f61953abe0f5561c1c3f011c 100644 (file)
  * 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.test.persistence;
 
-
 /**
  * Database that encapsulates connection to an external database. Database
  * connection details can be configured through system properties and
index cc54799bc0ef5fcca63c11457e6751acc2d1669b..a460cc52e844271032543573af27ecc8e6184be5 100644 (file)
  * 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.test.persistence;
 
 import java.util.Arrays;
 import java.util.List;
 
 /**
- * Database provider for an external database. 
+ * Database provider for an external database.
  * 
  * @author Erik Brakkee
  */
index 223971c6cdfec69eec48daf8e224f452b2f61663..48556cfafcecf1f55690db0ff6b23a000fa788d2 100644 (file)
@@ -153,7 +153,7 @@ public class JpaBuilder implements TransactionResource<EntityManager> {
      * 
      * This method requires the transaction to succeed. Otherwise the test will
      * fail. See {@link #execute(JpaUnitOfWork, TransactionResultCallback)} and
-     * {@link RequireTransactionStatus} for more possibilities. 
+     * {@link RequireTransactionStatus} for more possibilities.
      * 
      * @param aWork
      *            Work to execute.
@@ -161,9 +161,10 @@ public class JpaBuilder implements TransactionResource<EntityManager> {
      * @return The return value of the execute method of the unit of work.
      */
     public <T> T execute(JpaUnitOfWork<T> aWork) throws Exception {
-        return execute(aWork, new RequireTransactionStatus(TransactionResult.COMMIT));
+        return execute(aWork, new RequireTransactionStatus(
+            TransactionResult.COMMIT));
     }
-    
+
     /**
      * Executes a unit of work. This creates an entitymanager and runs the
      * {@link JpaUnitOfWork#execute(EntityManager)} within a transaction,
index dcafb4260011a277589235a003f44871d80e00bf..b022234228c925369dbb86e89676b00fd0297f25 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.util.Map;
@@ -33,16 +33,20 @@ import org.dbunit.dataset.filter.ITableFilterSimple;
 public interface JpaCustomizer {
 
     /**
-     * Customizes the persistence unit through properties. 
-     * @param aPersistenceUnit Persistence unit. 
-     * @param aJpaProperties Current properties. 
+     * Customizes the persistence unit through properties.
+     * 
+     * @param aPersistenceUnit
+     *            Persistence unit.
+     * @param aJpaProperties
+     *            Current properties.
      */
     void customize(PersistenceUnitDescription aPersistenceUnit,
         Map<String, String> aJpaProperties);
 
     /**
-     * Gets the tables specific to the JPA provider. 
-     * @return Tables. 
+     * Gets the tables specific to the JPA provider.
+     * 
+     * @return Tables.
      */
     ITableFilterSimple getJpaTables();
 }
index bd62c054fcfc40381c485f9dbc8efc684ccee291..6eae6661a94963d0ff601b2e9d083c10885f2d8f 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.util.ArrayList;
@@ -20,8 +20,8 @@ import java.util.List;
 import java.util.ServiceLoader;
 
 /**
- * JPA customizer builder implements the {@link ServiceLoader} based mechanism for looking up 
- * JPA customizers. 
+ * JPA customizer builder implements the {@link ServiceLoader} based mechanism
+ * for looking up JPA customizers.
  */
 public class JpaCustomizerBuilder {
 
@@ -29,9 +29,10 @@ public class JpaCustomizerBuilder {
         .load(JpaCustomizer.class);
 
     /**
-     * Gets the customizer to use. This is a composite customizer that combines all customizers that
-     * were found. 
-     * @return JPA customizer. 
+     * Gets the customizer to use. This is a composite customizer that combines
+     * all customizers that were found.
+     * 
+     * @return JPA customizer.
      */
     public static JpaCustomizer getCustomizer() {
         List<JpaCustomizer> customizers = new ArrayList<JpaCustomizer>();
index 27462fb0bf7cc73a0c75f4e2e82183e3ecc71d14..650c55e8bd4d9fcf955a9a3dfaebdb326e9b5792 100644 (file)
@@ -62,7 +62,7 @@ public class JpaTester {
     private DataSource dataSource;
     private DatabaseUtils dbUtils;
     private JpaBuilder jpaBuilder;
-   
+
     /**
      * Constructs the tester.
      * 
@@ -81,9 +81,9 @@ 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.
+
+        // 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();
@@ -96,7 +96,8 @@ public class JpaTester {
         dbUtils.start();
         dbUtils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
 
-        jpaBuilder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db.getPassword(), persistenceUnit);
+        jpaBuilder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db
+            .getPassword(), persistenceUnit);
         jpaBuilder.start();
     }
 
@@ -116,40 +117,45 @@ public class JpaTester {
     }
 
     /**
-     * Gets the database. 
-     * @return Database. 
+     * Gets the database.
+     * 
+     * @return Database.
      */
     public Database getDb() {
         return db;
     }
 
     /**
-     * Gets the datasource. 
-     * @return Datasource. 
+     * Gets the datasource.
+     * 
+     * @return Datasource.
      */
     public DataSource getDataSource() {
         return dataSource;
     }
 
     /**
-     * Gets the database utilities. 
-     * @return Database utilities. 
+     * Gets the database utilities.
+     * 
+     * @return Database utilities.
      */
     public DatabaseUtils getDbUtils() {
         return dbUtils;
     }
 
     /**
-     * Gets the jpa builder. 
-     * @return JPA builder. 
+     * Gets the jpa builder.
+     * 
+     * @return JPA builder.
      */
     public JpaBuilder getJpaBuilder() {
         return jpaBuilder;
     }
 
     /**
-     * Gets the persistence unit. 
-     * @return Persistence unit. 
+     * Gets the persistence unit.
+     * 
+     * @return Persistence unit.
      */
     public PersistenceUnitDescription getPersistenceUnit() {
         return persistenceUnit;
index 42d37e48f1a04e2bd254b74d58e9792fb4217c5c..a46ca18b0e1b772434477dec789bcc290cb83880 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.util.logging.Level;
@@ -22,22 +22,24 @@ import org.wamblee.test.transactions.TransactionResult;
 
 /**
  * Logging the result of a transaction.
+ * 
  * @author Erik Brakkee
- *
+ * 
  */
 public class LoggingTransactionResultCallback implements
     TransactionResultCallback {
-    
-    private static final Logger LOGGER = Logger.getLogger(LoggingTransactionResultCallback.class.getName());
-    
-    private Level level; 
-    
-    public LoggingTransactionResultCallback(Level aLevel) { 
-        level = aLevel; 
+
+    private static final Logger LOGGER = Logger
+        .getLogger(LoggingTransactionResultCallback.class.getName());
+
+    private Level level;
+
+    public LoggingTransactionResultCallback(Level aLevel) {
+        level = aLevel;
     }
 
     @Override
     public void status(TransactionResult aResult) {
-        LOGGER.log(level, "Transaction result " + aResult);   
+        LOGGER.log(level, "Transaction result " + aResult);
     }
 }
index 4a16dc06d0522c863ef98252719488df1a7e1ea5..dc9fca84da6be36faa28b4c8e3f3bf4b7e0a5b1a 100644 (file)
  * 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.test.persistence;
 
-
 /**
- * Describes a persistence unit. 
+ * Describes a persistence unit.
  * 
  * @author Erik Brakkee
  */
@@ -27,9 +26,12 @@ public class PersistenceUnitDescription {
     private String unitName;
 
     /**
-     * Constructs the description. 
-     * @param aJndiName Jndi name. 
-     * @param aUnitName Persistence unit name. 
+     * Constructs the description.
+     * 
+     * @param aJndiName
+     *            Jndi name.
+     * @param aUnitName
+     *            Persistence unit name.
      */
     public PersistenceUnitDescription(String aJndiName, String aUnitName) {
         jndiName = aJndiName;
@@ -37,14 +39,14 @@ public class PersistenceUnitDescription {
     }
 
     /**
-     * @return JNDI name. 
+     * @return JNDI name.
      */
     public String getJndiName() {
         return jndiName;
     }
 
     /**
-     * Persistence unit name. 
+     * Persistence unit name.
      */
     public String getUnitName() {
         return unitName;
index 338e41a1f310c87a72edc8858a53fc690283335f..14d871bf09ff5b19852b1c090000220478c9f4ea 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import org.wamblee.test.transactions.TransactionResult;
@@ -20,26 +20,31 @@ import org.wamblee.test.transactions.TransactionResult;
 import static junit.framework.Assert.*;
 
 /**
- * Specific transaction result callback to require a specific transaction result. 
+ * Specific transaction result callback to require a specific transaction
+ * result.
+ * 
  * @author Erik Brakkee
- *
+ * 
  */
 public class RequireTransactionStatus implements TransactionResultCallback {
 
-    private TransactionResult result; 
-    
+    private TransactionResult result;
+
     /**
-     * Constructs the callback. 
-     * @param aResult Required result. 
+     * Constructs the callback.
+     * 
+     * @param aResult
+     *            Required result.
      */
-    public RequireTransactionStatus(TransactionResult aResult) { 
+    public RequireTransactionStatus(TransactionResult aResult) {
         result = aResult;
     }
-    
+
     @Override
     public void status(TransactionResult aResult) {
-        if (!result.equals(aResult)) { 
-            fail("Required transaction result was " + result + " but actual result was " + aResult);
+        if (!result.equals(aResult)) {
+            fail("Required transaction result was " + result +
+                " but actual result was " + aResult);
         }
     }
 
index 64c787ddf962eb0cca68e1e8af9adb2d8902f11f..cc5074b310187a48c88d777e645b85eac151e2ce 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import org.wamblee.test.transactions.TransactionResult;
@@ -24,8 +24,10 @@ import org.wamblee.test.transactions.TransactionResult;
  */
 public interface TransactionResultCallback {
     /**
-     * Result notification. 
-     * @param aResult Transaction result.
+     * Result notification.
+     * 
+     * @param aResult
+     *            Transaction result.
      */
     void status(TransactionResult aResult);
 }
\ No newline at end of file
index 543166662e8446ea71bef4e181284b2e58583dda..7c7a4c4d6d7f8d2171e3e12353eeb802f81d5b57 100644 (file)
@@ -12,7 +12,7 @@
  * 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.
- */ 
+ */
 /**
  * <p>
  * This package provides test library for database testing in general and JPA testing
  */
 package org.wamblee.test.persistence;
 
-
index 9d58546d2b72a32498b82cf124e76427652494cf..1fd0343f360674550ed53c1bc56d8ba3dc33c001 100644 (file)
@@ -20,24 +20,26 @@ import java.util.List;
 import javax.transaction.UserTransaction;
 
 /**
- * Transaction factory implementation that creates {@link SimpleUserTransaction} objects. 
+ * Transaction factory implementation that creates {@link SimpleUserTransaction}
+ * objects.
  * 
  * @author Erik Brakkee
- *
+ * 
  */
 public class DefaultUserTransactionFactory implements UserTransactionFactory {
 
     /**
-     * Constructs the factory. 
+     * Constructs the factory.
      */
-    public DefaultUserTransactionFactory() { 
-        // Empty. 
+    public DefaultUserTransactionFactory() {
+        // Empty.
     }
-    
+
     @Override
     public UserTransaction create(UserTransactionCallback aCallback,
         List<TransactionResource> aResources) {
-        return new SimpleUserTransaction(aCallback, aResources.toArray(new TransactionResource[0]));
+        return new SimpleUserTransaction(aCallback, aResources
+            .toArray(new TransactionResource[0]));
     }
 
 }
index a3d57102a6f2fe4d3f324e6d00598d00a65e0e4e..7cb51431c12942a1a3edc1dcec707ec885461a63 100644 (file)
@@ -86,7 +86,7 @@ public class SimpleTransactionManager {
         transactionFInishedCallback = new UserTransactionCallback() {
             @Override
             public void transactionFinished() {
-                transaction.set(factory.create(this, resources)); 
+                transaction.set(factory.create(this, resources));
             }
         };
         transaction = new ThreadSpecificProxyFactory<UserTransaction>(
@@ -120,7 +120,7 @@ public class SimpleTransactionManager {
     public UserTransaction getTransaction() {
         return transaction.getProxy();
     }
-    
+
     /**
      * Gets the thread-specific transaction object.
      * 
index ffa8925a34ef0f9479b18636c8c2b43b8b86d033..99f7a6f91785a81c5bc3814bcea375a634676ae7 100644 (file)
@@ -64,8 +64,9 @@ public class SimpleUserTransaction implements UserTransaction {
     @Override
     public void rollback() throws IllegalStateException, SecurityException,
         SystemException {
-        if ( status == Status.STATUS_NO_TRANSACTION) { 
-            throw new IllegalStateException("Rollback while not in a transaction");
+        if (status == Status.STATUS_NO_TRANSACTION) {
+            throw new IllegalStateException(
+                "Rollback while not in a transaction");
         }
         try {
             for (int i = 0; i < resources.length; i++) {
@@ -98,11 +99,11 @@ public class SimpleUserTransaction implements UserTransaction {
                         resources[i].rollback(txStates[i]);
                     }
                 } catch (Exception e) {
-                    committing = false; 
+                    committing = false;
                 }
             }
-            
-            if (!committing) { 
+
+            if (!committing) {
                 throw new HeuristicMixedException("Commit failed");
             }
         } finally {
@@ -118,8 +119,9 @@ public class SimpleUserTransaction implements UserTransaction {
 
     @Override
     public void setRollbackOnly() throws IllegalStateException, SystemException {
-        if ( status == Status.STATUS_NO_TRANSACTION) { 
-            throw new IllegalStateException("setRollbackOnly() while not in a transaction");
+        if (status == Status.STATUS_NO_TRANSACTION) {
+            throw new IllegalStateException(
+                "setRollbackOnly() while not in a transaction");
         }
         status = Status.STATUS_MARKED_ROLLBACK;
     }
index d6d47992983d13023d41f72627c3d96676879faf..67f64bee95ba9fc65b683260687c4676a00226dc 100644 (file)
@@ -15,7 +15,6 @@
  */
 package org.wamblee.test.transactions;
 
-
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -31,24 +30,27 @@ import org.wamblee.test.persistence.JpaBuilder.JpaUnitOfWork;
 
 /**
  * This utility makes sure that each invocation on a certain interface is
- * carried out within a JPA unit of work. Note that this is equivalent
- * to the sementics of a requiresNew transaction attribute. 
+ * carried out within a JPA unit of work. Note that this is equivalent to the
+ * sementics of a requiresNew transaction attribute.
  * 
  * Use {@link #getTransactionScopedEntityManager()} to get the transaction
  * scoped entity manager to pass to services.
  * 
  * 
- * For example: 
+ * For example:
+ * 
  * <pre>
  *     JpaBuilder builder = ...
  *     TransactionProxyFactory<Service> factory = new TransactionProxyFactory<Service>(
  *           builder, Service.class);
  *     Service service = new JpaService(factory.getTransactionScopedEntityManager());
  *     Service proxy = factory.getProxy(service);
- *     proxy.executeMethod(...); 
+ *     proxy.executeMethod(...);
  * </pre>
- * The above example executes the executeMethod() call on the service object within an active transaction.
- * In the constructor of the service a transaction scoped entity manager is passed.  
+ * 
+ * The above example executes the executeMethod() call on the service object
+ * within an active transaction. In the constructor of the service a transaction
+ * scoped entity manager is passed.
  * 
  * @param T
  *            Type of interface to proxy.
@@ -58,11 +60,12 @@ import org.wamblee.test.persistence.JpaBuilder.JpaUnitOfWork;
 public class TransactionProxyFactory<T> {
 
     /**
-     * Executes the call on the service within a new transaction.  
+     * Executes the call on the service within a new transaction.
      * 
      * @author Erik Brakkee
-     *
-     * @param <T> Type of the service interface. 
+     * 
+     * @param <T>
+     *            Type of the service interface.
      */
     private class UnitOfWorkInvocationHandler<T> implements InvocationHandler {
 
@@ -75,11 +78,11 @@ public class TransactionProxyFactory<T> {
         @Override
         public Object invoke(Object aProxy, final Method aMethod,
             final Object[] aArgs) throws Throwable {
-            return TransactionProxyFactory.this.jpaBuilder
-                .execute(new JpaUnitOfWork<Object>() {
+            return TransactionProxyFactory.this.jpaBuilder.execute(
+                new JpaUnitOfWork<Object>() {
                     @Override
                     public Object execute(EntityManager aEm) throws Exception {
-                        EntityManager oldEm = ENTITY_MANAGER.get(); 
+                        EntityManager oldEm = ENTITY_MANAGER.get();
                         try {
                             ENTITY_MANAGER.set(aEm);
                             return aMethod.invoke(service, aArgs);
index 1ab649ab54b3218da7ba6dc37e492f8c551de2ef..4770d78889cfca742f0a579a252cea7d4bb05f9b 100644 (file)
  */
 package org.wamblee.test.transactions;
 
-
 /**
- * Interfaces to be implemented by resources that want to participate in transactions
- * managed through {@link SimpleTransactionManager}.
+ * Interfaces to be implemented by resources that want to participate in
+ * transactions managed through {@link SimpleTransactionManager}.
  * 
  * @author Erik Brakkee
- *
+ * 
  * @param <T>
  */
 public interface TransactionResource<T> {
-    
+
     /**
-     * Begins a transaction. 
+     * Begins a transaction.
+     * 
      * @return Object that manages the transaction for the resource.
      */
-    T begin(); 
-    
+    T begin();
+
     /**
      * Rolls back a transaction.
-     * @param aT Object that manages the transaction for the resource. 
+     * 
+     * @param aT
+     *            Object that manages the transaction for the resource.
      */
-    TransactionResult rollback(T aT); 
-    
+    TransactionResult rollback(T aT);
+
     /**
-     * Commits the transaction. 
-     * @param aT Object that manages the transaction for the resource. 
+     * Commits the transaction.
+     * 
+     * @param aT
+     *            Object that manages the transaction for the resource.
      */
     TransactionResult commit(T aT);
-    
+
 }
index 162d3704886323d989e6bf99fae45c3fa995704e..82d01c3e077d442bf4f05197f0e3ff5f984be0ed 100644 (file)
 package org.wamblee.test.transactions;
 
 /**
- * Transaction result. 
+ * Transaction result.
  * 
  * @author Erik Brakkee
  */
-public enum TransactionResult { 
+public enum TransactionResult {
     /**
-     * Nothing was done. The transaction was committed or rolled back by the application. 
-     * Most likely an exception occurred and the transaction was rolled back. 
+     * Nothing was done. The transaction was committed or rolled back by the
+     * application. Most likely an exception occurred and the transaction was
+     * rolled back.
      */
-    UNKNOWN, 
-    
+    UNKNOWN,
+
     /**
-     * Transaction was committed. 
+     * Transaction was committed.
      */
     COMMIT,
-    
+
     /**
      * Tranasction was rolled back.
      */
index 09b656db040e2249b871a9eff2b8dcd5e26ec0b2..e4e85128e17f26d0acfafa2b9d3adf9b6fd00891 100644 (file)
@@ -15,6 +15,6 @@
  */
 package org.wamblee.test.transactions;
 
-public interface UserTransactionCallback { 
-    void transactionFinished(); 
+public interface UserTransactionCallback {
+    void transactionFinished();
 }
\ No newline at end of file
index c1a085923ad0c1d1d0de58d5e06e70fe0e286e24..2de15aa07e5a9dfcba22182c48145e1aaa727e2f 100644 (file)
@@ -20,12 +20,13 @@ import java.util.List;
 import javax.transaction.UserTransaction;
 
 /**
- * Factory used to create transactions. 
+ * Factory used to create transactions.
  * 
  * @author Erik Brakkee
- *
+ * 
  */
 public interface UserTransactionFactory {
 
-    UserTransaction create(UserTransactionCallback aCallback, List<TransactionResource> aResources); 
+    UserTransaction create(UserTransactionCallback aCallback,
+        List<TransactionResource> aResources);
 }
index b5e361093a2211e07798edfeef1cba540030799d..812f67cd3b0e88bd319fce1c791dc7447c3e3e55 100644 (file)
@@ -12,7 +12,7 @@
  * 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.
- */ 
+ */
 /**
  * <p>
  * This package provides basic support utilities for testing with transactions.
index 4ad8cad8a0984ffe8181b64bca68adbab94bee91..4e68bd699a09e098ca81d2c38ea6927de83f9eef 100644 (file)
@@ -64,7 +64,8 @@ public class JavaEETestInjectorFactoryTest {
     @Test
     public void testXyz() {
         EntityManager em = mock(EntityManager.class);
-        InjectorBuilder.setInjectorFactory(new JavaEETestInjectorFactory().addEntityManagerBinding(em));
+        InjectorBuilder.setInjectorFactory(new JavaEETestInjectorFactory()
+            .addEntityManagerBinding(em));
 
         X x = new X();
 
@@ -80,13 +81,14 @@ public class JavaEETestInjectorFactoryTest {
 
     public static class Y {
         @PersistenceContext
-        Integer wrongType;
+        private Integer wrongType;
     }
 
     @Test
     public void testWrongType() {
         EntityManager em = mock(EntityManager.class);
-        InjectorBuilder.setInjectorFactory(new JavaEETestInjectorFactory().addEntityManagerBinding(em));
+        InjectorBuilder.setInjectorFactory(new JavaEETestInjectorFactory()
+            .addEntityManagerBinding(em));
         Y y = new Y();
         InjectorBuilder.getInjector().inject(y);
         assertNull(y.wrongType);
@@ -97,14 +99,14 @@ public class JavaEETestInjectorFactoryTest {
     public static @interface MyAnnotation {
 
     }
-    
+
     public static class Z {
         @MyAnnotation
         private int x;
-        
+
         // any annotation will force traversal.
         @Mock
-        private Z z; 
+        private Z z;
 
     }
 
@@ -121,6 +123,5 @@ public class JavaEETestInjectorFactoryTest {
         assertEquals(100, z.x);
         assertEquals(100, z.z.x);
     }
-    
-    
+
 }
index a0ae2d83f6cbc8bab9b7ac61b3c164bf6effb717..1960dac24231169de1e5dd5a158048ea17986011 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.jndi;
 
 import static junit.framework.Assert.*;
@@ -42,7 +42,7 @@ public class StubInitiaContextFactoryTest {
         InitialContext ctx = new InitialContext();
         ctx.bind(JNDI_NAME, "hallo");
     }
-    
+
     // String based lookups.
 
     @Test
@@ -57,15 +57,15 @@ public class StubInitiaContextFactoryTest {
 
         assertEquals("hallo", obj);
     }
-    
+
     @Test(expected = NameNotFoundException.class)
-    public void testUnbind() throws Exception { 
-        testLookup(); 
-        InitialContext ctx = new InitialContext(); 
+    public void testUnbind() throws Exception {
+        testLookup();
+        InitialContext ctx = new InitialContext();
         ctx.unbind(JNDI_NAME);
         ctx = new InitialContext();
         ctx.lookup(JNDI_NAME);
-        
+
     }
 
     @Test(expected = NameNotFoundException.class)
@@ -73,11 +73,11 @@ public class StubInitiaContextFactoryTest {
         StubInitialContextFactory.register();
 
         InitialContext ctx = new InitialContext();
-        Object obj = ctx.lookup(JNDI_NAME);
+        ctx.lookup(JNDI_NAME);
     }
-    
+
     // Name based lookups
-    
+
     @Test
     public void testLookupName() throws Exception {
         StubInitialContextFactory.register();
@@ -90,11 +90,11 @@ public class StubInitiaContextFactoryTest {
 
         assertEquals("hallo", obj);
     }
-    
+
     @Test(expected = NameNotFoundException.class)
-    public void testUnbindName() throws Exception { 
-        testLookup(); 
-        InitialContext ctx = new InitialContext(); 
+    public void testUnbindName() throws Exception {
+        testLookup();
+        InitialContext ctx = new InitialContext();
         ctx.unbind(new CompositeName(JNDI_NAME));
         ctx = new InitialContext();
         ctx.lookup(new CompositeName(JNDI_NAME));
@@ -105,6 +105,6 @@ public class StubInitiaContextFactoryTest {
         StubInitialContextFactory.register();
 
         InitialContext ctx = new InitialContext();
-        Object obj = ctx.lookup(JNDI_NAME);
+        ctx.lookup(JNDI_NAME);
     }
 }
index 9a8b205ad0a2ebe0e0372c01b1a66c190644a11e..70c2c318c214486908cc7495a756204ebe936f24 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import org.junit.Test;
@@ -31,9 +31,9 @@ public class DatabaseBuilderTest {
             System.out.println(description);
         }
     }
-    
+
     @Test
-    public void testConnectionLeak() { 
+    public void testConnectionLeak() {
         Database db = DatabaseBuilder.getDatabase();
         db.start();
         assertEquals(0, db.getActiveConnections());
index a8ff4f41d472f269c78581a3d0092e771e6d2478..fdc952bff8e526acf62b949a777ed13c5a0418b4 100644 (file)
@@ -14,27 +14,26 @@ import org.wamblee.test.persistence.DatabaseUtils;
 public class DatabaseUtilsLeakTest {
 
     private Database db;
-    private DatabaseUtils dbutils; 
-    
+    private DatabaseUtils dbutils;
+
     @Before
-    public void setUp() { 
+    public void setUp() {
         db = DatabaseBuilder.getDatabase();
-        DataSource ds = db.start(); 
-        
+        DataSource ds = db.start();
+
         dbutils = new DatabaseUtils(ds);
     }
-    
+
     @After
-    public void tearDown() { 
-        db.stop(); 
+    public void tearDown() {
+        db.stop();
     }
-    
+
     @Test
     public void testLeak() throws Exception {
-        assertEquals(0, db.getActiveConnections()); 
+        assertEquals(0, db.getActiveConnections());
         dbutils.dropTables(new MyTables());
         assertEquals(0, db.getActiveConnections());
     }
-    
-    
+
 }
index 12f3923c8fcfe13aef1ad09e7e73e4ea4157abd6..e6ea7ceb4bfcf39999517b8ccffb3fb65a8959f9 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import static junit.framework.Assert.assertEquals;
@@ -52,7 +52,8 @@ public class DatabaseUtilsTestBase {
         dbutils.dropTables(new MyTables());
         dbutils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables());
 
-        builder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db.getPassword(), persistenceUnit);
+        builder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db
+            .getPassword(), persistenceUnit);
         builder.start();
 
         assertEquals(0, db.getActiveConnections());
index b7b318390f5731409b728f1032dbdd25a04a4ac5..8a0b43c8a8412491e43e8ddd2f2338943b7dc2c1 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.sql.Connection;
index a1ad9823d64f0d676c08b5754b0395798d50d89d..39515909cd11b917dd7e926c165d3cda41396f28 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import java.sql.Connection;
index 42c2378fbfc9c5ec61f614f5b78dfead7d7909e7..bffd5b9f8a03f08b9ffecd4d703ea529c06750b7 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import javax.persistence.Entity;
index ca90304a9af8e2f60065fcff7ae6062131344264..441af10c92f197d84a065d40407d32344c2f9595 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import org.wamblee.test.persistence.PersistenceUnitDescription;
index 4fee6b25ee5896318b922ae0ab8aa2a9b447981d..750dfc8701b795ec83574d4ee1aa350026d8d2d3 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import org.dbunit.dataset.DataSetException;
index 6f0049ee60c463f4f9bc2968cb4b82497b8ffe92..179453c2eb2369172ca18211aec763ef0514af9b 100644 (file)
@@ -12,7 +12,7 @@
  * 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.test.persistence;
 
 import junit.framework.AssertionFailedError;
@@ -23,15 +23,17 @@ import org.wamblee.test.transactions.TransactionResult;
 public class RequireTransactionStatusTest {
 
     @Test
-    public void testResultOk() { 
-        RequireTransactionStatus callback = new RequireTransactionStatus(TransactionResult.ROLLBACK);
+    public void testResultOk() {
+        RequireTransactionStatus callback = new RequireTransactionStatus(
+            TransactionResult.ROLLBACK);
         callback.status(TransactionResult.ROLLBACK);
-        // if we get here everything is ok. 
+        // if we get here everything is ok.
     }
-    
+
     @Test(expected = AssertionFailedError.class)
-    public void testResultWrong() { 
-        RequireTransactionStatus callback = new RequireTransactionStatus(TransactionResult.COMMIT);
+    public void testResultWrong() {
+        RequireTransactionStatus callback = new RequireTransactionStatus(
+            TransactionResult.COMMIT);
         callback.status(TransactionResult.ROLLBACK);
     }
 }
index f200de51a6460aea9a955af59982c91ecbb569a6..302911c725cc95af4b8260ffb032b2f6be4aa627 100644 (file)
@@ -27,18 +27,17 @@ import org.junit.Test;
 
 public class SimpleTransactionManagerIntegrationTest {
 
-    
     private TransactionResource resource1;
     private TransactionResource resource2;
     private Object tx1;
     private Object tx2;
 
-    private SimpleTransactionManager manager; 
-    
+    private SimpleTransactionManager manager;
+
     @Before
     public void setUp() {
-        UserTransactionFactory factory = new DefaultUserTransactionFactory(); 
-        manager = new SimpleTransactionManager(factory);     
+        UserTransactionFactory factory = new DefaultUserTransactionFactory();
+        manager = new SimpleTransactionManager(factory);
         resource1 = mock(TransactionResource.class);
         resource2 = mock(TransactionResource.class);
         tx1 = mock(Object.class);
@@ -66,13 +65,13 @@ public class SimpleTransactionManagerIntegrationTest {
     }
 
     @Test
-    public void testTwoTransactions() throws Exception { 
+    public void testTwoTransactions() throws Exception {
         UserTransaction transaction = manager.getTransaction();
         transaction.begin();
         transaction.commit();
-        
+
         transaction.begin();
-        transaction.commit();    
+        transaction.commit();
     }
-    
+
 }
index 1f7afc645306fe19d48f065815243a531be980b1..02934c8f98689295f2a31661aabfa8df027e9d23 100644 (file)
@@ -92,7 +92,7 @@ public class SimpleTransactionManagerTest {
     public void testTransactionLifeCycle() throws Exception {
         manager.getTransaction().getStatus();
         UserTransaction transaction = manager.getThreadSpecificTransaction();
-        
+
         assertNotNull(transaction);
         assertEquals(1, callbacks.size());
         callbacks.get(0).transactionFinished();
index 22bb3ff953e01b595b7f3fcd7b14a2ed290b6b54..d46ce2df551d2ab15ad5a749223d4a61e9f8f325 100644 (file)
@@ -75,13 +75,13 @@ public class TransactionProxyFactoryTestBase {
 
     @Test
     public void testEntityManagerIsPassed() throws Exception {
-        
-       
+
         final TransactionProxyFactory<Service> factory = new TransactionProxyFactory<Service>(
             jpaTester.getJpaBuilder(), Service.class);
-        Service service = new Service() { 
-            private EntityManager em = factory.getTransactionScopedEntityManager();
-            
+        Service service = new Service() {
+            private EntityManager em = factory
+                .getTransactionScopedEntityManager();
+
             @Override
             public int execute(int aValue) throws Exception {
                 assertNotNull(em);
@@ -89,14 +89,14 @@ public class TransactionProxyFactoryTestBase {
                 return 0;
             }
         };
-        
+
         final Service proxy = factory.getProxy(service);
         jpaTester.getJpaBuilder().execute(new JpaUnitOfWork<Void>() {
             @Override
             public Void execute(EntityManager aEm) throws Exception {
-                assert(aEm != null); 
+                assert (aEm != null);
                 proxy.execute(10);
-                return null; 
+                return null;
             }
         });
     }