Search in sources :

Example 1 with Order

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

the class AccountTest method testSorter.

/**
 * 测试sorter功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testSorter.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testSorter.xml")
public void testSorter() {
    Account_Condition ac = new Account_Condition();
    ac.setSorter(new SortParam(new Order(Account_Condition.field_name, Conditionable.Sequence.desc)));
    Collection<Account_> c = accountService.selectAll(ac);
    Account_[] accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals("ann", accounts[3].getName());
    ac.setSorter(new SortParam(new Order(Account_Condition.field_name, Conditionable.Sequence.desc), new Order(Account_Condition.field_password, Conditionable.Sequence.desc)));
    c = accountService.selectAll(ac);
    accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(new Long(4), accounts[0].getId());
    ac.setSorter(new SortParam(new Order(Account_Condition.field_name, Conditionable.Sequence.desc), new Order(Account_Condition.field_name, Conditionable.Sequence.asc)));
    c = accountService.selectAll(ac);
    accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals("ann", accounts[3].getName());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) SortParam(indi.mybatis.flying.pagination.SortParam) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 2 with Order

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

the class CacheTest method testPaginationUsingCacheIndeed.

/* 一个证明分页确实使用了缓存的测试用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testPaginationUsingCacheIndeed.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPaginationUsingCacheIndeed.result.xml")
public void testPaginationUsingCacheIndeed() {
    Role_ role1 = new Role_(), role2 = new Role_(), role3 = new Role_();
    role1.setName("normal");
    roleService.insert(role1);
    role2.setName("silver");
    roleService.insert(role2);
    role3.setName("gold");
    roleService.insert(role3);
    Role_Condition rc = new Role_Condition();
    rc.setLimiter(new PageParam(1, 2));
    rc.setSorter(new SortParam(new Order("name", Conditionable.Sequence.asc)));
    Collection<Role_> c1 = roleService.selectAll(rc);
    Assert.assertEquals(2, c1.size());
    Role_[] roles = c1.toArray(new Role_[c1.size()]);
    Assert.assertEquals("gold", roles[0].getName());
    Map<String, Object> m = new HashMap<>(4);
    m.put("name", "gold1");
    m.put("id", roles[0].getId());
    roleService.updateDirect(m);
    Role_Condition rc2 = new Role_Condition();
    rc2.setLimiter(new PageParam(1, 2));
    rc2.setSorter(new SortParam(new Order("name", Conditionable.Sequence.asc)));
    Collection<Role_> c2 = roleService.selectAll(rc2);
    Assert.assertEquals(2, c2.size());
    Role_[] roles2 = c2.toArray(new Role_[c2.size()]);
    Assert.assertEquals("gold", roles2[0].getName());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Role_Condition(indi.mybatis.flying.pojo.condition.Role_Condition) HashMap(java.util.HashMap) PageParam(indi.mybatis.flying.pagination.PageParam) Role_(indi.mybatis.flying.pojo.Role_) SortParam(indi.mybatis.flying.pagination.SortParam) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 3 with Order

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

the class SelectOneTest method testSelectOne2.

/**
 * 测试selectOne2
 */
@Test
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/selectOneTest/testSelectOne2.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/selectOneTest/testSelectOne2.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/selectOneTest/testSelectOne2.result.xml")
public void testSelectOne2() {
    Account_ a1 = new Account_();
    a1.setName("ann");
    a1.setEmail("ann@live.cn");
    accountService.insert(a1);
    Account_ a2 = new Account_();
    a2.setName("ann");
    a2.setEmail("bob@live.cn");
    accountService.insert(a2);
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 2));
    ac.setSorter(new SortParam(new Order("id", Sequence.asc)));
    ac.setName("ann");
    Account_ account = accountService.selectOne(ac);
    Assert.assertEquals("ann@live.cn", account.getEmail());
    Assert.assertNull(ac.getLimiter());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) PageParam(indi.mybatis.flying.pagination.PageParam) SortParam(indi.mybatis.flying.pagination.SortParam) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 4 with Order

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

the class AccountTest method testLimiter.

/**
 * 测试limiter功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testLimiter.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testLimiter.xml")
public void testLimiter() {
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 2));
    Collection<Account_> c = accountService.selectAll(ac);
    Account_[] accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(2, accounts.length);
    Assert.assertEquals(1, accounts[0].getId().intValue());
    Assert.assertEquals(2, accounts[1].getId().intValue());
    Assert.assertEquals(2, ac.getLimiter().getMaxPageNum());
    ac.setSorter(new SortParam(new Order(Account_Condition.field_id, Conditionable.Sequence.desc)));
    c = accountService.selectAll(ac);
    accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(2, accounts.length);
    Assert.assertEquals(4, accounts[0].getId().intValue());
    Assert.assertEquals(3, accounts[1].getId().intValue());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) PageParam(indi.mybatis.flying.pagination.PageParam) SortParam(indi.mybatis.flying.pagination.SortParam) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 5 with Order

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

the class ConditionTest method testSorterWithMultiAssociation.

/**
 * 测试多重外键情况下sorter是否能正确发挥作用
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testSorterWithMultiAssociation.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/conditionTest/testSorterWithMultiAssociation.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testSorterWithMultiAssociation.xml")
public void testSorterWithMultiAssociation() {
    Role_Condition rc1 = new Role_Condition();
    rc1.setName("role1");
    Role_Condition rc2 = new Role_Condition();
    rc2.setName("role2");
    Account_Condition ac = new Account_Condition();
    ac.setRole(rc1);
    ac.setRoleDeputy(rc2);
    ac.setSorter(new SortParam(new Order("name", Sequence.asc)));
    Collection<Account_> accountC = accountService.selectAll(ac);
    Account_[] accounts = accountC.toArray(new Account_[accountC.size()]);
    Assert.assertEquals(3, accounts.length);
    Assert.assertEquals("bob", accounts[0].getName());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Role_Condition(indi.mybatis.flying.pojo.condition.Role_Condition) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) SortParam(indi.mybatis.flying.pagination.SortParam) 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)5 Order (indi.mybatis.flying.pagination.Order)5 SortParam (indi.mybatis.flying.pagination.SortParam)5 Test (org.junit.Test)5 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)4 Account_ (indi.mybatis.flying.pojo.Account_)4 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)4 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)3 PageParam (indi.mybatis.flying.pagination.PageParam)3 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)2 Role_ (indi.mybatis.flying.pojo.Role_)1 HashMap (java.util.HashMap)1 IfProfileValue (org.springframework.test.annotation.IfProfileValue)1