Search in sources :

Example 1 with Account_

use of indi.mybatis.flying.pojo.Account_ in project mybatis.flying by limeng32.

the class AccountTest method testUpdate.

/**
 * 测试update功能(有乐观锁)
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testUpdate.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testUpdate.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testUpdate.xml")
public void testUpdate() {
    Account_ a = accountService.select(1);
    a.setEmail("ann@tom.com");
    a.setActivated(false);
    accountService.update(a);
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 2 with Account_

use of indi.mybatis.flying.pojo.Account_ in project mybatis.flying by limeng32.

the class AccountTest method testSorter.

/**
 * 测试sorter功能
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testSorter.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testSorter.xml")
public void testSorter() {
    Account_Condition ac = new Account_Condition();
    ac.setSorter(new SortParam(new Order(Account_Condition.field_name, Conditionable.Sequence.desc)));
    Collection<Account_> c = accountService.selectAll(ac);
    Account_[] accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals("ann", accounts[3].getName());
    ac.setSorter(new SortParam(new Order(Account_Condition.field_name, Conditionable.Sequence.desc), new Order(Account_Condition.field_password, Conditionable.Sequence.desc)));
    c = accountService.selectAll(ac);
    accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals(new Long(4), accounts[0].getId());
    ac.setSorter(new SortParam(new Order(Account_Condition.field_name, Conditionable.Sequence.desc), new Order(Account_Condition.field_name, Conditionable.Sequence.asc)));
    c = accountService.selectAll(ac);
    accounts = c.toArray(new Account_[c.size()]);
    Assert.assertEquals("ann", accounts[3].getName());
}
Also used : Order(indi.mybatis.flying.pagination.Order) Account_Condition(indi.mybatis.flying.pojo.condition.Account_Condition) Account_(indi.mybatis.flying.pojo.Account_) SortParam(indi.mybatis.flying.pagination.SortParam) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 3 with Account_

use of indi.mybatis.flying.pojo.Account_ in project mybatis.flying by limeng32.

the class AccountTest method testDeputy2.

/**
 * 更多的测试deputyRole
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testDeputy2.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testDeputy2.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testDeputy2.xml")
public void testDeputy2() {
    Role_ rc = new Role_();
    rc.setName("role1");
    Role_ rdc = new Role_();
    rdc.setName("role2");
    Account_ ac = new Account_();
    ac.setRole(rc);
    ac.setRoleDeputy(rdc);
    Collection<Account_> accountC = accountService.selectAll(ac);
    Assert.assertEquals(1, accountC.size());
    int count = accountService.count(ac);
    Assert.assertEquals(1, count);
    Account_ ac2 = new Account_();
    ac2.setRole(rc);
    Collection<Account_> accountC2 = accountService.selectAll(ac2);
    Assert.assertEquals(2, accountC2.size());
    int count2 = accountService.count(ac2);
    Assert.assertEquals(2, count2);
    Account_ ac3 = new Account_();
    ac3.setRoleDeputy(rdc);
    Collection<Account_> accountC3 = accountService.selectAll(ac3);
    Assert.assertEquals(2, accountC3.size());
    int count3 = accountService.count(ac3);
    Assert.assertEquals(2, count3);
    Account_ ac4 = new Account_();
    Collection<Account_> accountC4 = accountService.selectAll(ac4);
    Assert.assertEquals(4, accountC4.size());
    int count4 = accountService.count(ac4);
    Assert.assertEquals(4, count4);
}
Also used : Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 4 with Account_

use of indi.mybatis.flying.pojo.Account_ 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 5 with Account_

use of indi.mybatis.flying.pojo.Account_ in project mybatis.flying by limeng32.

the class CacheTest method testUpdateDirect.

/* 测试在select查询的情况下,缓存确实生效的用例 */
// @Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect() {
    Role_ r = new Role_();
    r.setId(1);
    r.setName("ann");
    roleService.insert(r);
    Account_ a = new Account_();
    a.setId(1L);
    a.setRole(r);
    a.setEmail("email");
    accountService.insert(a);
    Account_ account = accountService.select(1);
    Assert.assertEquals("ann", account.getRole().getName());
    Map<String, Object> m = new HashMap<>(4);
    m.put("id", 1);
    m.put("name", "bob");
    roleService.updateDirect(m);
    Account_ account2 = accountService.select(1);
    Assert.assertEquals("ann", account2.getRole().getName());
}
Also used : HashMap(java.util.HashMap) Account_(indi.mybatis.flying.pojo.Account_) Role_(indi.mybatis.flying.pojo.Role_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Aggregations

Account_ (indi.mybatis.flying.pojo.Account_)42 Test (org.junit.Test)38 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)36 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)25 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)25 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)18 IfProfileValue (org.springframework.test.annotation.IfProfileValue)18 Role_ (indi.mybatis.flying.pojo.Role_)17 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)8 HashMap (java.util.HashMap)8 DatabaseSetups (com.github.springtestdbunit.annotation.DatabaseSetups)6 DatabaseTearDowns (com.github.springtestdbunit.annotation.DatabaseTearDowns)6 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)6 PageParam (indi.mybatis.flying.pagination.PageParam)6 Order (indi.mybatis.flying.pagination.Order)4 SortParam (indi.mybatis.flying.pagination.SortParam)4 ArrayList (java.util.ArrayList)4 LoginLogSource2 (indi.mybatis.flying.pojo.LoginLogSource2)3 Page (indi.mybatis.flying.pagination.Page)2 Account2_ (indi.mybatis.flying.pojo.Account2_)2