use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class AccountTest method testDelete.
/**
* 测试delete功能
*/
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testDelete.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testDelete.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testDelete.xml")
public void testDelete() {
Account_ a = accountService.select(1);
accountService.delete(a);
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class AccountTest method testIgnoreTag.
/**
* 测试ignoreTag功能
*/
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testIgnoredSelect.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testIgnoredSelect.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testIgnoredSelect.xml")
public void testIgnoreTag() {
Account_ account = accountService.select(1);
Assert.assertNull(account.getPassword());
Account_ ac = new Account_();
Collection<Account_> accountC = accountService.selectAll(ac);
for (Account_ a : accountC) {
Assert.assertNull(a.getPassword());
}
Account_ ac2 = new Account_();
ac2.setPassword("5a690d842935c51f26f473e025c1b97a");
Collection<Account_> accountC2 = accountService.selectAll(ac2);
Assert.assertEquals(1, accountC2.size());
LoginLog_ loginLog = loginLogService.select(1);
Assert.assertNull(loginLog.getAccount().getPassword());
LoginLog_ lc2 = new LoginLog_();
lc2.setAccount(ac2);
Collection<LoginLog_> loginLogC = loginLogService.selectAll(lc2);
Assert.assertEquals(1, loginLogC.size());
for (LoginLog_ l : loginLogC) {
Assert.assertEquals("0.0.0.1", l.getLoginIP());
}
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase 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.ExpectedDatabase 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.ExpectedDatabase 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());
}
Aggregations