Search in sources :

Example 51 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.

the class ConditionTest method testConditionTailLike.

/**
 * 测试condition:tailLike功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testConditionTailLike.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testConditionTailLike.xml")
public void testConditionTailLike() {
    Account_Condition ac = new Account_Condition();
    ac.setEmailTailLike("live.cn");
    Collection<Account_> c = accountService.selectAll(ac);
    Account_[] accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(1, accounts.length);
    Assert.assertEquals("ann@live.cn", accounts[0].getEmail());
}
Also used : Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 52 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.

the class InternalCacheTest method testCacheThread.

/**
 * 这是一个展示Junit配合Groboutils进行多线程测试的例子,在这个例子中accountInsert以子线程的方式执行多次,
 * 主线程会等待子线程全部执行完后再结束
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.result.xml")
public void testCacheThread() throws Throwable {
    // 实例化 TestRunnable 类
    TestRunnable tr1, tr2;
    tr1 = new acctionSelect();
    tr2 = new acctionUpdate();
    // 把实例传递给 MTTR
    TestRunnable[] trs = { tr1, tr2 };
    MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
    // 执行MTTR和线程
    mttr.runTestRunnables();
}
Also used : TestRunnable(net.sourceforge.groboutils.junit.v1.TestRunnable) MultiThreadedTestRunner(net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 53 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.

the class NotEqualConditionTest method testConditionGreaterThan.

/**
 * 测试condition:greaterThan功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/notEqualConditionTest/testConditionGreaterThan.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/notEqualConditionTest/testConditionGreaterThan.xml")
public void testConditionGreaterThan() {
    LoginLog_Condition lc = new LoginLog_Condition(), lc2 = new LoginLog_Condition(), lc3 = new LoginLog_Condition(), lc4 = new LoginLog_Condition();
    lc.setLoginTimeGreaterThan(new Date(1));
    lc.setIdGreaterThan(0);
    Collection<LoginLog_> c = loginLogService.selectAll(lc);
    Assert.assertEquals(1, c.size());
    LoginLog_[] loginlogs = c.toArray(new LoginLog_[c.size()]);
    Assert.assertEquals("0.0.0.1", loginlogs[0].getLoginIP());
    lc2.setLoginTimeGreaterThan(new Date());
    Collection<LoginLog_> c2 = loginLogService.selectAll(lc2);
    Assert.assertEquals(0, c2.size());
    lc3.setIdGreaterThan(10);
    int count3 = loginLogService.count(lc3);
    Assert.assertEquals(0, count3);
    lc3.setIdGreaterThan(null);
    lc3.setIdGreaterOrEqual(10);
    count3 = loginLogService.count(lc3);
    Assert.assertEquals(1, count3);
    lc3.setIdGreaterOrEqual(null);
    lc3.setLoginTime(loginlogs[0].getLoginTime());
    count3 = loginLogService.count(lc3);
    Assert.assertEquals(1, count3);
    lc3.setLoginTime(null);
    lc3.setLoginTimeNotEqual(loginlogs[0].getLoginTime());
    count3 = loginLogService.count(lc3);
    Assert.assertEquals(0, count3);
    lc4.setIdGreaterThan(9);
    int count4 = loginLogService.count(lc4);
    Assert.assertEquals(1, count4);
    lc4.setIdGreaterThan(null);
    lc4.setIdLessThan(11);
    count4 = loginLogService.count(lc4);
    Assert.assertEquals(1, count4);
    lc4.setIdLessThan(10);
    count4 = loginLogService.count(lc4);
    Assert.assertEquals(0, count4);
    lc4.setIdLessThan(null);
    lc4.setIdLessOrEqual(10);
    count4 = loginLogService.count(lc4);
    Assert.assertEquals(1, count4);
    lc4.setIdLessOrEqual(null);
    lc4.setIdNotEqual(10);
    count4 = loginLogService.count(lc4);
    Assert.assertEquals(0, count4);
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) LoginLog_Condition(indi.mybatis.flying.pojo.condition.LoginLog_Condition) Date(java.util.Date) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 54 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.

the class NullOrNotTest method testNullOrNot.

/**
 * 测试NullOrNot关键字
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/nullOrNotTest/testNullOrNot.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/nullOrNotTest/testNullOrNot.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/nullOrNotTest/testNullOrNot.xml")
public void testNullOrNot() {
    Account_Condition ac = new Account_Condition();
    ac.setEmailIsNull(true);
    Collection<Account_> accountC = accountService.selectAll(ac);
    Assert.assertEquals(1, accountC.size());
    int count = accountService.count(ac);
    Assert.assertEquals(1, count);
    Account_Condition ac2 = new Account_Condition();
    ac2.setEmailIsNull(false);
    Collection<Account_> accountC2 = accountService.selectAll(ac2);
    Assert.assertEquals(1, accountC2.size());
    int count2 = accountService.count(ac2);
    Assert.assertEquals(1, count2);
    Account_Condition ac3 = new Account_Condition();
    Collection<Account_> accountC3 = accountService.selectAll(ac3);
    Assert.assertEquals(2, accountC3.size());
    int count3 = accountService.count(ac3);
    Assert.assertEquals(2, count3);
    Account_Condition ac4 = new Account_Condition();
    ac4.setRoleIsNull(true);
    Collection<Account_> accountC4 = accountService.selectAll(ac4);
    for (Account_ a : accountC4) {
        Assert.assertEquals("bob", a.getName());
    }
    int count4 = accountService.count(ac4);
    Assert.assertEquals(1, count4);
    Account_Condition ac5 = new Account_Condition();
    ac5.setRoleIsNull(false);
    Collection<Account_> accountC5 = accountService.selectAll(ac5);
    for (Account_ a : accountC5) {
        Assert.assertEquals("ann", a.getName());
    }
    int count5 = accountService.count(ac5);
    Assert.assertEquals(1, count5);
}
Also used : Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 55 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.

the class OrTest method testOr6.

/* 一个只有单独入参的或逻辑测试用例 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/orTest/testOr6.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/orTest/testOr6.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/orTest/testOr6.result.xml")
public void testOr6() {
    LoginLog_Condition lc = new LoginLog_Condition();
    lc.setAccount(new Account_Condition());
    lc.getAccount().setRole(new Role_Condition());
    ((Role_Condition) lc.getAccount().getRole()).setAccountNameEquals("ann");
    int i = loginLogService.count(lc);
    Assert.assertEquals(2, i);
    LoginLog_Condition lc2 = new LoginLog_Condition();
    lc2.setAccount(new Account_Condition());
    lc2.getAccount().setRole(new Role_Condition());
    ((Role_Condition) lc2.getAccount().getRole()).setNameEquals("admin");
    int i2 = loginLogService.count(lc2);
    Assert.assertEquals(4, i2);
}
Also used : Role_Condition(indi.mybatis.flying.pojo.condition.Role_Condition) LoginLog_Condition(indi.mybatis.flying.pojo.condition.LoginLog_Condition) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Aggregations

DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)59 Test (org.junit.Test)55 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)44 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)42 Account_ (indi.mybatis.flying.pojo.Account_)36 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)26 IfProfileValue (org.springframework.test.annotation.IfProfileValue)20 Role_ (indi.mybatis.flying.pojo.Role_)17 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)12 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 PageParam (indi.mybatis.flying.pagination.PageParam)7 Order (indi.mybatis.flying.pagination.Order)5 SortParam (indi.mybatis.flying.pagination.SortParam)5 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)5 Date (java.util.Date)3 Page (indi.mybatis.flying.pagination.Page)2 Account2_ (indi.mybatis.flying.pojo.Account2_)2 Role2_ (indi.mybatis.flying.pojo.Role2_)2