Search in sources :

Example 6 with DatabaseTearDowns

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

the class AccountTypeHandlerTest method testAccountTypeHandler.

/* 测试AccountTypeHandler的功能 */
@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTypeHandlerTest/testAccountTypeHandler.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTypeHandlerTest/testAccountTypeHandler.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTypeHandlerTest/testAccountTypeHandler.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTypeHandlerTest/testAccountTypeHandler.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTypeHandlerTest/testAccountTypeHandler.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTypeHandlerTest/testAccountTypeHandler.datasource2.result.xml") })
public void testAccountTypeHandler() {
    LoginLogSource2 longinLogSource0 = loginLogSource2Service.selectWithoutAccount(22);
    Assert.assertNull(longinLogSource0.getAccount());
    LoginLogSource2 longinLogSource = loginLogSource2Service.select(22);
    Assert.assertNotNull(longinLogSource);
    Assert.assertNotNull(longinLogSource.getAccount());
    Assert.assertEquals("ann@live.cn", longinLogSource.getAccount().getEmail());
    Account_ ac = new Account_();
    ac.setId(1L);
    LoginLogSource2 l2c = new LoginLogSource2();
    l2c.setAccount(ac);
    Collection<LoginLogSource2> loginLogSource2C = loginLogSource2Service.selectAll(l2c);
    Assert.assertEquals(2, loginLogSource2C.size());
    for (LoginLogSource2 e : loginLogSource2C) {
        Assert.assertEquals("ann@live.cn", e.getAccount().getEmail());
    }
    LoginLogSource2 loginLogSource2 = loginLogSource2Service.select(24);
    Assert.assertNull(loginLogSource2.getAccount());
    LoginLogSource2 loginLogSource3 = loginLogSource2Service.select(25);
    Assert.assertNull(loginLogSource3.getAccount());
    Account_ ac2 = new Account_();
    ac2.setId(2L);
    LoginLogSource2 l2c2 = new LoginLogSource2();
    l2c2.setAccount(ac2);
    LoginLogSource2 loginLogSource4 = loginLogSource2Service.selectOne(l2c2);
    loginLogSource4 = loginLogSource2Service.selectOne(l2c2);
    loginLogSource4 = loginLogSource2Service.selectOne(l2c2);
    loginLogSource4 = loginLogSource2Service.selectOne(l2c2);
    loginLogSource4 = loginLogSource2Service.selectOne(l2c2);
    Assert.assertEquals("bob@live.cn", loginLogSource4.getAccount().getEmail());
    Account_ ac3 = new Account_();
    ac3.setId(1L);
    LoginLogSource2 l2c3 = new LoginLogSource2();
    l2c3.setAccount(ac3);
    l2c3.setLoginIP("ip1");
    int i = loginLogSource2Service.count(l2c3);
    Assert.assertEquals(1, i);
    Account_ account2 = accountService.select(2);
    loginLogSource2.setAccount(account2);
    loginLogSource2Service.update(loginLogSource2);
    loginLogSource4.setAccount(null);
    loginLogSource2Service.updatePersistent(loginLogSource4);
    Account_ account = accountService.select(1);
    loginLogSource2Service.loadAccount(account, new LoginLogSource2());
    Assert.assertEquals(2, account.getLoginLogSource2().size());
}
Also used : LoginLogSource2(indi.mybatis.flying.pojo.LoginLogSource2) Account_(indi.mybatis.flying.pojo.Account_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 7 with DatabaseTearDowns

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

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

Example 9 with DatabaseTearDowns

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

the class DirectSqlTest method testDirectSelect.

/**
 * flying托管与非托管共存的情况
 */
@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/directSqlTest/testDirectSelect.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/directSqlTest/testDirectSelect.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/directSqlTest/testDirectSelect.result.xml") })
public void testDirectSelect() {
    Account_ account1 = accountService.selectDirect(1);
    Assert.assertEquals("ann", account1.getName());
    Assert.assertEquals("5a690d842935c51f26f473e025c1b97a", account1.getPassword());
    Account_ account2 = accountService.select(1);
    Assert.assertNull(account2.getPassword());
    Account_ account3 = accountService.selectEverything(1);
    Assert.assertEquals("5a690d842935c51f26f473e025c1b97a", account3.getPassword());
    Map<String, Object> map = new HashMap<>(4);
    map.put("name", "bob");
    map.put("email", "bob@live.cn");
    Collection<Account_> c1 = accountService.selectAllDirect(map);
    for (Account_ t : c1) {
        Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
    }
    Account_ a1 = new Account_();
    a1.setName("bob");
    a1.setEmail("bob@live.cn");
    Collection<Account_> c2 = accountService.selectAll(a1);
    for (Account_ t : c2) {
        Assert.assertNull(t.getPassword());
    }
    Collection<Account_> c3 = accountService.selectAllEverything(a1);
    for (Account_ t : c3) {
        Assert.assertEquals("5a690d842935c51f26f473e025c1b97b", t.getPassword());
    }
}
Also used : HashMap(java.util.HashMap) Account_(indi.mybatis.flying.pojo.Account_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 10 with DatabaseTearDowns

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

the class IgnoreInsertAndUpdateTest method testUpdate.

@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/ignoreInsertAndUpdateTest/testUpdate.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/ignoreInsertAndUpdateTest/testUpdate.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/ignoreInsertAndUpdateTest/testUpdate.datasource2.result.xml") })
public void testUpdate() {
    Detail2_ detail = detail2Service.select(1);
    detail.setName("n1New");
    detail.setDetail("dNew");
    LoginLogSource2 log = loginLogSource2Service.select(12);
    detail.setLoginLogSource2(log);
    detail2Service.updateWithoutName(detail);
    Detail2_ detail2 = detail2Service.select(2);
    detail2.setName(null);
    detail2.setNumber(null);
    detail2.setLoginLogSource2(null);
    detail2Service.updatePersistentWithoutName(detail2);
}
Also used : Detail2_(indi.mybatis.flying.pojo.Detail2_) LoginLogSource2(indi.mybatis.flying.pojo.LoginLogSource2) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Aggregations

DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)12 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)12 Test (org.junit.Test)12 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)11 Account_ (indi.mybatis.flying.pojo.Account_)6 Detail2_ (indi.mybatis.flying.pojo.Detail2_)4 LoginLogSource2 (indi.mybatis.flying.pojo.LoginLogSource2)4 IfProfileValue (org.springframework.test.annotation.IfProfileValue)4 Role2_ (indi.mybatis.flying.pojo.Role2_)3 Role_ (indi.mybatis.flying.pojo.Role_)3 Account22 (indi.mybatis.flying.pojo.Account22)2 Account2_ (indi.mybatis.flying.pojo.Account2_)2 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)2 LoginLogSource2Condition (indi.mybatis.flying.pojo.condition.LoginLogSource2Condition)2 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)1 HashMap (java.util.HashMap)1