org.nuiton.topia
Class TopiaDatabase

java.lang.Object
  extended by org.junit.rules.TestWatcher
      extended by org.nuiton.topia.TopiaDatabase
All Implemented Interfaces:
org.junit.rules.TestRule

public class TopiaDatabase
extends org.junit.rules.TestWatcher

Put this class as a Rule in test to obtain a new isolated db for each test.

Here is a simple example of usage :

 public class MyTest {

   \@Rule
   public final TopiaDatabase db = new TopiaDatabase();

   \@Test
   public void testMethod() throws TopiaException {

       TopiaContext tx = db.beginTransaction();
       ...
 }
 
The db created will be unique for each test method (and for each build also).

You don't need to close any transaction, it will be done for you and the end of each method test.

Since:
2.6.8
Author:
tchemit

Field Summary
static String TIMESTAMP
          A time-stamp, allow to make multiple build and keep the tests data.
 
Constructor Summary
TopiaDatabase()
           
TopiaDatabase(String configurationPath)
           
 
Method Summary
 org.nuiton.topia.TopiaContext beginTransaction()
           
 void finished(org.junit.runner.Description description)
           
 Properties getDbConfiguration()
           
 org.nuiton.topia.TopiaContext getRootCtxt()
           
 File getTestBasedir()
           
static File getTestSpecificDirectory(Class<?> testClassName, String methodName)
           
protected  void onDbConfigurationCreate(Properties configuration, File testDir, String dbPath)
           
protected  void starting(org.junit.runner.Description description)
           
 
Methods inherited from class org.junit.rules.TestWatcher
apply, failed, succeeded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMESTAMP

public static final String TIMESTAMP
A time-stamp, allow to make multiple build and keep the tests data.

Constructor Detail

TopiaDatabase

public TopiaDatabase()

TopiaDatabase

public TopiaDatabase(String configurationPath)
Method Detail

starting

protected void starting(org.junit.runner.Description description)
Overrides:
starting in class org.junit.rules.TestWatcher

finished

public void finished(org.junit.runner.Description description)
Overrides:
finished in class org.junit.rules.TestWatcher

getTestBasedir

public File getTestBasedir()

getRootCtxt

public org.nuiton.topia.TopiaContext getRootCtxt()

getDbConfiguration

public Properties getDbConfiguration()

beginTransaction

public org.nuiton.topia.TopiaContext beginTransaction()
                                               throws org.nuiton.topia.TopiaException
Throws:
org.nuiton.topia.TopiaException

onDbConfigurationCreate

protected void onDbConfigurationCreate(Properties configuration,
                                       File testDir,
                                       String dbPath)

getTestSpecificDirectory

public static File getTestSpecificDirectory(Class<?> testClassName,
                                            String methodName)


Copyright © 2004-2012 CodeLutin. All Rights Reserved.