Search in sources :

Example 6 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown in project mybatis.flying by limeng32.

the class CacheTest method testCacheHit.

/* 测试查询结果可以因缓存json而正常改变 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testCacheHit.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testCacheHit.result.xml")
public void testCacheHit() {
    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.setRole(role1);
    accountService.insert(a1);
    a2.setName("bob");
    a2.setRole(role1);
    accountService.insert(a2);
    a3.setName("cal");
    a3.setRole(role2);
    accountService.insert(a3);
    Account_ ac1 = new Account_();
    Role_ rc1 = new Role_();
    rc1.setId(role1.getId());
    ac1.setRole(rc1);
    Collection<Account_> accountC1 = accountService.selectAll(ac1);
    Assert.assertEquals(2, accountC1.size());
    Account_ ac2 = new Account_();
    Role_ rc2 = new Role_();
    rc2.setId(role2.getId());
    ac2.setRole(rc2);
    Collection<Account_> accountC2 = accountService.selectAll(ac2);
    Assert.assertEquals(1, accountC2.size());
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) 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 DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown 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 8 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown 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 9 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown 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 10 with DatabaseTearDown

use of com.github.springtestdbunit.annotation.DatabaseTearDown 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)

Aggregations

DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)59 Test (org.junit.Test)55 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)44 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)42 Account_ (indi.mybatis.flying.pojo.Account_)36 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)26 IfProfileValue (org.springframework.test.annotation.IfProfileValue)20 Role_ (indi.mybatis.flying.pojo.Role_)17 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)12 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 PageParam (indi.mybatis.flying.pagination.PageParam)7 Order (indi.mybatis.flying.pagination.Order)5 SortParam (indi.mybatis.flying.pagination.SortParam)5 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)5 Date (java.util.Date)3 Page (indi.mybatis.flying.pagination.Page)2 Account2_ (indi.mybatis.flying.pojo.Account2_)2 Role2_ (indi.mybatis.flying.pojo.Role2_)2