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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations