import static org.junit.Assert.*;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
//设置junit运行的类
@RunWith(SpringJUnit4ClassRunner.class)
//设置运行时的spring配置文件
@ContextConfiguration(locations={"/spring/sa/applicationContext.xml" })
public class MytookDaoImplTest {
@Autowired//这个也是要加上去的
@Test
@Transactional
public void testGetBy_id() {
//fail("Not yet implemented");
Leave leave=(Leave)staffLeaveDao.getBy_id(8);
System.out.println(leave.getStaff().getName()+leave.getLeavecase());
}
@Test
//当有事务存在的时候,测试的时候也要再加上事务处理,不然就会出现找不到session
@Transactional
public void testGetBy_state() {
List<Leave> leaves=staffLeaveDao.getBy_state(2);
for (Iterator<Leave> iterator = leaves.iterator(); iterator.hasNext();) {
Leave leave = (Leave) iterator.next();
System.out.println(leave.getStaff().getName()+leave.getLeavecase());
}
}
///一种得到list的写法
List<CertificateManager> resulist=this.getSession()
.createQuery("select c from CertificateManager c inner join c.certificate cf where cf.cernum=:cernum")
.setString("cernum", cernum).list();
//一种得到结果的方法
Certifi certi=()getHibernateTemplate()
// .find("from Certifi c left join Certi cf where cf.cernum=:cernum", cernum);
//li另一种写法:
certif=(Certif)new Configuration().configure()
// .buildSessionFactory().getCurrentSession()
// .createQuery("from tablename where :id=:id ")
// .setString("tablename",tablename)
// .setInteger("id",id);
//其他写法
List<Cert> certificateManagers=(List<Cert>)this.getSession()
.createQuery("from Cert c where c.registime ='"+date+"'").list();
//getHibernateTemplate().find("queryString", values)