Search in sources :

Example 11 with DatabaseTearDown

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

the class CacheTest method testNPlusOne.

/* 一个展示n+1问题的测试用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne.datasource2.result.xml")
@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne.datasource2.result.xml")
public void testNPlusOne() {
    Role2_ r = new Role2_();
    r.setId(1);
    r.setName("root");
    role2Service.insert(r);
    Role2_ r2 = new Role2_();
    r2.setId(2);
    r2.setName("user");
    role2Service.insert(r2);
    Account2_ a = new Account2_();
    a.setId(21);
    a.setEmail("10");
    a.setRole(r);
    account2Service.insert(a);
    Account2_ a2 = new Account2_();
    a2.setId(22);
    a2.setEmail("11");
    a2.setRole(r);
    account2Service.insert(a2);
    Collection<Account2_> accounts = account2Service.selectAll(new Account2_());
    Assert.assertEquals(2, accounts.size());
}
Also used : Account2_(indi.mybatis.flying.pojo.Account2_) Role2_(indi.mybatis.flying.pojo.Role2_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 12 with DatabaseTearDown

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

the class CacheTest method testSelectWithoutRole.

/* 测试ignoreTag加到外键上后如期望一样不显示相关外键父对象,但有多重外键的情况下不影响另一外键 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSelectWithoutRole.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSelectWithoutRole.result.xml")
public void testSelectWithoutRole() {
    Role_ r = new Role_(), r2 = new Role_();
    r.setId(1);
    r.setName("root");
    roleService.insert(r);
    r2.setId(2);
    r2.setName("user");
    roleService.insert(r2);
    Account_ a = new Account_();
    a.setId(1L);
    a.setRole(r);
    a.setRoleDeputy(r2);
    a.setName("deployer");
    accountService.insert(a);
    Account_ account = accountService.selectWithoutRole(1);
    Assert.assertNull(account.getRole());
    Assert.assertEquals("2", account.getRoleDeputy().getId().toString());
    roleService.update(r);
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 2);
    m.put("name", "newUser");
    roleService.updateDirect(m);
    Account_ account2 = accountService.selectWithoutRole(1);
    Assert.assertEquals("newUser", account2.getRoleDeputy().getName());
}
Also used : HashMap(java.util.HashMap) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 13 with DatabaseTearDown

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

the class CacheTest method testClearCache.

/* 测试分页缓存的用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testClearCache.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testClearCache.result.xml")
public void testClearCache() {
    Role_ r = new Role_(), r2 = new Role_();
    r.setId(1);
    r.setName("root");
    roleService.insert(r);
    r2.setId(2);
    r2.setName("deployer");
    roleService.insert(r2);
    Account_ a = new Account_(), a2 = new Account_(), a3 = new Account_(), a4 = new Account_(), a5 = new Account_(), a6 = new Account_(), a7 = new Account_(), a8 = new Account_(), a9 = new Account_(), a10 = new Account_(), a11 = new Account_(), a12 = new Account_();
    a.setName("ann");
    accountService.insert(a);
    a2.setName("bob");
    accountService.insert(a2);
    a3.setName("caq");
    accountService.insert(a3);
    a4.setName("don");
    accountService.insert(a4);
    a5.setName("eli");
    accountService.insert(a5);
    a6.setName("fea");
    accountService.insert(a6);
    a7.setName("gus");
    accountService.insert(a7);
    a8.setName("hex");
    accountService.insert(a8);
    a9.setName("ivy");
    accountService.insert(a9);
    a10.setName("jak");
    accountService.insert(a10);
    a11.setName("kir");
    a11.setRole(r);
    accountService.insert(a11);
    a12.setName("lee");
    a12.setRole(r);
    accountService.insert(a12);
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 10));
    Collection<Account_> c = accountService.selectAll(ac);
    Page<Account_> p = new Page<>(c, ac.getLimiter());
    Assert.assertEquals(2, p.getMaxPageNum());
    Assert.assertEquals(12, p.getTotalCount());
    Assert.assertEquals(1, p.getPageNo());
    Assert.assertEquals(10, p.getPageItems().size());
    Account_Condition ac2 = new Account_Condition();
    ac2.setLimiter(new PageParam(2, 10));
    Collection<Account_> c2 = accountService.selectAll(ac2);
    Page<Account_> p2 = new Page<>(c2, ac2.getLimiter());
    Assert.assertEquals(2, p2.getMaxPageNum());
    Assert.assertEquals(12, p2.getTotalCount());
    Assert.assertEquals(2, p2.getPageNo());
    Assert.assertEquals(2, p2.getPageItems().size());
    for (Account_ temp : p2.getPageItems()) {
        Assert.assertEquals("root", temp.getRole().getName());
    }
    a11.setRole(r2);
    accountService.update(a11);
    a12.setRole(r2);
    accountService.update(a12);
    Account_Condition ac3 = new Account_Condition();
    ac3.setLimiter(new PageParam(2, 10));
    Collection<Account_> c3 = accountService.selectAll(ac3);
    Page<Account_> p3 = new Page<>(c3, ac3.getLimiter());
    Assert.assertEquals(2, p3.getMaxPageNum());
    Assert.assertEquals(12, p3.getTotalCount());
    Assert.assertEquals(2, p3.getPageNo());
    Assert.assertEquals(2, p3.getPageItems().size());
    for (Account_ temp : p3.getPageItems()) {
        Assert.assertEquals("deployer", temp.getRole().getName());
    }
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Page(indi.mybatis.flying.pagination.Page) PageParam(indi.mybatis.flying.pagination.PageParam) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 14 with DatabaseTearDown

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

the class CacheTest method testClearCache2.

/* 测试分页缓存能正确清除父对象的用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testClearCache2.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testClearCache2.result.xml")
public void testClearCache2() {
    Role_ r = new Role_(), r2 = new Role_();
    r.setId(1);
    r.setName("root");
    roleService.insert(r);
    r2.setId(2);
    r2.setName("deployer");
    roleService.insert(r2);
    Account_ a = new Account_(), a2 = new Account_(), a3 = new Account_(), a4 = new Account_(), a5 = new Account_(), a6 = new Account_(), a7 = new Account_(), a8 = new Account_(), a9 = new Account_(), a10 = new Account_(), a11 = new Account_(), a12 = new Account_();
    a.setName("ann");
    a.setEmail("");
    a.setRole(r);
    accountService.insert(a);
    a2.setName("bob");
    a2.setEmail("");
    a2.setRole(r);
    accountService.insert(a2);
    a3.setName("caq");
    a3.setEmail("");
    a3.setRole(r);
    accountService.insert(a3);
    a4.setName("don");
    a4.setEmail("");
    a4.setRole(r);
    accountService.insert(a4);
    a5.setName("eli");
    a5.setEmail("");
    a5.setRole(r);
    accountService.insert(a5);
    a6.setName("fea");
    a6.setEmail("");
    a6.setRole(r);
    accountService.insert(a6);
    a7.setName("gus");
    a7.setEmail("");
    a7.setRole(r);
    accountService.insert(a7);
    a8.setName("hex");
    a8.setEmail("");
    a8.setRole(r);
    accountService.insert(a8);
    a9.setName("ivy");
    a9.setEmail("");
    a9.setRole(r);
    accountService.insert(a9);
    a10.setName("jak");
    a10.setEmail("");
    a10.setRole(r);
    accountService.insert(a10);
    a11.setName("kir");
    a11.setEmail("");
    a11.setRole(r);
    accountService.insert(a11);
    a12.setName("lee");
    a12.setEmail("");
    a12.setRole(r);
    accountService.insert(a12);
    Role_ role = roleService.select(1);
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(2, 10));
    ac.setEmail("");
    Role_ rc = new Role_();
    rc.setId(1);
    ac.setRole(rc);
    Collection<Account_> c = accountService.selectAll(ac);
    Page<Account_> p = new Page<>(c, ac.getLimiter());
    Assert.assertEquals(2, p.getPageItems().size());
    for (Account_ temp : p.getPageItems()) {
        Assert.assertEquals("root", temp.getRole().getName());
    }
    Account_Condition ac1 = new Account_Condition();
    ac1.setLimiter(new PageParam(2, 10));
    ac1.setEmail("");
    Role_ rc1 = new Role_();
    rc1.setId(1);
    ac1.setRole(rc1);
    Collection<Account_> c1 = accountService.selectAll(ac1);
    role.setName("rootNew");
    roleService.update(role);
    Account_Condition ac2 = new Account_Condition();
    ac2.setLimiter(new PageParam(2, 10));
    ac2.setEmail("");
    Role_ rc2 = new Role_();
    rc2.setId(1);
    ac2.setRole(rc2);
    Collection<Account_> c2 = accountService.selectAll(ac2);
    Page<Account_> p2 = new Page<>(c2, ac2.getLimiter());
    Assert.assertEquals(2, p2.getPageItems().size());
    for (Account_ temp : p2.getPageItems()) {
        Assert.assertEquals("rootNew", temp.getRole().getName());
    }
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Page(indi.mybatis.flying.pagination.Page) PageParam(indi.mybatis.flying.pagination.PageParam) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 15 with DatabaseTearDown

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

the class CacheTest method testUpdateDirect3.

/* 测试在查询对象查询的情况下,缓存确实生效的用例 */
// @Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect3() {
    Role_ r = new Role_();
    r.setId(1);
    r.setName("ann");
    roleService.insert(r);
    Account_ a = new Account_();
    a.setId(1L);
    a.setRole(r);
    a.setEmail("email");
    accountService.insert(a);
    Account_Condition ac = new Account_Condition();
    ac.setEmailLike("mai");
    Collection<Account_> c = accountService.selectAll(ac);
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 1);
    m.put("name", "bob");
    roleService.updateDirect(m);
    Account_Condition ac2 = new Account_Condition();
    ac2.setEmailLike("mai");
    Collection<Account_> c2 = accountService.selectAll(ac2);
    for (Account_ t : c2) {
        Assert.assertEquals("ann", t.getRole().getName());
    }
}
Also used : HashMap(java.util.HashMap) Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

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