use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class CacheTest method testSameInjection.
/*
* 设计两个注入值完全相同的同一pojo的select,观察它们是否共享缓存。 方法:先证明缓存生成之前updateDirect可以影响缓存,
* 再证明缓存生成之后updateDirect不能影响缓存,再看注入值相同的另一个select的结果是否受updateDirect影响。
* 结论:不共享缓存。
*/
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSameInjection.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSameInjection.result.xml")
public void testSameInjection() {
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);
Role_ role = roleService.select(1);
Assert.assertEquals("root", role.getName());
Map<String, Object> m = new HashMap<>(4);
m.put("id", 1);
m.put("name", "newRoot");
roleService.updateDirect(m);
Role_ role2 = roleService.select(1);
Assert.assertEquals("root", role2.getName());
Role_ role3 = roleService.selectEverything(1);
Assert.assertEquals("newRoot", role3.getName());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class CacheTest method testNearlySameInjection.
/* 设计两个注入值中只有ignoreTag不同的同一pojo的select,可以同时正常缓存失效 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testNearlySameInjection.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNearlySameInjection.result.xml")
public void testNearlySameInjection() {
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);
Role_ role = roleService.select(1);
Assert.assertEquals("root", role.getName());
Role_ role2 = roleService.selectNoId(1);
Assert.assertEquals("root", role2.getName());
Assert.assertNull(role2.getId());
r.setName("newRoot");
roleService.update(r);
Role_ role3 = roleService.select(1);
Assert.assertEquals("newRoot", role3.getName());
Role_ role4 = roleService.selectNoId(1);
Assert.assertEquals("newRoot", role4.getName());
Assert.assertNull(role4.getId());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class CacheTest method test.
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/test.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test.result.xml")
public void test() {
String name = "ann";
String newName = "bob";
String loginIP = "0.0.0.1";
Account_ a = new Account_();
LoginLog_ l = new LoginLog_();
a.setName(name);
accountService.insert(a);
l.setLoginIP(loginIP);
l.setAccount(a);
loginLogService.insert(l);
LoginLog_ loginLog = loginLogService.select(l.getId());
Assert.assertEquals(name, loginLog.getAccount().getName());
Account_ account = accountService.select(a.getId());
account.setName(newName);
accountService.update(account);
LoginLog_ loginLog2 = loginLogService.select(l.getId());
Assert.assertEquals(newName, loginLog2.getAccount().getName());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class CacheTest method test2.
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test2.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/test2.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test2.result.xml")
public void test2() {
String name = "新权限", newName = "新角色", accountName = "ann", ip = "0.0.0.1";
Role_ r = new Role_();
r.setName(name);
roleService.insert(r);
Account_ a = new Account_();
a.setName(accountName);
a.setRole(r);
accountService.insert(a);
LoginLog_ l = new LoginLog_();
l.setLoginIP(ip);
l.setAccount(a);
loginLogService.insert(l);
Account_ account = accountService.select(a.getId());
Assert.assertEquals(name, account.getRole().getName());
LoginLog_ loginLog = loginLogService.select(l.getId());
Assert.assertEquals(name, loginLog.getAccount().getRole().getName());
Role_ role = roleService.select(r.getId());
role.setName(newName);
roleService.update(role);
Account_ account2 = accountService.select(a.getId());
Assert.assertEquals(newName, account2.getRole().getName());
LoginLog_ loginLog2 = loginLogService.select(l.getId());
Assert.assertEquals(newName, loginLog2.getAccount().getRole().getName());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase 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());
}
Aggregations