Search in sources :

Example 51 with DatabaseSetup

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

the class ConditionNotInTest method testConditionNotIn4.

/**
 * 测试无外键情况下condition:notIn功能且变量类型为时间的情况
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionNotInTest/testConditionIn4.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionNotInTest/testConditionIn4.xml")
public void testConditionNotIn4() {
    LoginLog_Condition lc = new LoginLog_Condition();
    List<Date> timeC = new ArrayList<>();
    Calendar c = Calendar.getInstance(), c2 = Calendar.getInstance();
    c.clear();
    c2.clear();
    c.set(1970, 0, 1, 8, 0, 0);
    c2.set(1970, 0, 1, 8, 0, 1);
    timeC.add(c.getTime());
    timeC.add(c2.getTime());
    lc.setLoginTimeNotIn(timeC);
    int count = loginLogService.count(lc);
    Assert.assertEquals(0, count);
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) LoginLog_Condition(indi.mybatis.flying.pojo.condition.LoginLog_Condition) Date(java.util.Date) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 52 with DatabaseSetup

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

the class ConditionTest method testSorterWithMultiAssociation.

/**
 * 测试多重外键情况下sorter是否能正确发挥作用
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testSorterWithMultiAssociation.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/conditionTest/testSorterWithMultiAssociation.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testSorterWithMultiAssociation.xml")
public void testSorterWithMultiAssociation() {
    Role_Condition rc1 = new Role_Condition();
    rc1.setName("role1");
    Role_Condition rc2 = new Role_Condition();
    rc2.setName("role2");
    Account_Condition ac = new Account_Condition();
    ac.setRole(rc1);
    ac.setRoleDeputy(rc2);
    ac.setSorter(new SortParam(new Order("name", Sequence.asc)));
    Collection<Account_> accountC = accountService.selectAll(ac);
    Account_[] accounts = accountC.toArray(new Account_[accountC.size()]);
    Assert.assertEquals(3, accounts.length);
    Assert.assertEquals("bob", accounts[0].getName());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Role_Condition(indi.mybatis.flying.pojo.condition.Role_Condition) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) SortParam(indi.mybatis.flying.pagination.SortParam) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 53 with DatabaseSetup

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

the class ConditionTest method testConditionLike2.

/**
 * 测试condition:like功能2:在parameter为null和为空字符串时的情况
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testConditionLike2.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testConditionLike2.xml")
public void testConditionLike2() {
    Account_Condition ac = new Account_Condition(), ac2 = new Account_Condition();
    ac.setEmailLike(null);
    Collection<Account_> c = accountService.selectAll(ac);
    Account_[] accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(2, accounts.length);
    ac2.setEmailLike("");
    Collection<Account_> c2 = accountService.selectAll(ac);
    Assert.assertEquals(2, c2.size());
}
Also used : Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 54 with DatabaseSetup

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

the class ConditionTest method testConditionLike.

/**
 * 测试condition:like功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testConditionLike.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testConditionLike.xml")
public void testConditionLike() {
    Account_Condition ac = new Account_Condition();
    ac.setEmailLike("%%");
    Collection<Account_> c = accountService.selectAll(ac);
    Account_[] accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(1, accounts.length);
    Assert.assertEquals("an%%n@live.cn", accounts[0].getEmail());
}
Also used : Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 55 with DatabaseSetup

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

the class ConditionTest method testMultiLikeOR.

@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionTest/testMultiLikeOR.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionTest/testMultiLikeOR.xml")
public void testMultiLikeOR() {
    Account_Condition ac = new Account_Condition();
    ac.setName("ann");
    ac.setEmailLike("as");
    List<String> multi = new ArrayList<>();
    multi.add(null);
    multi.add(null);
    multi.add(null);
    multi.add(null);
    ac.setMultiLikeOR(multi);
    Collection<Account_> c = accountService.selectAll(ac);
    Assert.assertEquals(1, c.size());
    int count = accountService.count(ac);
    Assert.assertEquals(1, count);
    Account_Condition ac2 = new Account_Condition();
    ac2.setName("ann");
    ac2.setEmailLike("as");
    List<String> multi2 = new ArrayList<>();
    multi2.add(null);
    multi2.add("a");
    multi2.add("sd");
    multi2.add("z");
    ac2.setMultiLikeOR(multi2);
    Collection<Account_> c2 = accountService.selectAll(ac2);
    Assert.assertEquals(1, c2.size());
    LoginLog_ lc = new LoginLog_();
    Account_Condition ac3 = new Account_Condition();
    List<String> multi3 = new ArrayList<>();
    multi3.add(null);
    multi3.add("a");
    multi3.add("sd");
    multi3.add("z");
    ac3.setMultiLikeOR(multi3);
    lc.setAccount(ac3);
    Collection<LoginLog_> c3 = loginLogService.selectAll(lc);
    Assert.assertEquals(1, c3.size());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) ArrayList(java.util.ArrayList) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Aggregations

DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)79 Test (org.junit.Test)78 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)53 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)44 MvcResult (org.springframework.test.web.servlet.MvcResult)26 Account_ (indi.mybatis.flying.pojo.Account_)25 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)22 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)21 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)12 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)11 ArrayList (java.util.ArrayList)11 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)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 IfProfileValue (org.springframework.test.annotation.IfProfileValue)5 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)4 Order (indi.mybatis.flying.pagination.Order)4 SortParam (indi.mybatis.flying.pagination.SortParam)4 Role_ (indi.mybatis.flying.pojo.Role_)4