de.akquinet.jbosscc.needle.db
Class DatabaseTestcase

java.lang.Object
  extended by de.akquinet.jbosscc.needle.db.DatabaseTestcase
All Implemented Interfaces:
InjectionProvider<Object>, InjectionVerifier
Direct Known Subclasses:
DatabaseRule, DatabaseTestcase, DatabaseTestRule

public class DatabaseTestcase
extends Object
implements InjectionProvider<Object>

Base class for a database test case. Executes optional database operation on test setup and tear down. May be used as an injection provider for EntityManager, EntityManagerFactory and EntityTransaction.

See Also:
InjectionProvider, DBOperation

Constructor Summary
DatabaseTestcase()
          Creates an instance of DatabaseTestcase with the global configured persistence unit name and the global configured DBOperation.
DatabaseTestcase(Class<?>... clazzes)
          Deprecated. 
DatabaseTestcase(DBOperation dbOperation)
          Creates an instance of DatabaseTestcase with the global configured persistence unit name and overrides the global configured DBOperation with the given database operation.
DatabaseTestcase(DBOperation dbOperation, Class<?>... clazzes)
          Deprecated. 
DatabaseTestcase(String persistenceUnitName)
          Creates an instance of DatabaseTestcase with the given persistence unit name and the global configured DBOperation.
DatabaseTestcase(String persistenceUnitName, DBOperation dbOperation)
          Creates an instance of DatabaseTestcase with the given persistence unit name and overrides the global configured DBOperation with the given database operation.
 
Method Summary
protected  void after()
          Execute tear down database operation, if configured.
protected  void before()
          Execute setup database operation, if configured.
 javax.persistence.EntityManager getEntityManager()
          Returns the EntityManager.
 javax.persistence.EntityManagerFactory getEntityManagerFactory()
          Returns the EntityManagerFactory.
 Object getInjectedObject(Class<?> injectionPointType)
          Provides an instance of T.
 Object getKey(InjectionTargetInformation injectionTargetInformation)
          Returns a key object, which identifies the provided object.
 TransactionHelper getTransactionHelper()
          Returns an instance of TransactionHelper
 boolean verify(InjectionTargetInformation injectionTargetInformation)
          Verifies the injection target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseTestcase

public DatabaseTestcase()
Creates an instance of DatabaseTestcase with the global configured persistence unit name and the global configured DBOperation.

See Also:
DBOperation

DatabaseTestcase

public DatabaseTestcase(DBOperation dbOperation)
Creates an instance of DatabaseTestcase with the global configured persistence unit name and overrides the global configured DBOperation with the given database operation.

Parameters:
dbOperation - database operation to execute on test setup and tear down
See Also:
DBOperation

DatabaseTestcase

public DatabaseTestcase(String persistenceUnitName)
Creates an instance of DatabaseTestcase with the given persistence unit name and the global configured DBOperation.

Parameters:
persistenceUnitName - the name of the persistence unit
See Also:
DBOperation

DatabaseTestcase

public DatabaseTestcase(String persistenceUnitName,
                        DBOperation dbOperation)
Creates an instance of DatabaseTestcase with the given persistence unit name and overrides the global configured DBOperation with the given database operation.

Parameters:
persistenceUnitName - the name of the persistence unit
dbOperation - database operation to execute on test setup and tear down
See Also:
DBOperation

DatabaseTestcase

@Deprecated
public DatabaseTestcase(Class<?>... clazzes)
Deprecated. 

Creates an instance of DatabaseTestcase for the given entity classes by using the configured hibernate specific configuration file (*cfg.xml) and use the global configured DBOperation.

Parameters:
clazzes - the entity classes
See Also:
DBOperation

DatabaseTestcase

@Deprecated
public DatabaseTestcase(DBOperation dbOperation,
                                   Class<?>... clazzes)
Deprecated. 

Creates an instance of DatabaseTestcase for the given entity classes by using the configured hibernate specific configuration file (*cfg.xml) and overrides the global configured DBOperation with the give database operation.

Parameters:
dbOperation - database operation to execute on test setup and tear down
clazzes - the entity classes
See Also:
DBOperation
Method Detail

after

protected void after()
              throws Exception
Execute tear down database operation, if configured.

Throws:
Exception - thrown if an error occurs

before

protected void before()
               throws Exception
Execute setup database operation, if configured.

Throws:
Exception - thrown if an error occurs

getEntityManager

public javax.persistence.EntityManager getEntityManager()
Returns the EntityManager.

Returns:
EntityManager.

getEntityManagerFactory

public javax.persistence.EntityManagerFactory getEntityManagerFactory()
Returns the EntityManagerFactory.

Returns:
EntityManagerFactory.

getTransactionHelper

public TransactionHelper getTransactionHelper()
Returns an instance of TransactionHelper

Returns:
TransactionHelper
See Also:
TransactionHelper

getInjectedObject

public Object getInjectedObject(Class<?> injectionPointType)
Description copied from interface: InjectionProvider
Provides an instance of T.

Specified by:
getInjectedObject in interface InjectionProvider<Object>
Parameters:
injectionPointType - the type of the injection target.
Returns:
instance of T

verify

public boolean verify(InjectionTargetInformation injectionTargetInformation)
Description copied from interface: InjectionVerifier
Verifies the injection target.

Specified by:
verify in interface InjectionVerifier
Parameters:
injectionTargetInformation - information about the injection point
Returns:
true, if the provided object is injectable to the given injection information, otherwise false.

getKey

public Object getKey(InjectionTargetInformation injectionTargetInformation)
Description copied from interface: InjectionProvider
Returns a key object, which identifies the provided object.

Specified by:
getKey in interface InjectionProvider<Object>
Parameters:
injectionTargetInformation - information about the injection point
Returns:
the key of the provided object
See Also:
NeedleTestcase.getInjectedObject(Object)


Copyright © 2013 akquinet AG. All Rights Reserved.