use of com.github.springtestdbunit.annotation.DatabaseTearDown 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);
}
use of com.github.springtestdbunit.annotation.DatabaseTearDown 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());
}
}
use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.
the class CacheTest method testSameIdAndInjectionInDifferentPojos.
/* 两个相同注入值的不同pojo的select,使其中一个缓存失效,不会影响到另一个。 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSameIdAndInjectionInDifferentPojos.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSameIdAndInjectionInDifferentPojos.result.xml")
public void testSameIdAndInjectionInDifferentPojos() {
Role_ r = new Role_();
r.setId(1);
r.setName("root");
roleService.insert(r);
Account_ a = new Account_();
a.setId(1L);
a.setName("deployer");
accountService.insert(a);
Role_ role = roleService.selectEverything(1);
Account_ account = accountService.selectEverything(1);
a.setName("newDeployer");
accountService.update(a);
Account_ account2 = accountService.selectEverything(1);
Assert.assertEquals("newDeployer", account2.getName());
Map<String, Object> m = new HashMap<>(4);
m.put("id", 1);
m.put("name", "newRoot");
roleService.updateDirect(m);
Role_ role2 = roleService.selectEverything(1);
Assert.assertEquals("root", role2.getName());
}
use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.
the class CacheTest method testCacheHitByDirectSql.
/* 测试非flying方式的查询结果可以因缓存json而正常改变 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testCacheHitByDirectSql.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testCacheHitByDirectSql.result.xml")
public void testCacheHitByDirectSql() {
Role_ role1 = new Role_(), role2 = new Role_();
role1.setName("silver");
roleService.insert(role1);
role2.setName("gold");
roleService.insert(role2);
Account_ a1 = new Account_(), a2 = new Account_(), a3 = new Account_();
a1.setName("ann");
a1.setEmail("ann@live.cn");
a1.setRole(role1);
accountService.insert(a1);
a2.setName("bob");
a2.setEmail("bob@live.cn");
a2.setRole(role1);
accountService.insert(a2);
a3.setName("cal");
a3.setEmail("cal@live.cn");
a3.setRole(role2);
accountService.insert(a3);
Map<String, Object> map1 = new HashMap<>(4);
map1.put("role_id", role1.getId());
Collection<Account_> c1 = accountService.selectAccountByRole(map1);
Assert.assertEquals(2, c1.size());
Map<String, Object> map2 = new HashMap<>(4);
map2.put("role_id", role2.getId());
Collection<Account_> c2 = accountService.selectAccountByRole(map2);
Assert.assertEquals(1, c2.size());
Map<String, Object> map3 = new HashMap<>(4);
map3.put("name", "ann");
map3.put("email", "ann@live.cn");
Collection<Account_> c3 = accountService.selectAllDirect(map3);
Assert.assertEquals(1, c3.size());
Account_ account1 = accountService.select(a1.getId());
Assert.assertEquals("ann", account1.getName());
Account_ account2 = accountService.select(a2.getId());
Assert.assertEquals("bob", account2.getName());
Account_ account3 = accountService.select(a1.getId());
Assert.assertEquals("ann", account3.getName());
}
use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.
the class CacheTest method testUpdateDirect2.
/* 测试在selectAll查询的情况下,缓存确实生效的用例 */
// @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 testUpdateDirect2() {
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_ ac = new Account_();
ac.setEmail("email");
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_ ac2 = new Account_();
ac2.setEmail("email");
Collection<Account_> c2 = accountService.selectAll(ac2);
for (Account_ t : c2) {
Assert.assertEquals("ann", t.getRole().getName());
}
}
Aggregations