Search in sources :

Example 6 with Account_

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

use of indi.mybatis.flying.pojo.Account_ 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 8 with Account_

use of indi.mybatis.flying.pojo.Account_ 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 9 with Account_

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

Example 10 with Account_

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

the class CacheTest method testClearCache.

/* 测试分页缓存的用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testClearCache.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testClearCache.result.xml")
public void testClearCache() {
    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);
    Account_ a = new Account_(), a2 = new Account_(), a3 = new Account_(), a4 = new Account_(), a5 = new Account_(), a6 = new Account_(), a7 = new Account_(), a8 = new Account_(), a9 = new Account_(), a10 = new Account_(), a11 = new Account_(), a12 = new Account_();
    a.setName("ann");
    accountService.insert(a);
    a2.setName("bob");
    accountService.insert(a2);
    a3.setName("caq");
    accountService.insert(a3);
    a4.setName("don");
    accountService.insert(a4);
    a5.setName("eli");
    accountService.insert(a5);
    a6.setName("fea");
    accountService.insert(a6);
    a7.setName("gus");
    accountService.insert(a7);
    a8.setName("hex");
    accountService.insert(a8);
    a9.setName("ivy");
    accountService.insert(a9);
    a10.setName("jak");
    accountService.insert(a10);
    a11.setName("kir");
    a11.setRole(r);
    accountService.insert(a11);
    a12.setName("lee");
    a12.setRole(r);
    accountService.insert(a12);
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 10));
    Collection<Account_> c = accountService.selectAll(ac);
    Page<Account_> p = new Page<>(c, ac.getLimiter());
    Assert.assertEquals(2, p.getMaxPageNum());
    Assert.assertEquals(12, p.getTotalCount());
    Assert.assertEquals(1, p.getPageNo());
    Assert.assertEquals(10, p.getPageItems().size());
    Account_Condition ac2 = new Account_Condition();
    ac2.setLimiter(new PageParam(2, 10));
    Collection<Account_> c2 = accountService.selectAll(ac2);
    Page<Account_> p2 = new Page<>(c2, ac2.getLimiter());
    Assert.assertEquals(2, p2.getMaxPageNum());
    Assert.assertEquals(12, p2.getTotalCount());
    Assert.assertEquals(2, p2.getPageNo());
    Assert.assertEquals(2, p2.getPageItems().size());
    for (Account_ temp : p2.getPageItems()) {
        Assert.assertEquals("root", temp.getRole().getName());
    }
    a11.setRole(r2);
    accountService.update(a11);
    a12.setRole(r2);
    accountService.update(a12);
    Account_Condition ac3 = new Account_Condition();
    ac3.setLimiter(new PageParam(2, 10));
    Collection<Account_> c3 = accountService.selectAll(ac3);
    Page<Account_> p3 = new Page<>(c3, ac3.getLimiter());
    Assert.assertEquals(2, p3.getMaxPageNum());
    Assert.assertEquals(12, p3.getTotalCount());
    Assert.assertEquals(2, p3.getPageNo());
    Assert.assertEquals(2, p3.getPageItems().size());
    for (Account_ temp : p3.getPageItems()) {
        Assert.assertEquals("deployer", temp.getRole().getName());
    }
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Page(indi.mybatis.flying.pagination.Page) PageParam(indi.mybatis.flying.pagination.PageParam) 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

Account_ (indi.mybatis.flying.pojo.Account_)42 Test (org.junit.Test)38 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)36 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)25 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)25 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)18 IfProfileValue (org.springframework.test.annotation.IfProfileValue)18 Role_ (indi.mybatis.flying.pojo.Role_)17 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)8 HashMap (java.util.HashMap)8 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)6 DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)6 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)6 PageParam (indi.mybatis.flying.pagination.PageParam)6 Order (indi.mybatis.flying.pagination.Order)4 SortParam (indi.mybatis.flying.pagination.SortParam)4 ArrayList (java.util.ArrayList)4 LoginLogSource2 (indi.mybatis.flying.pojo.LoginLogSource2)3 Page (indi.mybatis.flying.pagination.Page)2 Account2_ (indi.mybatis.flying.pojo.Account2_)2