spring验证事务的代码,用到了mockito
package *.withdraw; import javax.annotation.Resource; import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.AbstractTransactionalSpringContextTests;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.PlatformTransactionManager; import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseOperation;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import *.SasInfoDao;
import *.SasInfo;
import *.SettleBillManagerService;
import *.WithdrawServiceImpl; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/applicationContext-test.xml" })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class,
TransactionalTestExecutionListener.class })
@SuppressWarnings("deprecation")
public class TransactionTest extends AbstractTransactionalSpringContextTests { private static Logger LOGGER = LoggerFactory.getLogger(TransactionTest.class); @Resource
private PlatformTransactionManager transactionManager; @Spy
@Resource
private SasInfoDao sasInfoDao; @Resource
private SettleBillManagerService settleBillManagerService; @InjectMocks
private WithdrawServiceImpl withdrawServiceImpl; @Before
public void init() {
MockitoAnnotations.initMocks(this);
} @Test
@DatabaseSetup(value = { "/testData/sampleData.xml" }, type = DatabaseOperation.CLEAN_INSERT)
public void testSettleBillIssuing() {
this.setTransactionManager(transactionManager);
this.setDefaultRollback(false);
this.startNewTransaction();
Mockito.doThrow(new RuntimeException("fu")).when(sasInfoDao).update(Mockito.any(SasInfo.class));
settleBillManagerService.setSasInfoDao(sasInfoDao);
withdrawServiceImpl.setSettleBillManagerService(settleBillManagerService);
withdrawServiceImpl.operationSettleBillData(55L);
SasInfo sasInfo = settleBillManagerService.findSettleBillById(54L);
LOGGER.debug(sasInfo.toString());
this.endTransaction();
} }
spring验证事务的代码,用到了mockito的更多相关文章
- 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:测试SSH框架分层整合及验证事务是否有效
测试框架分层的整合 HibernateTemplate 和 HibernateDaoSupport,这两个类是 Spring 为整合 Hibernate3 提供的两个工具类. HibernateTem ...
- 普通的jdbc事务在插入数据后 下面的代码报错时 数据不会回滚 但是 spring的事务会回滚
普通的jdbc事务在插入数据后 下面的代码报错时 数据不会回滚 但是 spring的事务会回滚
- 如何实现XA式、非XA式Spring分布式事务
Spring应用的几种事务处理机制 Java Transaction API和XA协议是Spring常用的分布式事务机制,不过你可以选择选择其他的实现方式.理想的实现取决于你的应用程序使用何种资源,你 ...
- 非XA式Spring分布式事务
Spring应用的几种事务处理机制 Java Transaction API和XA协议是Spring常用的分布式事务机制,不过你可以选择选择其他的实现方式.理想的实现取决于你的应用程序使用何种资源,你 ...
- Mybatis整合Spring实现事务管理的源码分析
一:前言 没有完整看完,但是看到了一些关键的地方,这里做个记录,过程会有点乱,以后逐渐补充最终归档为完整流程:相信看过框架源码的都知道过程中无法完全确定是怎样的流程,毕竟不可能全部都去测试一遍 ,但是 ...
- spring的事务操作(重点)
这篇文章一起来回顾复习下spring的事务操作.事务是spring的重点, 也是面试的必问知识点之一. 说来这次面试期间,也问到了我,由于平时用到的比较少,也没有关注过这一块的东西,所以回答的不是特别 ...
- spring jdbcTemplate 事务,各种诡异,包你醍醐灌顶!
前言 项目框架主要是spring,持久层框架没有用mybtis,用的是spring 的jdbc: 业务需求:给应用添加领域(一个领域包含多个应用,一个应用可能属于多个领域,一般而言一个应用只属于一个领 ...
- Spring笔记⑤--整合hibernate代码测试
String整合hibernate代码测试 在上节生成的表中插入数据: 注意:使用myeclipse2014生成的整合项目可能存在问题需要我们自己导入. 第一步 我们写dao接口 packag ...
- Spring系列.事务管理原理简析
Spring的事务管理功能能让我们非常简单地进行事务管理.只需要进行简单的两步配置即可: step1:开启事务管理功能 @Configuration //@EnableTransactionManag ...
随机推荐
- 总结Web应用中基于浏览器的安全漏洞
1.浏览器缓存 每次打开一个网站,网页的内容会缓存到用户的机器中.如果这些内容在其他网页中需要重新加载,浏览器加载的是缓存,而不是再次下载内容.如果一些Web应用商店以及显示用户敏感信息(比 ...
- Windows Azure 配置SSTP
方法參考下面文章的步驟. 这个成功.http://freevpnba.com/windows-azure-sstp-vpn/ 这个没成功,不知道为什么.http://diaosbook.com/pos ...
- buffer busy waits
Buffer busy waits 当会话想要访问缓冲区中的数据块,而该数据块正在被其他会话使用时将产生Buffer busy waits事件. 其他会话可能正从数据文件向缓冲器读取同样的数据块,或正 ...
- 【Better Code】面向切面编程
用AOP改善JavaScript代码http://www.w3cfuns.com/thread-5597323-1-1.html
- (转载)MySQL关键字ORDER BY的使用
例子: mysql), d_id ), name ), age ), sex ), homeaddr )); // 可以看到首先按照d_id进行升序排列,排列好了之后, // 若d_id字段中有相同的 ...
- Jacob - Outlook
import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; public class Util { public ...
- git入门超详细(转载)
转自:http://www.cnblogs.com/tugenhua0707/p/4050072.html Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SV ...
- MacOS下的生活——RescueTime,时间规划利器
前段时间Yxj同学给我推荐了一款可以记录电脑及手机使用时间分类的软件,据说Mac平台下也支持,当时就有了兴趣,但是好像因为什么事给耽搁了,知道今天下午看到Yxj在看这个软件记录的自己的时间表,才觉得这 ...
- [转载]JVM性能调优--JVM参数配置
http://www.cnblogs.com/chen77716/archive/2010/06/26/2130807.html
- 爬虫技术浅析 | WooYun知识库
爬虫技术浅析 | WooYun知识库 爬虫技术浅析 好房通ERP | 房产中介软件最高水准领导者 undefined