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

📄 testpagesqlhelper.java.svn-base

📁 文件上传用例,纯sql分页源码,有用的着地方请下载 试用
💻 SVN-BASE
字号:
package org.derrick.jdbc.page.sql;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import junit.framework.TestCase;
/**
 * 
 * @author 刘冬宝Oct 26, 2006
   版权申明:所有人员均可自由修改源码并再发布,但必须保留此相关信息
 *
 */
abstract public class TestPageSqlHelper extends TestCase {

	protected final Logger logger = LogManager.getLogger(getClass());

	protected PageSqlHelper helper = null;

	public TestPageSqlHelper(String name) {
		super(name);
	}

	abstract protected void checkFirstPageSql();

	abstract protected void checkLastPageSql();

	abstract protected void checkMiddlePageSql();

	private void initForGetPageSql() {
		this.initForTotalRecordCountSql();
		this.helper.setRecordnumPerPage(getRecordnumPerPage());
		this.helper.setRecordTotalnum(getRecordTotalnum());
	}

	protected int getRecordTotalnum() {
		return 50;
	}

	protected int getRecordnumPerPage() {
		return 10;
	}

	protected void initForTotalRecordCountSql() {
		helper.setFieldClause("a.id,a.name");
		helper.setConditionClause("pageDemo a where a.id >5");
		helper.setOrderByClause("a.id asc");
	}

	public final void ptestGetRecordTotalCountSqlForCheckConditionNotAscOrDesc() {
		try {
			helper
					.setConditionClause(" pageDemo a where a.id >0 order by a.di ");
			helper.getRecordTotalnumSql();
			fail("must throw exceptions!");
		} catch (RuntimeException e) {
			assertTrue(true);
			logger.debug(e.getMessage());
		}
	}

	public final void testGetPageSqlFirstPage() {
		initForGetPageSql();
		checkFirstPageSql();

	}

	public final void testGetPageSqlLastPage() {
		initForGetPageSql();
		checkLastPageSql();

	}

	public final void testGetPageSqlMiddlePage() {
		initForGetPageSql();
		checkMiddlePageSql();

	}

	/*
	 * Test method for
	 * 'org.derrick.jdbc.page.sql.PageSqlHelper.getRecordTotalCountSql()'
	 */
	public final void testGetRecordTotalCountSql() {
		initForTotalRecordCountSql();
		String expectSql = "select count(*) from "
				+ helper.getConditionClause();
		String actualSql = helper.getRecordTotalnumSql();
		assertEquals(expectSql, actualSql);

	}

	public final void testGetRecordTotalCountSqlForCheckConditionHasFromClause() {
		try {
			helper.setConditionClause("from pageDemo a where a.id >0 ");
			helper.getRecordTotalnumSql();
			fail("must throw exceptions!");
		} catch (RuntimeException e) {
			assertTrue(true);
			logger.debug(e.getMessage());
		}
	}

	public final void testGetRecordTotalCountSqlForCheckConditionHasOrderByClause() {
		try {
			helper
					.setConditionClause(" pageDemo a where a.id >0 order by a.di asc");
			helper.getRecordTotalnumSql();
			fail("must throw exceptions!");
		} catch (RuntimeException e) {
			assertTrue(true);
			logger.debug(e.getMessage());
		}
	}

	public final void testGetRecordTotalCountSqlForCheckNullCondition() {
		try {
			helper.getRecordTotalnumSql();
			fail("must throw exceptions!");
		} catch (RuntimeException e) {
			assertTrue(true);
			logger.debug(e.getMessage());
		}
	}

	public final void testGetTotalPage() {
		this.helper.setRecordnumPerPage(10);
		this.helper.setRecordTotalnum(56);
		int expectCount = 6;
		assertEquals(expectCount, helper.getTotalPage());

	}

}

⌨️ 快捷键说明

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