spring多个xml配置文件测试方式1

/**
* 2010-7-6 上午11:47:21
*/
package com.wichina.test;

import java.util.Date;
import java.util.List;

import junit.framework.TestCase;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.wichina.dao.BookDAO;
import com.wichina.model.Book;

/**
* @author wuquanyou
*
*/
public class BookDAOTest extends TestCase {
private ApplicationContext context = null;

@Override
protected void setUp() throws Exception {

//context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/classes/applicationContext.xml");
context = new ClassPathXmlApplicationContext(new String[]{"application_dao.xml","application_data.xml","application_action.xml","application_service.xml","application_sso.xml"});
}
@Override
protected void tearDown() throws Exception {

super.tearDown();
}


public void getCount(){
BookDAO bookDAO = (BookDAO)context.getBean("bookDAO");
int i =bookDAO.countBookStateByUser("jade", (short)1);
System.out.println(i);
}

public void save(){
BookDAO bookDAO = (BookDAO)context.getBean("bookDAO");
Book book = null;
for(int i=1;i<6;i++){
book = new Book();
book.setAppNo("12323ad"+i);
book.setAuthorName("dfdfd"+i);
book.setCreateDate(new Date());
book.setCreateUser("jade");
book.setIntro("fdfdfd");
book.setModifyDate(new Date());
book.setName("火影");
book.setPropery((short)1);
book.setState((short)i);
book.setStyle((short)2);
book.setTotalEpisode(4);
book.setType((short)1);
bookDAO.save(book);
}
}

public void delete(){
BookDAO bookDAO = (BookDAO)context.getBean("bookDAO");
if(bookDAO.delete(2)){
System.out.println("successful");
}
}

public void getMaxId(){
BookDAO bookDAO = (BookDAO)context.getBean("bookDAO");
System.out.println(bookDAO.getMaxId());
}

public void findByPropery(){
BookDAO bookDAO = (BookDAO)context.getBean("bookDAO");
List<Book> bookl = bookDAO.findByProperty("appNo", "abc65");
for(Book b : bookl){
System.out.println(b.getName());
}
}
}

你可能感兴趣的:(java,DAO,spring,xml,SSO)