Search in sources :

Example 41 with DatabaseTearDown

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

the class CacheTest method test3.

@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test3.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/test3.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test3.result.xml")
public void test3() {
    String name = "新权限", newName = "新角色", newName2 = "新新角色", accountName = "ann", ip = "0.0.0.1", detailName = "细节";
    Role_ r = new Role_();
    r.setName(name);
    roleService.insert(r);
    Account_ a = new Account_();
    a.setName(accountName);
    a.setRole(r);
    accountService.insert(a);
    LoginLog_ l = new LoginLog_();
    l.setLoginIP(ip);
    l.setAccount(a);
    loginLogService.insert(l);
    Detail_ d = new Detail_();
    d.setName(detailName);
    d.setLoginLog(l);
    detailService.insert(d);
    Account_ account = accountService.select(a.getId());
    Assert.assertEquals(name, account.getRole().getName());
    LoginLog_ loginLog = loginLogService.select(l.getId());
    Assert.assertEquals(name, loginLog.getAccount().getRole().getName());
    Role_ role = roleService.select(r.getId());
    role.setName(newName);
    roleService.update(role);
    Account_ account2 = accountService.select(a.getId());
    Assert.assertEquals(newName, account2.getRole().getName());
    LoginLog_ loginLog2 = loginLogService.select(l.getId());
    Assert.assertEquals(newName, loginLog2.getAccount().getRole().getName());
    Detail_ detail = detailService.select(d.getId());
    Assert.assertEquals(accountName, detail.getLoginLog().getAccount().getName());
    Assert.assertEquals(newName, detail.getLoginLog().getAccount().getRole().getName());
    // Account_ account3 = accountService.select(a.getId());
    // account3.setName(newAccountName);
    // accountService.update(account3);
    Role_ role2 = roleService.select(r.getId());
    role2.setName(newName2);
    roleService.update(role2);
    Detail_ detail2 = detailService.select(d.getId());
    Assert.assertEquals(newName2, detail2.getLoginLog().getAccount().getRole().getName());
}
Also used : LoginLog_(indi.mybatis.flying.pojo.LoginLog_) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) Detail_(indi.mybatis.flying.pojo.Detail_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 42 with DatabaseTearDown

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

the class CacheTest method test21.

@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.xml")
@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.result.xml")
@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.result.xml")
public void test21() {
    String name = "ann";
    String roleName = "user";
    String newRoleName = "admin";
    Account2_ a = new Account2_();
    Role2_ r = new Role2_();
    r.setName(roleName);
    role2Service.insert(r);
    a.setName(name);
    a.setRole(r);
    account2Service.insert(a);
    Account2_ account2_ = account2Service.select(a.getId());
    Assert.assertEquals(roleName, account2_.getRole().getName());
    Role2_ r2 = role2Service.select(r.getId());
    r2.setName(newRoleName);
    role2Service.update(r2);
    account2_ = account2Service.select(a.getId());
    Assert.assertEquals(newRoleName, account2_.getRole().getName());
}
Also used : Account2_(indi.mybatis.flying.pojo.Account2_) Role2_(indi.mybatis.flying.pojo.Role2_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 43 with DatabaseTearDown

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

the class ConditionNotInTest method testConditionNotIn.

/**
 * 测试无外键情况下condition:notIn功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionNotInTest/testConditionIn.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionNotInTest/testConditionIn.xml")
public void testConditionNotIn() {
    Account_Condition ac = new Account_Condition();
    List<String> nameC = new ArrayList<>();
    nameC.add("ann");
    ac.setNameNotIn(nameC);
    Collection<Account_> c = accountService.selectAll(ac);
    Assert.assertEquals(1, c.size());
    nameC.add("bob");
    Collection<Account_> c2 = accountService.selectAll(ac);
    Assert.assertEquals(0, c2.size());
    List<String> nameC2 = new ArrayList<>();
    ac.setNameNotIn(nameC2);
    Collection<Account_> c3 = accountService.selectAll(ac);
    Assert.assertEquals(2, c3.size());
}
Also used : 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)

Example 44 with DatabaseTearDown

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

the class ConditionNotInTest method testConditionNotIn3.

/**
 * 测试无外键情况下condition:notIn功能且变量类型为数字的情况
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionNotInTest/testConditionIn3.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionNotInTest/testConditionIn3.xml")
public void testConditionNotIn3() {
    Account_Condition ac = new Account_Condition();
    List<Integer> opLockC = new ArrayList<>();
    opLockC.add(1);
    opLockC.add(2);
    ac.setOpLockNotIn(opLockC);
    int count = accountService.count(ac);
    Assert.assertEquals(0, count);
}
Also used : ArrayList(java.util.ArrayList) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 45 with DatabaseTearDown

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

Aggregations

DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)59 Test (org.junit.Test)55 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)44 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)42 Account_ (indi.mybatis.flying.pojo.Account_)36 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)26 IfProfileValue (org.springframework.test.annotation.IfProfileValue)20 Role_ (indi.mybatis.flying.pojo.Role_)17 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)12 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 PageParam (indi.mybatis.flying.pagination.PageParam)7 Order (indi.mybatis.flying.pagination.Order)5 SortParam (indi.mybatis.flying.pagination.SortParam)5 Role_Condition (indi.mybatis.flying.pojo.condition.Role_Condition)5 Date (java.util.Date)3 Page (indi.mybatis.flying.pagination.Page)2 Account2_ (indi.mybatis.flying.pojo.Account2_)2 Role2_ (indi.mybatis.flying.pojo.Role2_)2