Java Code Examples for com.github.springtestdbunit.annotation.DatabaseOperation#DELETE_ALL

The following examples show how to use com.github.springtestdbunit.annotation.DatabaseOperation#DELETE_ALL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Account2Test.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
/** 测试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);
}
 
Example 2
Source File: IgnoreInsertAndUpdateTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@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());
	LoginLogSource2 loginLog2 = new LoginLogSource2();
	loginLog2.setId(22);
	d2.setLoginLogSource2(loginLog2);
	detail2Service.insertWithoutFoo(d2);
}
 
Example 3
Source File: AccountTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@Test
@DatabaseSetups({
		@DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testTransactive2.datasource.xml"),
		@DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testTransactive2.datasource2.xml") })
@ExpectedDatabases({
		@ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testTransactive2.datasource.result.xml"),
		@ExpectedDatabase(connection = "dataSource2", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testTransactive2.datasource2.result.xml") })
@DatabaseTearDowns({
		@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testTransactive2.datasource.result.xml"),
		@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testTransactive2.datasource2.result.xml") })
public void testTransactive2() {
	try {
		transactiveService.addAccountTransactive();
	} catch (ConfigurerException e) {
		e.printStackTrace();
	}
}
 
Example 4
Source File: ConditionNotInTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
/** 测试无外键情况下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());
}
 
Example 5
Source File: ConditionTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
/** 测试多重外键情况下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());
}
 
Example 6
Source File: IndexTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/indexTest/testIndex.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/indexTest/testIndex.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/indexTest/testIndex.result.xml")
public void testIndex() {
	Account_ account = accountService.selectWithIndex(2);
	Assert.assertEquals("bob", account.getName());

	Account_ ac = new Account_();
	ac.setName("bob");
	Account_ account2 = accountService.selectOne(ac);
	Assert.assertEquals("[email protected]", account2.getEmail());

	Account_Condition ac2 = new Account_Condition();
	ac2.setNameNotEqual("carl");
	int c = accountService.count(ac2);
	Assert.assertEquals(2, c);
}
 
Example 7
Source File: WhiteListTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@Test
@DatabaseSetup(connection = "dataSource1", type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/whiteListTest/testWhiteListInsertBatch.xml")
@ExpectedDatabase(connection = "dataSource1", override = false, assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/whiteListTest/testWhiteListInsertBatch.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/whiteListTest/testWhiteListInsertBatch.result.xml")
public void testWhiteListInsertBatch() {
	Account_ account = new Account_();
	account.setName("name");
	account.setEmail("email");
	account.setPassword("aaa");
	Role_ role = new Role_();
	role.setId(11);
	account.setRole(role);
	Permission permission = new Permission();
	permission.setId(22);
	account.setPermission(permission);

	Collection<Account_> ac = new ArrayList<>();
	ac.add(account);
	accountService.insertBatchSimpleNoName(ac);
}
 
Example 8
Source File: AccountTest.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
/** 测试limiter功能 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testLimiter.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testLimiter.xml")
public void testLimiter() {
	Account_Condition ac = new Account_Condition();
	ac.setLimiter(new PageParam(1, 2));
	Collection<Account_> c = accountService.selectAll(ac);
	Account_[] accounts = c.toArray(new Account_[c.size()]);
	Assert.assertEquals(2, accounts.length);
	Assert.assertEquals(1, accounts[0].getId().intValue());
	Assert.assertEquals(2, accounts[1].getId().intValue());
	Assert.assertEquals(2, ac.getLimiter().getMaxPageNum());
	ac.setSorter(new SortParam(new Order(Account_Condition.field_id, Conditionable.Sequence.DESC)));
	c = accountService.selectAll(ac);
	accounts = c.toArray(new Account_[c.size()]);
	Assert.assertEquals(2, accounts.length);
	Assert.assertEquals(4, accounts[0].getId().intValue());
	Assert.assertEquals(3, accounts[1].getId().intValue());
}
 
Example 9
Source File: ConditionInTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/conditionInTest/testConditionIn5.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/conditionInTest/testConditionIn5.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/conditionInTest/testConditionIn5.xml")
public void testConditionIn5() {
	Account_Condition ac = new Account_Condition();
	Account_Condition ac2 = new Account_Condition();
	Account_Condition ac3 = new Account_Condition();
	List<Integer> roleIds = new ArrayList<>();
	roleIds.add(1);
	roleIds.add(2);
	ac.setRoleIdIn(roleIds);
	Role_ r1 = new Role_();
	r1.setId(1);
	Role_ r2 = new Role_();
	r2.setId(2);
	int c = accountService.count(ac);
	Assert.assertEquals(2, c);
	ac3.setRoleIdNotIn(roleIds);
	int c3 = accountService.count(ac3);
	Assert.assertEquals(1, c3);
	ac2.setRoleIdNotIn(roleIds);
	Account_ account = accountService.selectOne(ac2);
	Assert.assertEquals("role3", account.getRole().getName());
	LoginLog_ l = new LoginLog_();
	l.setAccount(ac2);
	LoginLog_ loginLog = loginLogService.selectOne(l);
	Assert.assertEquals("role3", loginLog.getAccount().getRole().getName());
	List<String> nameIn = new ArrayList<>();
	nameIn.add("ann");
	nameIn.add("bob");
	Account_Condition ac4 = new Account_Condition();
	ac4.setNameIn(nameIn);
	LoginLog_ l2 = new LoginLog_();
	l2.setAccount(ac4);
	int c4 = loginLogService.count(l2);
	Assert.assertEquals(2, c4);
}
 
Example 10
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 11
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne.datasource2.result.xml")
@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne.datasource2.result.xml")
public void testNPlusOne() {
	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);

	Account2_ a = new Account2_();
	a.setId(21);
	a.setEmail("10");
	a.setRole(r);
	account2Service.insert(a);

	Account2_ a2 = new Account2_();
	a2.setId(22);
	a2.setEmail("11");
	a2.setRole(r);
	account2Service.insert(a2);

	Collection<Account2_> accounts = account2Service.selectAll(new Account2_());
	Assert.assertEquals(2, accounts.size());
}
 
Example 12
Source File: AccountTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 更多的测试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);
}
 
Example 13
Source File: BatchProcessTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/batchProcessTest/testBatchUpdate4.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/batchProcessTest/testBatchUpdate4.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/batchProcessTest/testBatchUpdate4.xml")
public void testBatchUpdate4() {
	Account_Condition ac = new Account_Condition();
	ac.setEmail("[email protected]");
	ac.setNameGreaterOrEqual("b");
	accountService.update(ac);
}
 
Example 14
Source File: ConditionNotInTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 测试无外键情况下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);
}
 
Example 15
Source File: AccountTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 测试delete功能 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/accountTest/testDelete.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/accountTest/testDelete.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/accountTest/testDelete.xml")
public void testDelete() {
	Account_ a = accountService.select(1);
	accountService.delete(a);
}
 
Example 16
Source File: ConditionTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 测试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());
}
 
Example 17
Source File: AccountTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 测试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("[email protected]");
	a.setActivated(false);
	accountService.update(a);
}
 
Example 18
Source File: ConditionTest.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
/** 测试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%%[email protected]", accounts[0].getEmail());
}
 
Example 19
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 20
Source File: AccountTest.java    From mybatis.flying with Apache License 2.0 4 votes vote down vote up
/** 测试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("[email protected]");
	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("[email protected]");
	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());
}