Search in sources :

Example 6 with Role_

use of indi.mybatis.flying.pojo.Role_ 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 Role_

use of indi.mybatis.flying.pojo.Role_ 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 Role_

use of indi.mybatis.flying.pojo.Role_ 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 Role_

use of indi.mybatis.flying.pojo.Role_ 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 Role_

use of indi.mybatis.flying.pojo.Role_ in project mybatis.flying by limeng32.

the class CacheTest method testSelectWithoutRole.

/* 测试ignoreTag加到外键上后如期望一样不显示相关外键父对象,但有多重外键的情况下不影响另一外键 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSelectWithoutRole.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSelectWithoutRole.result.xml")
public void testSelectWithoutRole() {
    Role_ r = new Role_(), r2 = new Role_();
    r.setId(1);
    r.setName("root");
    roleService.insert(r);
    r2.setId(2);
    r2.setName("user");
    roleService.insert(r2);
    Account_ a = new Account_();
    a.setId(1L);
    a.setRole(r);
    a.setRoleDeputy(r2);
    a.setName("deployer");
    accountService.insert(a);
    Account_ account = accountService.selectWithoutRole(1);
    Assert.assertNull(account.getRole());
    Assert.assertEquals("2", account.getRoleDeputy().getId().toString());
    roleService.update(r);
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 2);
    m.put("name", "newUser");
    roleService.updateDirect(m);
    Account_ account2 = accountService.selectWithoutRole(1);
    Assert.assertEquals("newUser", account2.getRoleDeputy().getName());
}
Also used : HashMap(java.util.HashMap) 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)

Aggregations

Role_ (indi.mybatis.flying.pojo.Role_)23 IfProfileValue (org.springframework.test.annotation.IfProfileValue)18 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)17 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)17 Account_ (indi.mybatis.flying.pojo.Account_)17 Test (org.junit.Test)16 HashMap (java.util.HashMap)9 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)4 PageParam (indi.mybatis.flying.pagination.PageParam)4 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)4 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)3 DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)3 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)3 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Page (indi.mybatis.flying.pagination.Page)2 Role2_ (indi.mybatis.flying.pojo.Role2_)2 Configurer2Exception (indi.mybatis.flying.exceptions.Configurer2Exception)1 ConfigurerException (indi.mybatis.flying.exceptions.ConfigurerException)1 Order (indi.mybatis.flying.pagination.Order)1