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 ...
随机推荐
- Werkzeug教程
http://chaoxz2005.blog.163.com/blog/static/15036542012863405266/ http://www.dajo.com.cn/a/boke/pytho ...
- Eclipse配置Git
一.Eclipse上安装GIT插件EGit Eclipse的版本eclipse-java-helios-SR2-win32.zip(在Eclipse3.3版本找不到对应的 EGit插件,无法安装) E ...
- Apache HTTP Server suEXEC符号链接任意文件访问漏洞
漏洞版本: Apache HTTP Server 2.2.22 漏洞描述: Apache HTTP Server是一款开源的WEB服务程序 Apache HTTP Server包含的suEXEC会不安 ...
- DIP开放计算平台介绍
随着平台业务的发展,依赖于Portal(Web)构建的服务架构已逐渐不能满足现有的一些复杂需求(如:使用Hive SQL无法完成计算逻辑),而且对于一些具备编程能力的程序员或数据分析师而言,能够自主控 ...
- Android protectionLevel
Android protectionLevel分4个级别: "normal" "dangerous" "signature" "s ...
- 曾经的岁月之maya
- HDOJ 1312题Red and Black
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- JavaScript高级程序设计12.pdf
第六章 面向对象的程序设计 ECMA中有两种属性:数据属性和访问器属性 数据属性的特性 [[Configurable]] 表示是否通过delete删除属性,是否重新定义属性,是否能把属性修改为访问器属 ...
- 深入hibernate的三种状态【转载】
这篇文章写得很好,举了很多例子. http://www.cnblogs.com/xiaoluo501395377/p/3380270.html
- ReactiveCocoa Tutorial
ReactiveCocoa Tutorial – The Definitive Introduction: Part 1/2 ReactiveCocoa教程——明确的介绍:第一部分(共两部分) As ...