package com.mycom.billing;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.beanutils.BeanUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.AbstractSingleSpringContextTests;
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.TransactionConfiguration;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;
import com.mycom.billing.service.BalanceException;
import com.mycom.billing.service.BalanceFreezeException;
import com.mycom.billing.service.PaymentFaileException;
import com.mycom.billing.service.WithdrawService;
import com.mycom.common.lang.DateUtil;
import com.mycom.exception.TargetAlreadyExistsException;
import com.mycom.model.account.AccBankAccount;
import com.mycom.model.account.AccWithdrawCash;
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager = "mycom-persist-transactionManager", defaultRollback = true)
@TestExecutionListeners( { TransactionalTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class })
@Transactional
@ContextConfiguration(locations = {
"classpath*:spring/applicationContext-billing-service.xml",
"classpath*:spring/applicationContext-persist.xml",
"classpath*:spring/applicationContext-logging.xml",
"classpath*:spring/applicationContext-base-service.xml",
"classpath*:spring/applicationContext-*.xml",})
public class WithdrawServiceImplTest extends AbstractSingleSpringContextTests {
@Resource(name = "withdrawService")
private WithdrawService withdrawService;
/**
* 查询提现银行
*/
@Test
public void findWithdrawBankTest() {
AccBankAccount bank = withdrawService.findWithdrawBank(195L);
System.out.println(bank.getsBankAccount() + ":" + bank.getnAccountId()
+ ":" + bank.getnCityId());
}
/**
* 设置提现银行
*
* @param accountId
* @param bankId
* @param branchBankId
* @param bankAccount
* @param cityId
* @throws PaymentFaileException
*/
@Test
// 使用junit4的注释方法进行测试
@Transactional
public void setWithdrawBankTest() {
AccBankAccount bank = new AccBankAccount();
bank.setnAccountId(195L);
bank.setnBankId(2137814318L);
bank.setnBranchId(3L);
bank.setnCityId(82L);
bank.setsBankAccount("217381926313123");
try {
withdrawService.setWithdrawBank(bank);
} catch (PaymentFaileException e) {
e.printStackTrace();
}
AccBankAccount bank1 = withdrawService.findWithdrawBank(195L);
System.out.println(bank1.getsBankAccount() + ":"
+ bank1.getnAccountId() + ":" + bank1.getnCityId());
}
//...
}
//指定测试用例运行器
@RunWith(SpringJUnit4ClassRunner.class)
// 事务配置
// transactionManager="这里是applicationContext.xml文件中事务管理器的名称,默认是transactionManager"
// defaultRollback=true 事务执行后是回滚还是提交,如果不希望测试用数据留在数据库中,可以设置为true
@TransactionConfiguration(transactionManager = "mycom-persist-transactionManager", defaultRollback = true)
// 注册测试用例的监听器。
// 加入TransactionalTestExecutionListener后,它负责解析 @Transactional、@NotTransactional
// 以及 @Rollback 等事务注解的注解。
// @Transaction 注解让测试方法工作于事务环境中,不过在测试方法返回前事务会被回滚。你可以使用 @Rollback(false)
// 让测试方法返回前提交事务。而 @NotTransactional 注解则让测试方法不工作于事务环境中。
// 加入DependencyInjectionTestExecutionListener后,可以识别@Autowired,本类的属性名与applicationContext中bean
// id或name相同,则autowire
@TestExecutionListeners( { TransactionalTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class })
// 使测试用例的所有方法都将工作于事务环境下
@Transactional
// 上下文配置。
// locations:指定applicationContext.xml文件的路径,可以通过该属性手工指定 Spring
// 配置文件所在的位置,可以指定一个或多个 Spring
// 配置文件@ContextConfiguration(locations={“xx/yy/beans1.xml”,” xx/yy/beans2.xml”})
// inheritLocations:是否要继承父测试用例类中的 Spring 配置文件,默认为 true
@ContextConfiguration(locations = {
"classpath*:spring/applicationContext-persist.xml",
"classpath*:spring/applicationContext-account-service.xml",
"classpath*:spring/applicationContext-logging.xml",
"classpath*:spring/applicationContext-base-service.xml" })
分享到:
相关推荐
spring_test_demo:spring_test_demo
spring+springmvc+mybatis+log4j+springtest的demo,并且配置了多环境的配置文件,xml文件在源码中,配置了service层的事务处理,
采用struts1,hibernate,spring整合并分页demo,并作事物管理,数据库采用MySQL,数据可用test内方法生成。采用myeclipse6.5开发
发现csdn上其他的spring5 源码都不能直接运行,花了大量时间自己用gradle 编辑一下spring5.1的源码,可以直接在idea运行,包含demo-test测试模块。导入idea后 ,点项目右键build Module spring 。然后打开demo-test ...
Spring Test & Spring Boot Test:为 Spring Boot 应用提供集成测试和工具支持 AssertJ:支持流式断言的 Java 测试框架 Hamcrest:一个匹配器库 Mockito:一个 java mock 框架 JSONassert:一个针对 JSON 的断言...
activemq+spring demo 简单示例。安装activemq 启动,运行Test
jquery test demo
测试源码下载
整合了mybatis spring springMVC框架,使用者只要需要在mysql数据中定义一个test的数据库,和一个login的表,字段名为 int id、string name、string password的字段,即可。然后通过config.properties的设置好自己的...
my spring demo codes Join Point A point in the execution of a program such as a method call or field assignment Pointcut An expression that selects one or more Join Points Advice Code to be ...
spring boot 项目demo,用于生成 archetype maven生成本项目脚手架教程: spring-boot demo project 集成mybatis,dubbo,service模块为dubbo . 分成4个层次 使用的是spring-boot.version 1.4.1.RELEASE, commons ...
5、spring:3.1.1 hibernate:4.1.6 Hibernate-JPA:2.0 6、若更换数据库后代码有误,无法调通,请先运行com.web.test代码调试数据库配置,运行测试,数据库调通再运行com.web.mvc下的controller。 7、附带的另一...
SpringTest.zip demo(Spring).zip demo(Spring+Hibernate).zip demo(Struts+Spring).zip demo(Struts+Spring+Hibernate).zip demo_ssh_address.zip(个人通讯录系统) demo_ssh_oa.zip(办公自动化系统) lib文件删...
Spring3_MVC+MyBatis3整合搭建基础DEMO 测试表结构 create table T_TEST ( TEST_ID int not null auto_increment, USERNAME varchar(20), PASSWORD varchar(20), CREATE_DATE datetime, primary key (TEST_ID) ...
5、spring:3.1.1 hibernate:4.1.6 Hibernate-JPA:2.0 6、若更换数据库后代码有误,无法调通,请先运行com.web.test代码调试数据库配置,运行测试,数据库调通再运行com.web.mvc下的controller。 7、附带的另一...
创建此示例项目是为了结合 spring-security 讨论正确的 spring-boot 应用程序配置。 当前状态 应用程序的安全配置和集成测试的安全配置。 感谢 Stack Overflow 的 Kris,该应用程序现在按预期工作。 解决方案 如 ...
springcloud入门demo,项目包括:注册中心、服务提供者、服务消费者、feign、ribbon+restTemplate
建数据库test及表table,修改数据库连接即可使用
spring-cloud+注册中心eureka+配置中心demo的简单demo。先启动注册中心和配置中心,最后再起service。访问地址http://localhost:3011/test/getStr。可以输出在配置中心读取到的配置。注册中心地址...
这是本人总结精简之后的一个SpringBoot和SpringSecurity集成的demo项目,本人亲测可正常运行,内置登录页面非本人创作,请勿商用!