|
|
package spring;
|
|
|
|
|
|
import jeecg.system.service.SystemService;
|
|
|
|
|
|
import org.junit.Before;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
import org.springframework.test.context.transaction.TransactionConfiguration;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/*
|
|
|
* @TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)
|
|
|
* transactionManager的默认取值是"transactionManager",
|
|
|
* defaultRollback的默认取值是true,当然,你也可以改成false。
|
|
|
* true表示测试不会对数据库造成污染,false的话当然就会改动到数据库中了。
|
|
|
* 在方法名上添加@Rollback(false)表示这个测试用例不需要回滚。
|
|
|
*/
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
@ContextConfiguration(locations = { "classpath:spring*.xml" })
|
|
|
@TransactionConfiguration(defaultRollback = true)
|
|
|
@Transactional
|
|
|
public class SpringTxTestCase extends AbstractJUnit4SpringContextTests {
|
|
|
|
|
|
|
|
|
protected SystemService systemService;
|
|
|
|
|
|
@Autowired
|
|
|
public void setSystemService(final SystemService systemService) {
|
|
|
this.systemService = systemService;
|
|
|
}
|
|
|
|
|
|
@Before
|
|
|
public void beforeClass() {
|
|
|
systemService.initAllTypeGroups();
|
|
|
}
|
|
|
public <T> T getBean(Class<T> type) {
|
|
|
return applicationContext.getBean(type);
|
|
|
}
|
|
|
|
|
|
public Object getBean(String beanName) {
|
|
|
return applicationContext.getBean(beanName);
|
|
|
}
|
|
|
|
|
|
protected ApplicationContext getContext() {
|
|
|
return applicationContext;
|
|
|
}
|
|
|
}
|