现在的位置: 首页 > 综合 > 正文

spring 元单测试

2014年02月23日 ⁄ 综合 ⁄ 共 3426字 ⁄ 字号 评论关闭

package jnuit.test;

import java.util.List;

import org.hibernate.SessionFactory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.huawei.bean.Person;
import com.huawei.common.dao.CommonDao;
import com.huawei.person.PersonAction;
import com.huawei.service.PersonService;

/********************************************************* *  
   Copy right (c) 2005-2008 RLL RIGHTS RESSERVED BY SYNICS Ltd.
 *               All rights reserved
 *  @author 吴文来  E-mail:wenlaixl@163.com
 *  @version 1.0
 *  Create Date: 2009-12-22 19:05:43
 *  Update Date: 2009-12-22 19:05:43
 *
 * **********************************************************/
public class MyTest
{
    private static PersonService personService;
    private static CommonDao commonDaos;
    private static PersonAction personAction;
    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
         //ApplicationContext ac  = new ClassPathXmlApplicationContext("beans.xml");
       
         String string = "F:/worspace/ssh2/WebRoot/WEB-INF/conf/";
         String s1 = string+"spring_beans.xml";
         String s2 = string+"test/spring_dao.xml";
         String s3 = string+"test/spring_facade.xml";
         String[] files = {s1,s2,s3};
         ApplicationContext ac = new FileSystemXmlApplicationContext(files);
         personService  = (PersonService)ac.getBean("personService");
         commonDaos     = (CommonDao)ac.getBean("commonDaos");
         personAction   = (PersonAction)ac.getBean("personList");
    }
   
    @Test
    public void testAction()
    {
       String aa= personAction.paginBy();
       System.out.println("aa "+aa);
       System.out.println("cc"+personAction.getPageBar());
      
    }
   
    @Test
    public void testcommondao()
    {
        List<Person> person =commonDaos.getPageins(0, 1, "from Person");
        for(Person sp:person)
                System.out.println("sp  "+sp.getName());
    }
   
//    @Test
//    public void testget()
//    {
//        Person person = (Person)personService.getPerson(2);
//        try
//        {
//            System.out.println(person.getName());
//            System.out.println("???????");
//            Thread.sleep(1000*16);
//        } catch (InterruptedException e)
//        {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//        System.out.println("????????");
//        System.out.println(person.getName());
//    }
//   
//    @Test
//    public void  testsave()
//    {
//        Person person = new Person();
//        person.setName("???1");
//        personService.add(person);
//    }
//   
//    @Test
//    public void testupdate()
//    {
//        Person person = (Person)personService.getPerson(1);
//        person.setName("ok2!");
//        personService.update(person);
//    }
//   
//    @Test
//    public void testdelete()
//    {
//        personService.delete(1);
//    }
//   
//    @Test
//    public void testPersonList()
//    {
//      List<Person>    person = (List<Person>)personService.getPersonList();
//      for(Person ps:person)
//          System.out.println(ps.getName());
//    }
    @Test
    public void testPersonPageid()
    {
       Person personbean = new Person();
       personbean.setName("abc");
       List<Person>    person = (List<Person>)personService.getPagein(0,10,personbean);
      
       for(Person ps:person)
          System.out.println(ps.getId());
       List<Person>    person2 = (List<Person>)personService.getTest("From Person b where 1=1");
      
       for(Person ps2:person2)
          System.out.println(ps2.getId());
    }
}

抱歉!评论已关闭.