Search in sources :

Example 1 with ExpectedDatabase

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

the class AccountTest method testUpdate.

/**
 * 测试update功能(有乐观锁)
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testUpdate.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testUpdate.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testUpdate.xml")
public void testUpdate() {
    Account_ a = accountService.select(1);
    a.setEmail("ann@tom.com");
    a.setActivated(false);
    accountService.update(a);
}
Also used : 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)

Example 2 with ExpectedDatabase

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

the class AccountTest method testDeputy2.

/**
 * 更多的测试deputyRole
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testDeputy2.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testDeputy2.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testDeputy2.xml")
public void testDeputy2() {
    Role_ rc = new Role_();
    rc.setName("role1");
    Role_ rdc = new Role_();
    rdc.setName("role2");
    Account_ ac = new Account_();
    ac.setRole(rc);
    ac.setRoleDeputy(rdc);
    Collection<Account_> accountC = accountService.selectAll(ac);
    Assert.assertEquals(1, accountC.size());
    int count = accountService.count(ac);
    Assert.assertEquals(1, count);
    Account_ ac2 = new Account_();
    ac2.setRole(rc);
    Collection<Account_> accountC2 = accountService.selectAll(ac2);
    Assert.assertEquals(2, accountC2.size());
    int count2 = accountService.count(ac2);
    Assert.assertEquals(2, count2);
    Account_ ac3 = new Account_();
    ac3.setRoleDeputy(rdc);
    Collection<Account_> accountC3 = accountService.selectAll(ac3);
    Assert.assertEquals(2, accountC3.size());
    int count3 = accountService.count(ac3);
    Assert.assertEquals(2, count3);
    Account_ ac4 = new Account_();
    Collection<Account_> accountC4 = accountService.selectAll(ac4);
    Assert.assertEquals(4, accountC4.size());
    int count4 = accountService.count(ac4);
    Assert.assertEquals(4, count4);
}
Also used : 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)

Example 3 with ExpectedDatabase

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

the class CacheTest method testPaginationUsingCacheIndeed.

/* 一个证明分页确实使用了缓存的测试用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testPaginationUsingCacheIndeed.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPaginationUsingCacheIndeed.result.xml")
public void testPaginationUsingCacheIndeed() {
    Role_ role1 = new Role_(), role2 = new Role_(), role3 = new Role_();
    role1.setName("normal");
    roleService.insert(role1);
    role2.setName("silver");
    roleService.insert(role2);
    role3.setName("gold");
    roleService.insert(role3);
    Role_Condition rc = new Role_Condition();
    rc.setLimiter(new PageParam(1, 2));
    rc.setSorter(new SortParam(new Order("name", Conditionable.Sequence.asc)));
    Collection<Role_> c1 = roleService.selectAll(rc);
    Assert.assertEquals(2, c1.size());
    Role_[] roles = c1.toArray(new Role_[c1.size()]);
    Assert.assertEquals("gold", roles[0].getName());
    Map<String, Object> m = new HashMap<>(4);
    m.put("name", "gold1");
    m.put("id", roles[0].getId());
    roleService.updateDirect(m);
    Role_Condition rc2 = new Role_Condition();
    rc2.setLimiter(new PageParam(1, 2));
    rc2.setSorter(new SortParam(new Order("name", Conditionable.Sequence.asc)));
    Collection<Role_> c2 = roleService.selectAll(rc2);
    Assert.assertEquals(2, c2.size());
    Role_[] roles2 = c2.toArray(new Role_[c2.size()]);
    Assert.assertEquals("gold", roles2[0].getName());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Role_Condition(indi.mybatis.flying.pojo.condition.Role_Condition) HashMap(java.util.HashMap) PageParam(indi.mybatis.flying.pagination.PageParam) Role_(indi.mybatis.flying.pojo.Role_) SortParam(indi.mybatis.flying.pagination.SortParam) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 4 with ExpectedDatabase

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

the class CacheTest method testUpdateDirect.

/* 测试在select查询的情况下,缓存确实生效的用例 */
// @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 testUpdateDirect() {
    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_ account = accountService.select(1);
    Assert.assertEquals("ann", account.getRole().getName());
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 1);
    m.put("name", "bob");
    roleService.updateDirect(m);
    Account_ account2 = accountService.select(1);
    Assert.assertEquals("ann", account2.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 5 with ExpectedDatabase

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

Aggregations

ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)76 Test (org.junit.Test)72 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)53 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)42 MvcResult (org.springframework.test.web.servlet.MvcResult)26 Account_ (indi.mybatis.flying.pojo.Account_)25 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)20 IfProfileValue (org.springframework.test.annotation.IfProfileValue)19 Role_ (indi.mybatis.flying.pojo.Role_)17 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)11 HashMap (java.util.HashMap)9 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)7 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)7 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)6 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)6 PageParam (indi.mybatis.flying.pagination.PageParam)5 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)5 Order (indi.mybatis.flying.pagination.Order)3 SortParam (indi.mybatis.flying.pagination.SortParam)3 JSONArray (org.json.JSONArray)3