Search in sources :

Example 6 with PageParam

use of indi.mybatis.flying.pagination.PageParam in project mybatis.flying by limeng32.

the class CacheTest method testPagination.

@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPagination.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPagination.result.xml")
public void testPagination() {
    String name1 = "ann", name2 = "bob", name3 = "carl", name4 = "duke";
    Account_ a1 = new Account_();
    a1.setId(1L);
    a1.setName(name1);
    accountService.insert(a1);
    Account_ a2 = new Account_();
    a2.setId(2L);
    a2.setName(name2);
    accountService.insert(a2);
    Account_ a3 = new Account_();
    a3.setId(3L);
    a3.setName(name3);
    accountService.insert(a3);
    Account_ a4 = new Account_();
    a4.setId(4L);
    a4.setName(name4);
    accountService.insert(a4);
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 2));
    Collection<Account_> c1 = accountService.selectAll(ac);
    Assert.assertEquals(2, c1.size());
    for (Account_ a : c1) {
        if (a.getId() == 1) {
            Assert.assertEquals(name1, a.getName());
        } else {
            Assert.assertEquals(name2, a.getName());
        }
    }
    Assert.assertEquals(2, ac.getLimiter().getMaxPageNum());
    ac.setLimiter(new PageParam(1, 2));
    c1 = accountService.selectAll(ac);
    Assert.assertEquals(2, ac.getLimiter().getMaxPageNum());
    accountService.delete(a1);
    accountService.delete(a2);
    accountService.delete(a3);
    accountService.delete(a4);
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) PageParam(indi.mybatis.flying.pagination.PageParam) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 7 with PageParam

use of indi.mybatis.flying.pagination.PageParam in project mybatis.flying by limeng32.

the class CacheTest method testUpdateDirect4.

/* 测试在查询对象查询的情况下,缓存确实生效的用例 */
// @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 testUpdateDirect4() {
    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.setLimiter(new PageParam(1, 1));
    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.setLimiter(new PageParam(1, 1));
    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) PageParam(indi.mybatis.flying.pagination.PageParam) 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)7 PageParam (indi.mybatis.flying.pagination.PageParam)7 Account_ (indi.mybatis.flying.pojo.Account_)6 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)6 Test (org.junit.Test)6 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)5 IfProfileValue (org.springframework.test.annotation.IfProfileValue)5 Role_ (indi.mybatis.flying.pojo.Role_)4 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)3 Order (indi.mybatis.flying.pagination.Order)3 SortParam (indi.mybatis.flying.pagination.SortParam)3 Page (indi.mybatis.flying.pagination.Page)2 HashMap (java.util.HashMap)2 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)1