* Copyright (c) 2005-2012 springside.org.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.hyzy.core.test.spring;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
/**
* Spring的支持数据库访问, 事务控制和依赖注入的JUnit4 集成测试基类.
* 相比Spring原基类名字更短并保存了dataSource变量.
*
* 子类需要定义applicationContext文件的位置, 如:
* @ContextConfiguration(locations = { "/applicationContext.xml" })
*
* @author calvin
*/
@ActiveProfiles("test")
public abstract class SpringTransactionalTestCase extends AbstractTransactionalJUnit4SpringContextTests {
protected DataSource dataSource;
@Override
@Autowired
public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource);
this.dataSource = dataSource;
}
}
@ContextConfiguration(locations = { "/applicationContext.xml" })
public class TradeServiceTest extends SpringTransactionalTestCase {
@Resource
private TradeService tradeService;
@Rollback(false) //当rollback为true时会自动回滚不会修改数据库数据
@Test
public void createOrder(){
List<Trade> list = tradeService.getAllUnprocessedTrade(TradeStatus.unprocessed,PaymentStatus.paid, ShippingStatus.unshipped);
int size=list.size()>8 ?8:list.size();
System.out.println(new Date()+"需要提交至物流系统的订单数为:"+size);
for(int i=0;null!=list&&i<size;i++){
omsA.importOrder(list.get(i));
}
}