Search in sources :

Example 6 with ExpectedDatabase

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());
}
Also used : HashMap(java.util.HashMap) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 7 with ExpectedDatabase

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());
}
Also used : Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 8 with ExpectedDatabase

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());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) Account_(indi.mybatis.flying.pojo.Account_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 9 with ExpectedDatabase

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());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 10 with ExpectedDatabase

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());
}
Also used : Account2_(indi.mybatis.flying.pojo.Account2_) Role2_(indi.mybatis.flying.pojo.Role2_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Aggregations

ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)76 Test (org.junit.Test)72 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)53 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)42 MvcResult (org.springframework.test.web.servlet.MvcResult)26 Account_ (indi.mybatis.flying.pojo.Account_)25 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)20 IfProfileValue (org.springframework.test.annotation.IfProfileValue)19 Role_ (indi.mybatis.flying.pojo.Role_)17 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)11 HashMap (java.util.HashMap)9 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)7 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)7 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)6 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)6 PageParam (indi.mybatis.flying.pagination.PageParam)5 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)5 Order (indi.mybatis.flying.pagination.Order)3 SortParam (indi.mybatis.flying.pagination.SortParam)3 JSONArray (org.json.JSONArray)3