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的更多相关文章

  1. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:测试SSH框架分层整合及验证事务是否有效

    测试框架分层的整合 HibernateTemplate 和 HibernateDaoSupport,这两个类是 Spring 为整合 Hibernate3 提供的两个工具类. HibernateTem ...

  2. 普通的jdbc事务在插入数据后 下面的代码报错时 数据不会回滚 但是 spring的事务会回滚

    普通的jdbc事务在插入数据后 下面的代码报错时 数据不会回滚 但是 spring的事务会回滚

  3. 如何实现XA式、非XA式Spring分布式事务

    Spring应用的几种事务处理机制 Java Transaction API和XA协议是Spring常用的分布式事务机制,不过你可以选择选择其他的实现方式.理想的实现取决于你的应用程序使用何种资源,你 ...

  4. 非XA式Spring分布式事务

    Spring应用的几种事务处理机制 Java Transaction API和XA协议是Spring常用的分布式事务机制,不过你可以选择选择其他的实现方式.理想的实现取决于你的应用程序使用何种资源,你 ...

  5. Mybatis整合Spring实现事务管理的源码分析

    一:前言 没有完整看完,但是看到了一些关键的地方,这里做个记录,过程会有点乱,以后逐渐补充最终归档为完整流程:相信看过框架源码的都知道过程中无法完全确定是怎样的流程,毕竟不可能全部都去测试一遍 ,但是 ...

  6. spring的事务操作(重点)

    这篇文章一起来回顾复习下spring的事务操作.事务是spring的重点, 也是面试的必问知识点之一. 说来这次面试期间,也问到了我,由于平时用到的比较少,也没有关注过这一块的东西,所以回答的不是特别 ...

  7. spring jdbcTemplate 事务,各种诡异,包你醍醐灌顶!

    前言 项目框架主要是spring,持久层框架没有用mybtis,用的是spring 的jdbc: 业务需求:给应用添加领域(一个领域包含多个应用,一个应用可能属于多个领域,一般而言一个应用只属于一个领 ...

  8. Spring笔记⑤--整合hibernate代码测试

    String整合hibernate代码测试 在上节生成的表中插入数据:   注意:使用myeclipse2014生成的整合项目可能存在问题需要我们自己导入.   第一步 我们写dao接口 packag ...

  9. Spring系列.事务管理原理简析

    Spring的事务管理功能能让我们非常简单地进行事务管理.只需要进行简单的两步配置即可: step1:开启事务管理功能 @Configuration //@EnableTransactionManag ...

随机推荐

  1. mysql 2006

    1.在my.ini文件中添加或者修改以下两个变量:wait_timeout=2880000interactive_timeout = 2880000 关于两个变量的具体说明可以google或者看官方手 ...

  2. 开启Eclipse 智能感知代码功能

    1.打开windows->Perferences..窗口,选择java->Editor->Content Assist,在右下方的“Auto Activation triggers  ...

  3. GNOME Shell叫板Ubuntu Unity:优劣PK

    转自GNOME Shell叫板Ubuntu Unity:优劣PK GNOME Shell 对阵 Ubuntu Unity--默认桌面界面的战火一触即发.双方在台上已经对峙了很长时间,现在是时候决定谁会 ...

  4. C++必备知识

    新进C++程序员应在一年内完成学习“basic”类别知识点,两年内完成学习“advance”类别知识点,三到四年内完成学习“expert”1.基础(Basic)(1)变量与基本类型:(2)typede ...

  5. sublime配置python开发

    想在sublime里要python shell那种交互或者run module F5 F5 F5下这种效果的话,还是挺容易实现的,windows下的:1. 打开Sublime text 3 安装pac ...

  6. 译文:TransactionScope 与 Async/Await

    你可能不知道这一点,在 .NET Framework 4.5.0  版本中包含有一个关于 System.Transactions.TransactionScope 在与 async/await 一起工 ...

  7. WordPress A Forms插件HTML注入漏洞和跨站请求伪造漏洞

    漏洞名称: WordPress A Forms插件HTML注入漏洞和跨站请求伪造漏洞 CNNVD编号: CNNVD-201308-281 发布时间: 2013-08-20 更新时间: 2013-08- ...

  8. java生成随机整数

    1. 使用Random类的nextInt方法: Random rand = new Random(); rand.nextInt(max);, 此时输出[0,max),注意右边是开区间,如果需要设定最 ...

  9. shell 执行jar 的命令

    #!/bin/sh ############## #判断是否程序已启动 jappname='Test' mainclasspath="com.company.commontest.test& ...

  10. c语言 快速排序---归并排序----堆排序

    //快速排序: #include <stdio.h> #define MAX 500000 int s[MAX]; void Q_Sort(int start,int end) { int ...