use of com.github.springtestdbunit.annotation.ExpectedDatabase 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());
}
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class CacheTest method test3.
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test3.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/test3.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test3.result.xml")
public void test3() {
String name = "新权限", newName = "新角色", newName2 = "新新角色", accountName = "ann", ip = "0.0.0.1", detailName = "细节";
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);
Detail_ d = new Detail_();
d.setName(detailName);
d.setLoginLog(l);
detailService.insert(d);
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());
Detail_ detail = detailService.select(d.getId());
Assert.assertEquals(accountName, detail.getLoginLog().getAccount().getName());
Assert.assertEquals(newName, detail.getLoginLog().getAccount().getRole().getName());
// Account_ account3 = accountService.select(a.getId());
// account3.setName(newAccountName);
// accountService.update(account3);
Role_ role2 = roleService.select(r.getId());
role2.setName(newName2);
roleService.update(role2);
Detail_ detail2 = detailService.select(d.getId());
Assert.assertEquals(newName2, detail2.getLoginLog().getAccount().getRole().getName());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class CacheTest method test21.
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.xml")
@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.result.xml")
@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.result.xml")
public void test21() {
String name = "ann";
String roleName = "user";
String newRoleName = "admin";
Account2_ a = new Account2_();
Role2_ r = new Role2_();
r.setName(roleName);
role2Service.insert(r);
a.setName(name);
a.setRole(r);
account2Service.insert(a);
Account2_ account2_ = account2Service.select(a.getId());
Assert.assertEquals(roleName, account2_.getRole().getName());
Role2_ r2 = role2Service.select(r.getId());
r2.setName(newRoleName);
role2Service.update(r2);
account2_ = account2Service.select(a.getId());
Assert.assertEquals(newRoleName, account2_.getRole().getName());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase 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());
}
use of com.github.springtestdbunit.annotation.ExpectedDatabase in project mybatis.flying by limeng32.
the class InternalCacheTest method testCacheThread.
/**
* 这是一个展示Junit配合Groboutils进行多线程测试的例子,在这个例子中accountInsert以子线程的方式执行多次,
* 主线程会等待子线程全部执行完后再结束
*/
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.result.xml")
public void testCacheThread() throws Throwable {
// 实例化 TestRunnable 类
TestRunnable tr1, tr2;
tr1 = new acctionSelect();
tr2 = new acctionUpdate();
// 把实例传递给 MTTR
TestRunnable[] trs = { tr1, tr2 };
MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
// 执行MTTR和线程
mttr.runTestRunnables();
}
Aggregations