From 8de7e216b692c68571038021c725212587e822ec Mon Sep 17 00:00:00 2001 From: rmpestano Date: Thu, 20 Aug 2015 21:16:43 -0300 Subject: [PATCH] refs #5 --- .../github/dbunit/rules/DBUnitRulesIt.java | 28 ++++++++++++++----- .../test/resources/datasets/yml/follower.yml | 4 +++ .../src/test/resources/datasets/yml/tweet.yml | 4 +++ core/src/test/resources/datasets/yml/user.yml | 3 ++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 core/src/test/resources/datasets/yml/follower.yml create mode 100644 core/src/test/resources/datasets/yml/tweet.yml create mode 100644 core/src/test/resources/datasets/yml/user.yml diff --git a/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java b/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java index 8a4095a..73394af 100644 --- a/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java +++ b/core/src/test/java/com/github/dbunit/rules/DBUnitRulesIt.java @@ -1,17 +1,18 @@ package com.github.dbunit.rules; -import com.github.dbunit.rules.api.dataset.DataSet; -import com.github.dbunit.rules.model.Follower; -import com.github.dbunit.rules.model.User; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; + +import java.util.List; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import com.github.dbunit.rules.api.dataset.DataSet; +import com.github.dbunit.rules.model.Follower; +import com.github.dbunit.rules.model.User; /** * Created by pestano on 23/07/15. @@ -113,4 +114,17 @@ public void shouldLoadUsersFromXmlDataset() { assertThat(user.getFollowers()).contains(expectedFollower); } + @Test + @DataSet(value = "yml/user.yml, yml/tweet.yml, yml/follower.yml", executeStatementsBefore = {"DELETE FROM FOLLOWER","DELETE FROM TWEET","DELETE FROM USER"}) + public void shouldLoadDataFromMultipleDataSets(){ + User user = (User) emProvider.em().createQuery("select u from User u join fetch u.tweets join fetch u.followers left join fetch u.followers where u.id = 1").getSingleResult(); + assertThat(user).isNotNull(); + assertThat(user.getId()).isEqualTo(1); + assertThat(user.getTweets()).hasSize(1); + assertEquals("dbunit rules again",user.getTweets().get(0).getContent()); + assertThat(user.getFollowers()).isNotNull().hasSize(1); + Follower expectedFollower = new Follower(2,1); + assertThat(user.getFollowers()).contains(expectedFollower); + } + } diff --git a/core/src/test/resources/datasets/yml/follower.yml b/core/src/test/resources/datasets/yml/follower.yml new file mode 100644 index 0000000..8bcaa42 --- /dev/null +++ b/core/src/test/resources/datasets/yml/follower.yml @@ -0,0 +1,4 @@ +follower: + - id: 1 + user_id: 1 + follower_id: 2 diff --git a/core/src/test/resources/datasets/yml/tweet.yml b/core/src/test/resources/datasets/yml/tweet.yml new file mode 100644 index 0000000..c45edb8 --- /dev/null +++ b/core/src/test/resources/datasets/yml/tweet.yml @@ -0,0 +1,4 @@ +tweet: + - id: abcdef12345 + content: "dbunit rules again!" + user_id: 1 \ No newline at end of file diff --git a/core/src/test/resources/datasets/yml/user.yml b/core/src/test/resources/datasets/yml/user.yml new file mode 100644 index 0000000..d8032b2 --- /dev/null +++ b/core/src/test/resources/datasets/yml/user.yml @@ -0,0 +1,3 @@ +user: + - id: 99 + name: "@realpestano" \ No newline at end of file