Skip to content

Commit

Permalink
fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Aug 21, 2015
1 parent 0d16e04 commit 2b72890
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<configuration>
<parallel>classes</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<reuseForks>true</reuseForks>
<reuseForks>false</reuseForks>
<includes>
<include>**/*It.java</include>
<include>**/*Test.java</include>
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/com/github/dbunit/rules/DBUnitRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public class DBUnitRule implements MethodRule {
private DBUnitRule() {
}

public final synchronized static DBUnitRule instance(Connection connection) {
public final static DBUnitRule instance(Connection connection) {
return instance(new ConnectionHolderImpl(connection));
}

public final synchronized static DBUnitRule instance(String executorName, Connection connection) {
public final static DBUnitRule instance(String executorName, Connection connection) {
return instance(executorName,new ConnectionHolderImpl(connection));
}

public final synchronized static DBUnitRule instance(ConnectionHolder connectionHolder) {
public final static DBUnitRule instance(ConnectionHolder connectionHolder) {
return instance(DataSetExecutorImpl.DEFAULT_EXECUTOR_ID,connectionHolder);
}

public final synchronized static DBUnitRule instance(String executorName, ConnectionHolder connectionHolder) {
public final static DBUnitRule instance(String executorName, ConnectionHolder connectionHolder) {

DBUnitRule instance = new DBUnitRule();
instance.init(executorName, connectionHolder);
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.github.dbunit.rules.api.dataset.DataSet;
import com.github.dbunit.rules.api.dataset.SeedStrategy;
import com.github.dbunit.rules.dataset.DataSetExecutorImpl;
import com.github.dbunit.rules.model.Follower;
import com.github.dbunit.rules.model.User;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.sql.SQLException;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -127,4 +131,9 @@ public void shouldLoadDataFromMultipleDataSets(){
assertThat(user.getFollowers()).contains(expectedFollower);
}

@AfterClass//optional
public static void close() throws SQLException {
DataSetExecutorImpl.getExecutorById(DataSetExecutorImpl.DEFAULT_EXECUTOR_ID).getConnection().close();
}

}
25 changes: 10 additions & 15 deletions core/src/test/java/com/github/dbunit/rules/MultipleDataSetsIt.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

import java.sql.SQLException;
import java.util.List;

import com.github.dbunit.rules.dataset.DataSetExecutorImpl;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -36,9 +39,6 @@ public class MultipleDataSetsIt {
@Rule
public DBUnitRule exec2Rule = DBUnitRule.instance("exec2",emProvider2.getConnection());

@Rule
public DBUnitRule defaultExecutorRule = DBUnitRule.instance(emProvider.getConnection());


@Test
@DataSet(value = "datasets/yml/users.yml",disableConstraints = true, executorId = "exec1")
Expand Down Expand Up @@ -148,18 +148,6 @@ public void shouldSeedUserDataSet2() {
assertThat(user.getId()).isEqualTo(1);
}

@Test
@DataSet(value = "datasets/yml/users.yml")
public void shouldLoadUserFollowersWithDefaultExecutor() {
User user = (User) emProvider.em().createQuery("select u from User u left join fetch u.followers where u.id = 1").getSingleResult();
assertThat(user).isNotNull();
assertThat(user.getId()).isEqualTo(1);
assertThat(user.getTweets()).hasSize(1);
assertEquals(user.getTweets().get(0).getContent(), "dbunit rules!");
assertThat(user.getFollowers()).isNotNull().hasSize(1);
Follower expectedFollower = new Follower(2,1);
assertThat(user.getFollowers()).contains(expectedFollower);
}

@Test
@DataSet(value = "datasets/yml/users.yml", executorId = "exec1")
Expand Down Expand Up @@ -241,4 +229,11 @@ public void shouldLoadUsersFromXmlDataset2() {
assertThat(user.getFollowers()).contains(expectedFollower);
}


@AfterClass//optional
public static void close() throws SQLException {
DataSetExecutorImpl.getExecutorById("exec1").getConnection().close();
DataSetExecutorImpl.getExecutorById("exec2").getConnection().close();
}

}

0 comments on commit 2b72890

Please sign in to comment.