use of com.github.springtestdbunit.annotation.DatabaseSetups in project mybatis.flying by limeng32.
the class CacheTest method test22.
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource1.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource1.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource1.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test2.datasource2.result.xml") })
public void test22() {
String name = "ann";
String roleName = "user";
String newRoleName = "admin";
Account_ a = new Account_();
Role_ r = new Role_();
r.setName(roleName);
roleService.insert(r);
a.setName(name);
a.setRole(r);
accountService.insert(a);
Account_ account_ = accountService.select(a.getId());
Assert.assertEquals(roleName, account_.getRole().getName());
Role_ r12 = roleService.select(r.getId());
r12.setName(newRoleName);
roleService.update(r12);
account_ = accountService.select(a.getId());
Assert.assertEquals(newRoleName, account_.getRole().getName());
Account2_ a2 = new Account2_();
Role2_ r2 = new Role2_();
r2.setName(roleName);
role2Service.insert(r2);
a2.setName(name);
a2.setRole(r2);
account2Service.insert(a2);
Account2_ account2_ = account2Service.select(a2.getId());
Assert.assertEquals(roleName, account2_.getRole().getName());
Role2_ r22 = role2Service.select(r2.getId());
r22.setName(newRoleName);
role2Service.update(r22);
account2_ = account2Service.select(a2.getId());
Assert.assertEquals(newRoleName, account2_.getRole().getName());
}
use of com.github.springtestdbunit.annotation.DatabaseSetups in project mybatis.flying by limeng32.
the class CacheTest method testAccountTypeHandlerUsingCache.
/* 一个证明缓存对跨库关联也有效的测试用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testAccountTypeHandlerUsingCache.datasource2.result.xml") })
public void testAccountTypeHandlerUsingCache() {
Role_ r = new Role_();
r.setId(101);
r.setName("user");
roleService.insert(r);
Account_ a = new Account_();
a.setId(1L);
a.setEmail("ann@live.cn");
a.setRole(r);
accountService.insert(a);
Account_ a2 = new Account_();
a2.setId(2L);
a2.setEmail("bob@live.cn");
accountService.insert(a2);
LoginLog_ l = new LoginLog_();
l.setId(2);
l.setLoginIP("2");
loginLogService.insert(l);
LoginLogSource2 l2 = new LoginLogSource2();
l2.setId(21);
l2.setLoginIP("ip0");
l2.setAccount(a);
loginLogSource2Service.insert(l2);
LoginLogSource2 loginLogSource2 = loginLogSource2Service.select(21);
Assert.assertEquals("user", loginLogSource2.getAccount().getRole().getName());
Account_ account = accountService.select(1L);
LoginLogSource2 loginLogSource4 = loginLogSource2Service.select(21);
loginLogSource4.setLoginIP("ip00");
loginLogSource2Service.updateNoFlush(loginLogSource4);
account = accountService.select(1L);
accountService.update(account);
LoginLogSource2 loginLogSource5 = loginLogSource2Service.select(21);
Assert.assertEquals("ip00", loginLogSource5.getLoginIP());
Assert.assertEquals(1, loginLogSource5.getAccount().getOpLock().intValue());
}
use of com.github.springtestdbunit.annotation.DatabaseSetups in project mybatis.flying by limeng32.
the class NoApplicationContextProviderTest method testNormal.
@Test
@IfProfileValue(name = "NO_PROVIDER", value = "true")
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/noApplicationContextProviderTest/testNormal.datasource2.result.xml") })
public void testNormal() {
Account_ a = accountService.selectWithoutCache(1);
assertEquals("r", a.getRole().getName());
Role_ r = roleService.selectWithoutCache(51);
assertEquals("r", r.getName());
try {
Account22 account22 = account22Service.select(11);
fail("Expected an Exception to be thrown");
} catch (Exception e) {
assertEquals("Can not find the ApplicationContextProvider bean in the context", e.getCause().getCause().getMessage());
}
}
use of com.github.springtestdbunit.annotation.DatabaseSetups in project mybatis.flying by limeng32.
the class DirectSqlTest method testDirectSelect.
/**
* flying托管与非托管共存的情况
*/
@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/directSqlTest/testDirectSelect.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/directSqlTest/testDirectSelect.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/directSqlTest/testDirectSelect.result.xml") })
public void testDirectSelect() {
Account_ account1 = accountService.selectDirect(1);
Assert.assertEquals("ann", account1.getName());
Assert.assertEquals("5a690d842935c51f26f473e025c1b97a", account1.getPassword());
Account_ account2 = accountService.select(1);
Assert.assertNull(account2.getPassword());
Account_ account3 = accountService.selectEverything(1);
Assert.assertEquals("5a690d842935c51f26f473e025c1b97a", account3.getPassword());
Map<String, Object> map = new HashMap<>(4);
map.put("name", "bob");
map.put("email", "bob@live.cn");
Collection<Account_> c1 = accountService.selectAllDirect(map);
for (Account_ t : c1) {
Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
}
Account_ a1 = new Account_();
a1.setName("bob");
a1.setEmail("bob@live.cn");
Collection<Account_> c = accountMapper.selectAllDirect(a1);
for (Account_ t : c) {
Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
}
Collection<Account_> c2 = accountService.selectAll(a1);
for (Account_ t : c2) {
Assert.assertNull(t.getPassword());
}
Collection<Account_> c3 = accountService.selectAllEverything(a1);
for (Account_ t : c3) {
Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
}
Collection<Account_> c4 = accountMapper.selectAllDirect2("bob", "bob@live.cn");
for (Account_ t : c4) {
Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
}
Account_ a = new Account_();
a.setName("bob");
a.setEmail("bob@live.cn");
Collection<Account_> c5 = accountMapper.selectAllDirect3(a);
for (Account_ t : c5) {
Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
}
Collection<Account_> c6 = accountMapper.selectAllDirect4("bob@live.cn", "bob");
for (Account_ t : c6) {
Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
}
}
use of com.github.springtestdbunit.annotation.DatabaseSetups in project mybatis.flying by limeng32.
the class GroupTest method test2.
@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/groupTest/test2.datasource.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/groupTest/test2.datasource.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/groupTest/test2.datasource.xml") })
public void test2() {
EmpScore2 e = new EmpScore2();
e.setState("0");
int c = empScore2Mapper.count(e);
Assert.assertEquals(3, c);
System.out.println("::" + JSONObject.toJSONString(e));
List<EmpScore2> l = empScore2Mapper.selectAll(e);
Assert.assertEquals(3, l.size());
System.out.println("::" + JSONObject.toJSONString(e));
EmpScore2 emp1 = empScore2Mapper.select(1L);
emp1.setState("2");
empScore2Mapper.update(emp1);
EmpScore2 emp2 = empScore2Mapper.select(2L);
System.out.println("::" + JSONObject.toJSONString(emp2));
emp2.setState(null);
empScore2Mapper.updatePersistent(emp2);
EmpScore2 e2 = new EmpScore2();
e2.setId(8L);
e2.setStaffId("120");
e2.setStaffName("丁七");
e2.setYear("2020");
e2.setSeason(4);
e2.setState("1");
empScore2Mapper.insert(e2);
EmpScore2 e3 = new EmpScore2(), e4 = new EmpScore2();
e3.setId(9L);
e3.setStaffId("120");
e3.setStaffName("丁七");
e3.setYear("2020");
e3.setSeason(4);
e3.setState("1");
e4.setId(10L);
e4.setStaffId("120");
e4.setStaffName("丁七");
e4.setYear("2020");
e4.setSeason(4);
e4.setState("1");
List<EmpScore2> l2 = new ArrayList<>();
l2.add(e3);
l2.add(e4);
empScore2Mapper.insertBatch(l2);
List<EmpScore2> l3 = empScore2Mapper.selectAll(e);
Assert.assertEquals(2, l3.size());
for (EmpScore2 entry : l3) {
entry.setYear("2021");
}
empScore2Mapper.updateBatch(l3);
}
Aggregations