public abstract class ContainerTest extends Object implements TestRunnerFacade.ContextAware, TestRunnerFacade.Initializable, TestRunnerFacade.TransactionAware
Note that any JUnit related features like @Before, @After and so on will run in the client JVM and not on the server.
You can, however, override the doInit method to perform initialization tasks and use the serviceLocator to perform CDI and JNDI lookups in the container.
Note that the container will have to provide an EntityManager producer so we can inject it into our test class.
The ContainerTest provides a TxHandler instance that can be used to control the transaction if necessary. When entering the test method, we will have a running transaction and it will be automatically committed if necessary after completing the test.
Parameterized tests are not supported.
| Modifier and Type | Field and Description |
|---|---|
protected org.jboss.logging.Logger |
_log |
protected javax.persistence.EntityManager |
em
EntityManager provided by the container.
|
protected ch.inftec.ju.db.JuEmUtil |
emUtil
JuEmUtil instance wrapped around the EntityManager.
|
protected ServiceLocator |
serviceLocator
ServiceLocator instance that can be used to lookup JNDI or CDI objects on the server.
|
ContainerTestRunnerRule |
testRunnerRule
Rule that runs the method statements on the remote JBoss container VM
|
protected ch.inftec.ju.db.TxHandler |
txHandler
TxHandler that can be used to control the DB transaction.
|
| Constructor and Description |
|---|
ContainerTest() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doInit()
Extending classes can override this method to perform custom initialization.
|
protected Path |
getLocalPath(Path relativePath,
boolean createParentDirectories)
Gets a Path instance relative to the 'local' test (rather than the JBoss server context).
|
protected Path |
getLocalPath(String relativePath,
boolean createParentDirectories)
Gets a Path instance relative to the 'local' test (rather than the JBoss server context).
|
void |
init()
Initializer method that is called before the unit test is executed.
|
protected void |
initFrom(ContainerTest hostTest)
Initializes the context and txHandler fields from the specified host test.
|
void |
setContext(TestRunnerFacade.TestRunnerContext context)
Sets the TestRunnerContext
|
void |
setTxHandler(ch.inftec.ju.db.TxHandler txHandler)
Sets the TxHandler used to control the transaction.
|
protected org.jboss.logging.Logger _log
public ContainerTestRunnerRule testRunnerRule
protected javax.persistence.EntityManager em
protected ch.inftec.ju.db.JuEmUtil emUtil
protected ch.inftec.ju.db.TxHandler txHandler
protected ServiceLocator serviceLocator
Note that the ServiceLocator is not configured to lookup remote objects
public final void setContext(TestRunnerFacade.TestRunnerContext context)
TestRunnerFacade.ContextAwaresetContext in interface TestRunnerFacade.ContextAwarepublic void setTxHandler(ch.inftec.ju.db.TxHandler txHandler)
TestRunnerFacade.TransactionAwaresetTxHandler in interface TestRunnerFacade.TransactionAwaretxHandler - TxHandlerpublic final void init()
TestRunnerFacade.InitializableThe method will be called within the same EJB / transaction context as the test method
init in interface TestRunnerFacade.Initializableprotected void doInit()
protected void initFrom(ContainerTest hostTest)
Can be used if we want to call a test from another test.
hostTest - Test to load settings fromprotected final Path getLocalPath(String relativePath, boolean createParentDirectories)
relativePath - Relative path like target/file.xmlcreateParentDirectories - If true, the parent directories of the path are created if necessaryprotected final Path getLocalPath(Path relativePath, boolean createParentDirectories)
relativePath - Relative path like target/file.xmlcreateParentDirectories - If true, the parent directories of the path are created if necessaryCopyright © 2015. All rights reserved.