Search in sources :

Example 1 with DatabaseSetups

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

the class AccountTest2 method testCondition.

/**
 * 测试insert功能(有乐观锁)
 */
@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest2/testCondition.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest2/testCondition.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest2/testCondition.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest2/testCondition.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest2/testCondition.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest2/testCondition.datasource2.result.xml") })
public void testCondition() {
    LoginLog_Condition lc1 = new LoginLog_Condition();
    lc1.setIpLikeFilter("5");
    int i1 = loginLogService.count(lc1);
    Assert.assertEquals(1, i1);
    LoginLogSource2Condition lc2 = new LoginLogSource2Condition();
    lc2.setIpLikeFilter("2");
    int i2 = loginLogSource2Service.count(lc2);
    Assert.assertEquals(1, i2);
}
Also used : LoginLog_Condition(indi.mybatis.flying.pojo.condition.LoginLog_Condition) LoginLogSource2Condition(indi.mybatis.flying.pojo.condition.LoginLogSource2Condition) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 2 with DatabaseSetups

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

the class AccountTest method testInsert.

/**
 * 测试insert功能(有乐观锁)
 */
@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testInsert.datasource.xml"), @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testInsert.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testInsert.datasource.result.xml"), @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testInsert.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testInsert.datasource.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testInsert.datasource2.result.xml") })
public void testInsert() {
    Account_ a = new Account_();
    a.setId(1L);
    a.setName("ann");
    a.setEmail("ann@live.cn");
    a.setPassword("5a690d842935c51f26f473e025c1b97a");
    a.setActivated(true);
    a.setActivateValue("");
    accountService.insert(a);
    Role2_ role2_ = new Role2_();
    role2_.setName("new");
    role2Service.insert(role2_);
    LoginLog_ loginLog_ = new LoginLog_();
    loginLog_.setLoginIP("old");
    loginLogService.insert(loginLog_);
    LoginLogSource2 loginLogSource2 = new LoginLogSource2();
    loginLogSource2.setLoginIP("new");
    loginLogSource2Service.insert(loginLogSource2);
    Collection<LoginLogSource2> c = loginLogSource2Service.selectAll(new LoginLogSource2());
    LoginLogSource2[] loginLogSource2s = c.toArray(new LoginLogSource2[1]);
    Assert.assertEquals("new", loginLogSource2s[0].getLoginIP());
    Account2_ account2_ = new Account2_();
    account2_.setEmail("l@x.com");
    account2_.setNickname("nick");
    account2_.setRole(role2_);
    account2Service.insert(account2_);
    Collection<Account2_> c2 = account2Service.selectAll(new Account2_());
    Account2_[] account2_s = c2.toArray(new Account2_[1]);
    Assert.assertEquals("new", account2_s[0].getRole().getName());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) Account2_(indi.mybatis.flying.pojo.Account2_) LoginLogSource2(indi.mybatis.flying.pojo.LoginLogSource2) Account_(indi.mybatis.flying.pojo.Account_) Role2_(indi.mybatis.flying.pojo.Role2_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 3 with DatabaseSetups

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

the class CacheTest1 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 4 with DatabaseSetups

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

the class BatchProcessTest method testUpdateBatch4.

@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/batchProcessTest/testUpdateBatch.datasource.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/batchProcessTest/testUpdateBatch4.datasource.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/batchProcessTest/testUpdateBatch.datasource.result.xml") })
public void testUpdateBatch4() {
    List<Account_> l = new LinkedList<>();
    Account_ a1 = new Account_();
    Account_ a2 = new Account_();
    Account_ a3 = new Account_();
    a1.setId(1L);
    a1.setName("ann1");
    l.add(a1);
    a2.setId(2L);
    a2.setName("bob2");
    a2.setPassword("b");
    a2.setStatus(StoryStatus_.CANCEL);
    l.add(a2);
    a3.setId(3L);
    a3.setName("carl3");
    l.add(a3);
    int i = accountService.updateBatch(l);
    System.out.println("::" + i);
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) LinkedList(java.util.LinkedList) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 5 with DatabaseSetups

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

the class BatchProcessTest method testUpdateBatch2.

@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/batchProcessTest/testUpdateBatch.datasource.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/batchProcessTest/testUpdateBatch2.datasource.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/batchProcessTest/testUpdateBatch.datasource.result.xml") })
public void testUpdateBatch2() {
    List<Account_> l = new LinkedList<>();
    Account_ a1 = new Account_();
    Account_ a2 = new Account_();
    Account_ a3 = new Account_();
    a1.setId(1L);
    a1.setName("ann1");
    l.add(a1);
    a2.setId(2L);
    a2.setName("bob2");
    a2.setPassword("b");
    a2.setStatus(StoryStatus_.CANCEL);
    Role_ r1 = new Role_();
    r1.setId(11);
    a2.setRole(r1);
    l.add(a2);
    a3.setId(3L);
    a3.setName("carl3");
    a3.setDelegateRoleId(24L);
    l.add(a3);
    int i = accountService.updateBatch(l);
    System.out.println("::" + i);
    List<Account_> l2 = new LinkedList<>();
    Account_ a4 = new Account_();
    Account_ a5 = new Account_();
    a4.setId(4L);
    a4.setRole(r1);
    l2.add(a4);
    a5.setId(5L);
    a5.setDelegateRoleId(24L);
    l2.add(a5);
    i = accountService.updateBatch(l2);
    System.out.println("::" + i);
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) LinkedList(java.util.LinkedList) Role_(indi.mybatis.flying.pojo.Role_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Aggregations

DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)50 Test (org.junit.Test)49 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)44 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)26 DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 Account_ (indi.mybatis.flying.pojo.Account_)15 Role_ (indi.mybatis.flying.pojo.Role_)10 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)8 LoginLogSource2 (indi.mybatis.flying.pojo.LoginLogSource2)7 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)6 Detail2_ (indi.mybatis.flying.pojo.Detail2_)5 IfProfileValue (org.springframework.test.annotation.IfProfileValue)5 UpdateParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 AnalysisUpdateDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO)3 Account2_ (indi.mybatis.flying.pojo.Account2_)3 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)3 Role2_ (indi.mybatis.flying.pojo.Role2_)3