package org.secKill.dao;
import org.junit.Test; import org.junit.runner.RunWith; import org.secKill.entity.SecKill; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4Cla***unner;
import javax.annotation.Resource;
import java.util.Date; import java.util.List;
import static org.junit.Assert.*;
/** * Created by 谭雪娇 on 2017/5/4. * 配置spring和junit整合,junit启动时加载springIOC容器 * spring-test,junit */ @RunWith(SpringJUnit4Cla***unner.class) @ContextConfiguration({"classpath:spring/spring-dao.xml"}) public class SecKillDaoTest { //注入Dao实现类依赖 @Resource private SecKillDao secKillDao; @Test public void testQueryById() throws Exception { long id=1000; SecKill secKill=secKillDao.queryById(id); System.out.println(secKill.getName()); System.out.println(secKill);
} //100元秒杀诺基亚 // SecKill{secKillId=1000, name='100元秒杀诺基亚', number=10000, startTime=Fri Feb 17 12:02:05 CST 2017, // endTime=Sat Dec 21 00:00:00 CST 2019, createTime=Wed Dec 21 00:00:00 CST 2016}
@Test public void testQueryAll() throws Exception { // java没有保存形参的记录:queryAll(int off,int,limit)->queryAll(arg0,arg1) List<SecKill> secKills=secKillDao.queryAll(0,100); for(SecKill secKill:secKills){ System.out.println(secKill); } } // SecKill{secKillId=1004, name='1400元秒杀魅族4', number=1099, startTime=Fri Feb 17 12:02:28 CST 2017, endTime=Sat Feb 17 11:48:00 CST 2018, createTime=Fri Feb 17 11:48:00 CST 2017} // SecKill{secKillId=1000, name='100元秒杀诺基亚', number=10000, startTime=Fri Feb 17 12:02:05 CST 2017, endTime=Sat Dec 21 00:00:00 CST 2019, createTime=Wed Dec 21 00:00:00 CST 2016} // SecKill{secKillId=1003, name='1600元秒杀小米4', number=1200, startTime=Fri Feb 17 11:47:47 CST 2017, endTime=Sat Jul 23 00:00:00 CST 2016, createTime=Sat Jul 23 00:00:00 CST 2016} // SecKill{secKillId=1002, name='1000元秒杀ipad1', number=3500, startTime=Fri Feb 17 11:47:41 CST 2017, endTime=Thu May 12 00:00:00 CST 2016, createTime=Thu May 12 00:00:00 CST 2016} // SecKill{secKillId=1001, name='5000元秒杀iphone7', number=1700, startTime=Fri Feb 17 11:47:36 CST 2017, endTime=Mon Apr 11 00:00:00 CST 2016, createTime=Mon Apr 11 00:00:00 CST 2016} // SecKill{secKillId=1005, name='1400元秒杀小米3', number=1100, startTime=Fri Feb 17 11:48:23 CST 2017, endTime=Thu Jan 21 00:00:00 CST 2016, createTime=Thu Jan 21 00:00:00 CST 2016}
@Test public void testReduceNumber() throws Exception { Date KillDate=new Date(); int updateCount=secKillDao.reduceNumber(1000L,KillDate); System.out.println("updateCount:"+updateCount);
}
//updateCount:1 }
|