⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookdaotest.java

📁 有简单的网上书店需求及设计流程
💻 JAVA
字号:
package org.wiely.dao.impl;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.wiely.dao.BookDAO;
import org.wiely.vo.Admin;
import org.wiely.vo.Book;

public class BookDAOTest extends TestCase {

	private Book book;
	private BookDAO bookDAO;

	@Override
	protected void setUp() throws Exception {
		ApplicationContext context = new FileSystemXmlApplicationContext(
				"classpath:applicationContext.xml");
		book = new Book();
		Admin admin =new Admin();
		admin.setAdminid(3);	
		bookDAO = (BookDAO) context.getBean("bookDAO");
		book.setBookauthor("wiely");
		book.setBookname("a test");
		book.setIntroduction("test again");
		book.setIsnew("是");
		book.setPrice(45.0);
		book.setPublisher("a test");
		book.setIsbn("d123456");
		book.setAdmin(admin);
		
	

	}

	public void testInsertBook() throws Exception {
		bookDAO.insertBook(book);
	}

	@SuppressWarnings("unchecked")
	public void testGetNewBooks() throws Exception {
		List l = new ArrayList();

		l = bookDAO.getNewBooks();
		assertNotNull(l);
	}

	@SuppressWarnings("unchecked")
	public void testQueryAllBooks() throws Exception {
		List l = new ArrayList();

		l = bookDAO.queryAllBooks(1, 2);

		assertNotNull(l);
	}

	public void testQueryBookByBookisbn() throws Exception {
		Book book1 = new Book();
		String bookisbn = "S123456";
		book1 = bookDAO.queryBookByBookisbn(bookisbn);

		assertNotNull(book1);
	}

	@SuppressWarnings("unchecked")
	public void testQueryBooksByAdminid() throws Exception {
		List l = new ArrayList();
		int adminid = 1;
		l = bookDAO.queryBooksByAdminid(adminid,1,2);

		assertNotNull(l);

	}

	@SuppressWarnings("unchecked")
	public void testQueryBooksByName() throws Exception {
		List l = new ArrayList();
		String bookname = "a test";
		l = bookDAO.queryBooksByName(bookname,1,2);

		assertNotNull(l);
	}

	public void testUpdateBook() throws Exception {		

		book.setBookname("testUpdate");
		book.setBookid(2);
		bookDAO.updateBook(book);
	}

	public void testDelBook() throws Exception {
		int bookid =3;
		bookDAO.delBook(bookid);
	}

	@Override
	protected void tearDown() throws Exception {
		book = null;
		bookDAO = null;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -