Search in sources :

Example 26 with Account_

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

the class CacheTest method testSameIdAndInjectionInDifferentPojos.

/* 两个相同注入值的不同pojo的select,使其中一个缓存失效,不会影响到另一个。 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSameIdAndInjectionInDifferentPojos.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSameIdAndInjectionInDifferentPojos.result.xml")
public void testSameIdAndInjectionInDifferentPojos() {
    Role_ r = new Role_();
    r.setId(1);
    r.setName("root");
    roleService.insert(r);
    Account_ a = new Account_();
    a.setId(1L);
    a.setName("deployer");
    accountService.insert(a);
    Role_ role = roleService.selectEverything(1);
    Account_ account = accountService.selectEverything(1);
    a.setName("newDeployer");
    accountService.update(a);
    Account_ account2 = accountService.selectEverything(1);
    Assert.assertEquals("newDeployer", account2.getName());
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 1);
    m.put("name", "newRoot");
    roleService.updateDirect(m);
    Role_ role2 = roleService.selectEverything(1);
    Assert.assertEquals("root", role2.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 27 with Account_

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

the class CacheTest method testCacheHitByDirectSql.

/* 测试非flying方式的查询结果可以因缓存json而正常改变 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testCacheHitByDirectSql.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testCacheHitByDirectSql.result.xml")
public void testCacheHitByDirectSql() {
    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.setEmail("ann@live.cn");
    a1.setRole(role1);
    accountService.insert(a1);
    a2.setName("bob");
    a2.setEmail("bob@live.cn");
    a2.setRole(role1);
    accountService.insert(a2);
    a3.setName("cal");
    a3.setEmail("cal@live.cn");
    a3.setRole(role2);
    accountService.insert(a3);
    Map<String, Object> map1 = new HashMap<>(4);
    map1.put("role_id", role1.getId());
    Collection<Account_> c1 = accountService.selectAccountByRole(map1);
    Assert.assertEquals(2, c1.size());
    Map<String, Object> map2 = new HashMap<>(4);
    map2.put("role_id", role2.getId());
    Collection<Account_> c2 = accountService.selectAccountByRole(map2);
    Assert.assertEquals(1, c2.size());
    Map<String, Object> map3 = new HashMap<>(4);
    map3.put("name", "ann");
    map3.put("email", "ann@live.cn");
    Collection<Account_> c3 = accountService.selectAllDirect(map3);
    Assert.assertEquals(1, c3.size());
    Account_ account1 = accountService.select(a1.getId());
    Assert.assertEquals("ann", account1.getName());
    Account_ account2 = accountService.select(a2.getId());
    Assert.assertEquals("bob", account2.getName());
    Account_ account3 = accountService.select(a1.getId());
    Assert.assertEquals("ann", account3.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 28 with Account_

use of indi.mybatis.flying.pojo.Account_ 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());
}
Also used : Account2_(indi.mybatis.flying.pojo.Account2_) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) Role2_(indi.mybatis.flying.pojo.Role2_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 29 with Account_

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

the class CacheTest method testUpdateDirect2.

/* 测试在selectAll查询的情况下,缓存确实生效的用例 */
// @Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect2() {
    Role_ r = new Role_();
    r.setId(1);
    r.setName("ann");
    roleService.insert(r);
    Account_ a = new Account_();
    a.setId(1L);
    a.setRole(r);
    a.setEmail("email");
    accountService.insert(a);
    Account_ ac = new Account_();
    ac.setEmail("email");
    Collection<Account_> c = accountService.selectAll(ac);
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 1);
    m.put("name", "bob");
    roleService.updateDirect(m);
    Account_ ac2 = new Account_();
    ac2.setEmail("email");
    Collection<Account_> c2 = accountService.selectAll(ac2);
    for (Account_ t : c2) {
        Assert.assertEquals("ann", t.getRole().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) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 30 with Account_

use of indi.mybatis.flying.pojo.Account_ 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());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) LoginLogSource2(indi.mybatis.flying.pojo.LoginLogSource2) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns) 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