Search in sources :

Example 36 with DatabaseTearDown

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

the class CacheTest method testPagination.

@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPagination.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPagination.result.xml")
public void testPagination() {
    String name1 = "ann", name2 = "bob", name3 = "carl", name4 = "duke";
    Account_ a1 = new Account_();
    a1.setId(1L);
    a1.setName(name1);
    accountService.insert(a1);
    Account_ a2 = new Account_();
    a2.setId(2L);
    a2.setName(name2);
    accountService.insert(a2);
    Account_ a3 = new Account_();
    a3.setId(3L);
    a3.setName(name3);
    accountService.insert(a3);
    Account_ a4 = new Account_();
    a4.setId(4L);
    a4.setName(name4);
    accountService.insert(a4);
    Account_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 2));
    Collection<Account_> c1 = accountService.selectAll(ac);
    Assert.assertEquals(2, c1.size());
    for (Account_ a : c1) {
        if (a.getId() == 1) {
            Assert.assertEquals(name1, a.getName());
        } else {
            Assert.assertEquals(name2, a.getName());
        }
    }
    Assert.assertEquals(2, ac.getLimiter().getMaxPageNum());
    ac.setLimiter(new PageParam(1, 2));
    c1 = accountService.selectAll(ac);
    Assert.assertEquals(2, ac.getLimiter().getMaxPageNum());
    accountService.delete(a1);
    accountService.delete(a2);
    accountService.delete(a3);
    accountService.delete(a4);
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) PageParam(indi.mybatis.flying.pagination.PageParam) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 37 with DatabaseTearDown

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

the class CacheTest method testUpdateDirect4.

/* 测试在查询对象查询的情况下,缓存确实生效的用例 */
// @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 testUpdateDirect4() {
    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_Condition ac = new Account_Condition();
    ac.setLimiter(new PageParam(1, 1));
    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_Condition ac2 = new Account_Condition();
    ac2.setLimiter(new PageParam(1, 1));
    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_) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) PageParam(indi.mybatis.flying.pagination.PageParam) 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 38 with DatabaseTearDown

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

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

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

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