testuserdao.java

来自「struts+spring+hibernate 集成的例子」· Java 代码 · 共 72 行

JAVA
72
字号
package com.test.dao;

import java.util.List;

import junit.framework.Assert;
import junit.framework.TestCase;

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

import com.lqk.dao.UserDAO;
import com.lqk.vo.Users;

public class TestUserDAO extends TestCase {

	public TestUserDAO(String arg0) {
		super(arg0);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	public UserDAO getDao(){
		String currentPath = null;
		currentPath = TestUserDAO.class.getResource("/").getPath();
		String[] patterns = new String[] {
				currentPath + "../applicationContext.xml"};
		
		ApplicationContext ctx= new FileSystemXmlApplicationContext(patterns);
		return (UserDAO)ctx.getBean("userDAOProxy");
	}
	
	public void testInsertUser(){
		
		Users user = new Users();
		user.setUsername("王武");
		user.setUserpassword("123");
		user.setUsermail("xiaxin@163.com");
		int i = getDao().insertUser(user);	
		System.out.println(i);
		
		Assert.assertNotNull(new Integer(i));
	}
	
	public void testFindUsersForPage(){
		
		List list = getDao().findUsersForPage(80000,100);
		
		Assert.assertNotNull(list);
	}
	
	public void testGetRow(){
		int i = getDao().getAllRow();
		System.out.println("Count:"+i);
		Assert.assertNotNull(new Integer(i));
	}
	
	public void testTemp(){
		int a=300;
		int b=30;
		int c=(a/b)+1;
		int mod = a%b;
		System.out.println("mod:" + mod);
	}
	
}

⌨️ 快捷键说明

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