Skip to content

Commit

Permalink
refs #3
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Jul 30, 2015
1 parent 62ea672 commit 8e50be9
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 22 deletions.
25 changes: 23 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,29 @@
<scope>provided</scope>
</dependency>



</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<reuseForks>true</reuseForks>
<includes>
<include>**/*It.java</include>
<include>**/*Test.java</include>
</includes>
<systemPropertyVariables>
<java.util.logging.config.file>
src/test/resources/logging.properties
</java.util.logging.config.file>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void shouldLoadUserFollowers() {
assertThat(user.getFollowers()).contains(expectedFollower);
}

/*@Test
@Test
@DataSet(value = "datasets/json/users.json")
public void shouldLoadUsersFromJsonDataset() {
User user = (User) emProvider.em().createQuery("select u from User u left join fetch u.followers where u.id = 1").getSingleResult();
Expand All @@ -76,6 +76,6 @@ public void shouldLoadUsersFromXmlDataset() {
assertThat(user.getFollowers()).isNotNull().hasSize(1);
Follower expectedFollower = new Follower(2,1);
assertThat(user.getFollowers()).contains(expectedFollower);
} */
}

}
29 changes: 26 additions & 3 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
<scope>test</scope>
</dependency>

<dependency>
<!-- see DeltaspikeUsingInterceptorIt -->
<groupId>com.github.dbunit-rules</groupId>
<artifactId>jpa</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-test-control-module-api</artifactId>
Expand Down Expand Up @@ -147,13 +155,28 @@
<scope>test</scope>
</dependency>




</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkCount>0</forkCount>
<threadCount>0</threadCount>
<reuseForks>false</reuseForks>
<includes>
<include>**/*It.java</include>
<include>**/*Test.java</include>
</includes>
<systemPropertyVariables>
<java.util.logging.config.file>
src/test/resources/logging.properties
</java.util.logging.config.file>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/java/org/example/CdiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class CdiConfig {

@Produces
@Dependent
@PersistenceContext(unitName = "customerdb")
@PersistenceContext(unitName = "customerDB")
private EntityManager entityManager;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dbunit.rules.examples;

import com.github.dbunit.rules.jpa.EntityManagerProvider;
import org.example.CdiConfig;
import org.hibernate.Session;
import org.hibernate.internal.SessionImpl;
Expand All @@ -9,6 +10,7 @@
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.Specializes;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
Expand All @@ -26,19 +28,14 @@
@ApplicationScoped
public class CdiTestConfig extends CdiConfig {

private EntityManagerFactory emf;
private EntityManager em;


@Produces
public EntityManager produce(){
if(emf == null){
emf = Persistence.createEntityManagerFactory("customerTestDb");
}
if(em == null || !em.isOpen()){
em = emf.createEntityManager();
}
return em;
synchronized (this){
return EntityManagerProvider.instance(System.getProperty("db")).em();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.annotation.concurrent.NotThreadSafe;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import java.sql.Connection;
Expand All @@ -29,6 +30,10 @@
@RunWith(CdiTestRunner.class)
public class DeltaspikeIt {

static {
System.setProperty("db","customerDB");
}

@Inject
EntityManager entityManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
@DataSetInterceptor
public class DeltaspikeUsingInterceptorIt {

static {
System.setProperty("db","interceptorDB");
}

@Inject
EntityManager entityManager;

Expand Down
21 changes: 20 additions & 1 deletion examples/src/test/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="customerTestDb" transaction-type="RESOURCE_LOCAL">
<persistence-unit name="customerDB" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<class>org.example.jpadomain.Company</class>
Expand All @@ -19,4 +19,23 @@

</persistence-unit>

<persistence-unit name="interceptorDB" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<class>org.example.jpadomain.Company</class>
<class>org.example.jpadomain.Contact</class>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:interceptor;DB_CLOSE_DELAY=-1" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />

</properties>

</persistence-unit>

</persistence>
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<forkCount>2</forkCount>
<threadCount>4</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
<reuseForks>false</reuseForks>
<includes>
<include>**/*It.java</include>
<include>**/*Test.java</include>
Expand Down

0 comments on commit 8e50be9

Please sign in to comment.