Search in sources :

Example 1 with ExpectedDatabases

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

Example 2 with ExpectedDatabases

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

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

the class CacheTest method testNPlusOne2.

/* 一个展示n+1问题的测试用例 */
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource1.result.xml"), @ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource1.result.xml"), @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource2.result.xml") })
public void testNPlusOne2() {
    Role2_ r = new Role2_();
    r.setId(1);
    r.setName("root");
    role2Service.insert(r);
    Role2_ r2 = new Role2_();
    r2.setId(2);
    r2.setName("user");
    role2Service.insert(r2);
    Account22 a = new Account22();
    a.setId(21);
    a.setEmail("10");
    a.setRole(r);
    account22Service.insert(a);
    Account22 a2 = new Account22();
    a2.setId(22);
    a2.setEmail("11");
    a2.setRole(r);
    account22Service.insert(a2);
    Collection<Account22> accounts = account22Service.selectAll(new Account22());
    Assert.assertEquals(2, accounts.size());
    Collection<Account22> accounts2 = account22Service.selectAll(new Account22());
    Collection<Account22> accounts3 = account22Service.selectAll(new Account22());
}
Also used : Account22(indi.mybatis.flying.pojo.Account22) Role2_(indi.mybatis.flying.pojo.Role2_) 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 ExpectedDatabases

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

the class IgnoreInsertAndUpdateTest method testInsert.

@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/ignoreInsertAndUpdateTest/testInsert.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/ignoreInsertAndUpdateTest/testInsert.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/ignoreInsertAndUpdateTest/testInsert.datasource2.result.xml") })
public void testInsert() {
    Detail2_ d = new Detail2_(), d2 = new Detail2_();
    d.setName("n");
    d.setNumber(123);
    d.setDetail("d");
    d.setCreatetime(Calendar.getInstance().getTime());
    detail2Service.insertWithoutName(d);
    d2.setName("n2");
    d2.setNumber(234);
    d2.setDetail("d2");
    d2.setCreatetime(Calendar.getInstance().getTime());
    detail2Service.insertWithoutFoo(d2);
}
Also used : Detail2_(indi.mybatis.flying.pojo.Detail2_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Example 5 with ExpectedDatabases

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

the class JpaTest method testDetail2.

@Test
@DatabaseSetups({ @DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/jpaTest/testDetail2.datasource2.xml") })
@ExpectedDatabases({ @ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/jpaTest/testDetail2.datasource2.result.xml") })
@DatabaseTearDowns({ @DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/jpaTest/testDetail2.datasource2.result.xml") })
public void testDetail2() {
    Detail2_ detail2 = detail2Service.select(1);
    Assert.assertEquals("n", detail2.getName());
    Assert.assertEquals(123, detail2.getNumber().intValue());
    Assert.assertEquals("l", detail2.getLoginLogSource2().getLoginIP());
    loginLogSource2Service.update(detail2.getLoginLogSource2());
    Detail2_ detail2_2 = new Detail2_();
    detail2_2.setName("name");
    detail2_2.setDetail("detail");
    detail2_2.setNumber(321);
    detail2Service.insert(detail2_2);
    Detail2_ detail2_c = new Detail2_();
    detail2_c.setName("name");
    detail2_c.setDetail("detail");
    Detail2_ detail2_3 = detail2Service.selectOne(detail2_c);
    Assert.assertEquals(detail2_2.getId(), detail2_3.getId());
}
Also used : Detail2_(indi.mybatis.flying.pojo.Detail2_) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseTearDowns(com.github.springtestdbunit.annotation.DatabaseTearDowns)

Aggregations

ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)40 Test (org.junit.Test)40 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)31 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)28 DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)12 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)8 CreateStudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO)7 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)6 StudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO)6 Account_ (indi.mybatis.flying.pojo.Account_)6 UpdateParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateParticipantDTO)4 Detail2_ (indi.mybatis.flying.pojo.Detail2_)4 LoginLogSource2 (indi.mybatis.flying.pojo.LoginLogSource2)4 FileInputStream (java.io.FileInputStream)4 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)4 IfProfileValue (org.springframework.test.annotation.IfProfileValue)4 AnalysisUpdateDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO)3 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)3 Role2_ (indi.mybatis.flying.pojo.Role2_)3 Role_ (indi.mybatis.flying.pojo.Role_)3