Information Technology Reference
In-Depth Information
JUnit ( http://junit.org/ ) markup to let the test runtime know that this method will initialize
components for every test run:
@Before
public void setUp() {
this.ds = new PoolingDataSource();
this.ds.setUniqueName("jdbc/testDS");
this.ds.setClassName("org.h2.jdbcx.JdbcDataSource");
this.ds.setMaxPoolSize(3);
this.ds.setAllowLocalTransactions(true);
this.ds.getDriverProperties().setProperty("URL",
"jdbc:h2:mem:db");
this.ds.getDriverProperties().setProperty("user", "sa");
this.ds.getDriverProperties().setProperty("password",
"sasa");
this.ds.init();
}
The test will start a Bitronix ( http://www.bitronix.be ) transactional data source to be used
by the persistence unit. Bitronix is the framework that defines the Poolin-
gDataSource class, which is used to wrap a data source with a transaction manager.
In order for all these components to compile, we will need to add a few extra dependen-
cies to our pom.xml file. We do this so that our classpath can have the JPA APIs, an im-
plementation of those APIs (we will use hibernate for our case), and the Bitronix
transaction manager dependency as well, as shown in the following code:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Search WWH ::




Custom Search