This library provides Matchers for query conditions (cb.query().setXXX) and for fetching column (cb.specify().columnXXX).
You can use these matchers by import statically org.dbflute.testing.DBFluteMatchers. Please refer to JavaDoc API for complete list of APIs.
These matchers are intended to use with assertThat method.
To test condition for column, use hasCondition with a operator matcher.
assertThat(cb, hasCondition("memberName", equal("John Doe")));
The first argument (“memberName”) is a String of column name. This is a case-insensitive and accepting both camel case and snake case.
You can pass any Matcher instance to the operator matcher (equal(...) in above).
assertThat(cb, hasCondition("memberName", equal(startsWith("John"))));
cb.query().queryMemberStatus().setMemberStatusName_NotEqual("DEL"); cb.query().queryMemberServiceAsOne().queryServiceRank().setRankName_Equal("VIP"); assertThat(cb, hasRelation("memberStatus", hasCondition("memberName", notEqual("DEL")))); assertThat(cb, hasRelation("memberService.serviceRank", hasCondition("rankName", equal("ACT"))));
cb.specify().columnMemberName(); assertThat(cb, shouldSelect("memberName"));
cb.specify().specifyMemberStatus().columnMemberStatusName(); cb.specify().specifyMemberServiceAsOne().specifyServiceRank().columnServiceRankName(); assertThat(cb, shouldSelect("memberStatus.memberStatusName")); assertThat(cb, shouldSelect("memberService.serviceRank.serviceRankName"));
public class FooTest { @Rule public AccessContextInitializer ac = new AccessContextInitializer("foo"); @AutoWired MemberBhv bhv; @Test public void insert() { Member m = new Member(); m.setMemberName("John Doe"); bhv.insert(m); assertThat(m.getRegisterUser(), is("foo")); } }
@DatabaseTests is a JUnit @Category annotation. Please refer to JUnit wiki for details of categories.
<plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludedGroups>org.dbflute.testing.category.DatabaseTests</excludedGroups> </configuration> </plugin>