- 浏览: 326934 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
m133538:
现在好像行不通了,reflect包用户好像没有 导入的权限的
sun.reflect.Reflection后续 -
7先生:
刚好遇到这个问题,看到这篇文章解决了
合理运用remapResults属性 -
qkjava:
这个问题刚刚碰到
合理运用remapResults属性 -
G_o_o:
恩,我现在也遇到了楼主说的这个情况
少了思考 -
hanmiao:
今天就犯了这个错误,用1.5版本的JDK编译出來的jar运行在 ...
解决Unsupported major.minor version 49.0问题(转)
项目是用Spring+ibatis+jsp开发,一直再看敏捷开发方面的文章,虽然没有做到TDD,也没有做到事后测试,和每个方法都测试,但是也是在一直向这个方向努力,也在努力构建可测试的系统而努力。以前都是在测试一些工具类,现在努力在各个方面构建测试,努力做到自己的成果都是测试过的。 一直以来,数据库方面的测试都是比较困难的,特别是一些SQL语句是否正确,还有就是数据库中数据的不稳定性导致测试不可预见性。
从网上找了很多文章,都是HSQLDB测试Hibernate的 ,ibatis的找了很多都没有找到,只能自己一点点摸索,现在基本上稳定了,也可以了。写下来,经验共享一下,也让大家指点一下。废话少说,上代码。
结构Controller + logic(业务代码)+DAO(基本上只用一个工具类DAO)
- /**
- *数据访问类,所有对数据库访问的DAO都应继承这个抽象类,
- *可以利用其中一些公用方法
- */
- public class DefaultDAO extends SqlMapClientDaoSupport {
Logic基本上就是调用DAO进行一些操作,和一些业务代码,没有什么可介绍的。
下面介绍测试logic的测试基类
- import java.io.Reader;
- import junit.framework.TestCase;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.jdbc.datasource.SingleConnectionDataSource;
- import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
- import propertity.config.SystemConfig;
- import com.ibatis.common.resources.Resources;
- import com.ibatis.sqlmap.client.SqlMapClient;
- import com.ibatis.sqlmap.client.SqlMapClientBuilder;
- public abstract class DefaultLogicTest extends TestCase {
- private SingleConnectionDataSource m_dataSource;
- private SqlMapClient m_sqlMapClient; // Actually initialized in superclass
- private DefaultDAO m_dao;
- protected void setUp() throws Exception {
- super.setUp();
- // 构造DataSource
- m_dataSource = new SingleConnectionDataSource();
- m_dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
- m_dataSource.setUrl("jdbc:hsqldb:file:"+ SystemConfig.WORKSPACE_PATH + getDBScriptPath());
- m_dataSource.setUsername("sa");
- m_dataSource.setPassword("");
- m_dataSource.getConnection().setAutoCommit(false);
- m_dataSource.setSuppressClose(false);
- // 构在SQLMapClient
- Reader reader = Resources.getResourceAsReader(SystemConfig.SQL_MAP_CONFIG_RESOURCE);
- m_sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
- m_sqlMapClient.setUserConnection(m_dataSource.getConnection());
- // 构造默认的DAO
- m_dao = new DefaultDAO();
- m_dao.setDataSource(m_dataSource);
- m_dao.setSqlMapClient(m_sqlMapClient);
- }
- /**
- * 得到DAO
- * @return
- */
- protected DefaultDAO getDao() {
- return m_dao;
- }
- /**
- * 得到数据库的位置
- * @return
- */
- protected String getDBScriptPath() {
- return "/com/aaaa/bbbb/cccc/dddd/action/map/action";
- }
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- m_sqlMapClient.setUserConnection(m_dataSource.getConnection());
- m_sqlMapClient.update("HsqlDB.shutdown", null);
- m_dataSource.getConnection().close();
- m_sqlMapClient.setUserConnection(null);
- }
- }
这个里面需要注意的就是那个得到数据库位置的方法,因为我为每个测试类指定不同的数据库内容,如果不写就默认的,需要写数据库文件后面的.script后缀。
还有就是那个tearDown中的【shutdown】sql,因为Hsqldb如果不调用这句话的话,就会改变Script里面的内容,这个让我困惑了一阵子:) ,还有就是Url中的SystemConfig.WORKSPACE_PATH 常量,主要是自己找了半天资料,也找不到相对路径的写法,于是就定义了一个常量
下面就是具体的测试类
- public class UserLogicTest extends DefaultLogicTest {
- private UserLogic logic;
- protected void setUp() throws Exception {
- super.setUp();
- logic = new UserLogic();
- logic.setDefaultDao(super.getDao());
- }
- /**
- * 没有检索用户销售区域
- */
- public void testQueryUserByName() {
- User user = new User();
- user.setCorpID("1006");
- user.setUserID("PK116055807175866885");
- user.setLoginName("kaka");
- user.setPassword("1q");
- User userDB = logic.queryUserByName(user);
- assertNotNull("销售区域", userDB.getSaleAreaCls());
- }
- /**
- * 维护用户没有更新用户销售区域
- */
- public void testMaintenUser() throws Exception{
- User user = new User();
- user.setCorpID("1006");
- user.setUserID("PK116055807175866885");
- user.setPassword("password");
- user.setSaleAreaCls("0");
- logic.maintenUser(user);
- User userDB = logic.queryUserByID(user);
- assertEquals("销售区域", "0", userDB.getSaleAreaCls());
- }
- /**
- * 测试修改密码
- */
- public void testSaveUserPwd() throws Exception {
- User user = new User();
- user.setCorpID("1006");
- user.setUserID("PK116055807175866885");
- user.setPassword("password");
- // 插入前判断一下
- User userDB = logic.queryUserByID(user);
- assertFalse("密码开始", user.getPassword().equals(userDB.getPassword()));
- logic.saveUserPwd(user);
- userDB = logic.queryUserByID(user);
- assertEquals("密码结束", userDB.getPassword(), user.getPassword());
- }
- /**
- * 测试删除用户
- *
- */
- public void testDeleteUserByPK() throws Exception {
- User user = new User();
- user.setUserID("PK116055807175866884");
- logic.deleteUserByPK(user.getUserID());
- User userDB = logic.queryUserByID(user);
- assertNull("成功删除用户", userDB);
- super.getDao().getDataSource().getConnection().rollback();
- }
- public void testQueryUserRelationAndNotGroupListMap() {
- User user = new User();
- user.setUserID("PK116055807175866885");
- Map groupMap = logic.queryUserRelationAndNotGroupListMap(user.getUserID());
- List relationGroupList = (List)groupMap.get("RELATION");
- List notRelationGroupList = (List)groupMap.get("NOT_RELATION");
- // 关联的
- assertEquals("关联的是3个", 3, relationGroupList.size());
- // 顺序 1,2,test
- testSeq(new String[]{"1", "2", "test"}, relationGroupList);
- // 没有关联的
- assertEquals("没有关联的是4个", 4, notRelationGroupList.size());
- testSeq(new String[]{"原燃料供应商组", "综合供应商组", "销售客户组", "系统测试"}, notRelationGroupList);
- }
- private void testSeq(String[] seqNem, List groupList) {
- for (int i = 0; i < seqNem.length; i++) {
- UserGroup vo = (UserGroup)groupList.get(i);
- assertEquals("名称" + i,seqNem[i], vo.getUserGroupName());
- }
- }
- /**
- * 检查排序问题,大写字母的排在前面
- *
- */
- public void testQueryAllUsers() {
- List userList = logic.queryAllUsers("1006");
- User user = (User)userList.get(0);
- assertEquals("第一个不是大写", "kaka", user.getLoginName());
- }
- /**
- * 保存用户和用户组关联
- *
- */
- public void testSaveRelation() throws Exception {
- RelationGroupFormVO vo = new RelationGroupFormVO();
- vo.setUserID("PK116055807175866885");
- vo.setPk_corp("1006");
- vo.setRel_sel(new String[]{"PK116441420549454662", "PK116458716029826288"});
- logic.saveRelation(vo);
- Map groupMap = logic.queryUserRelationAndNotGroupListMap(vo.getUserID());
- List relationList = (List)groupMap.get("RELATION");
- assertEquals("长度", 2, relationList.size());
- if (relationList.size() <= 0) {
- return;
- }
- testSeq(new String[]{"综合供应商组", "销售客户组"}, relationList);
- }
- /* (non-Javadoc)
- * */
- protected String getDBScriptPath() {
- return "/com/ufida/cvms/basemanagement/usermanager/map/user";
- }
- }
还有就是数据库文件了
- CREATE TABLE BD_CUBASDOC(PK_CUBASDOC CHAR(20) NOT NULL,PK_CORP CHAR(4) NOT NULL,CUSTCODE VARCHAR(30) NOT NULL,CUSTNAME VARCHAR(100) NOT NULL,CUSTSHORTNAME VARCHAR(40) NOT NULL)
- CREATE TABLE CMS_DATADICT(PK_DATADICT CHAR(20) NOT NULL,VTYPE VARCHAR(20),IVALUE INTEGER,CLOCALE CHAR(5) DEFAULT 'zh_CN',VVALUEDESC VARCHAR(64),TS CHAR(19),DR INTEGER DEFAULT 0,VTYPENAME VARCHAR(30))
- CREATE TABLE BD_AREACL(PK_AREACL CHAR(20) NOT NULL,PK_CORP CHAR(4) NOT NULL,AREACLCODE VARCHAR(12) NOT NULL,AREACLNAME VARCHAR(20) NOT NULL,PK_FATHERAREA CHAR(20),TS CHAR(19),DR INTEGER,DEF1 VARCHAR(100),DEF2 VARCHAR(100),DEF3 VARCHAR(100),DEF4 VARCHAR(100),DEF5 VARCHAR(100),MNECODE VARCHAR(10))
- CREATE TABLE CMS_USER(PK_USER CHAR(20) NOT NULL,VLOGINNAME VARCHAR(28),VTRUENAME VARCHAR(32),VPASSWORD VARCHAR(30),VCERTCODE VARCHAR(50),VTEL VARCHAR(30),CCUBASID CHAR(20),CCUMANID CHAR(20),ISALEAREACLS INTEGER,VMOBILE VARCHAR(30),VFAX VARCHAR(30),VEMAIL VARCHAR(50),VMEMO VARCHAR(100),VCORPFULLNAME VARCHAR(128),VCORPSHORTNAME VARCHAR(64),VJURIDICAL VARCHAR(50),VCOUNTRY VARCHAR(64),CAREACLSID CHAR(20),VADDRESS VARCHAR(256),VPOSTALCODE CHAR(6),VTAXNO VARCHAR(32),VMASTERBUSS VARCHAR(128),VBANKNAME VARCHAR(256),VBANKACCOUNT VARCHAR(20),PK_CORP CHAR(4),DACTIVEDATE CHAR(10),DINVALIDATE CHAR(10),IUSERSTATUS INTEGER,DLASTLOGINDATE CHAR(19),IUSERTYPE INTEGER,TS CHAR(19),DR INTEGER)
- CREATE TABLE CMS_USERGROUP(PK_USERGROUP CHAR(20) NOT NULL,VGROUPCODE VARCHAR(28),VGROUPNAME VARCHAR(50),VGROUPDES VARCHAR(50),PK_CORP CHAR(4),TS CHAR(19),DR INTEGER DEFAULT 0)
- CREATE TABLE CMS_USER_GROUP_RELATION(PK_USERGROUP_B CHAR(20) NOT NULL,CUSERGROUPID CHAR(20),CUSERID CHAR(20),TS CHAR(19),DR INTEGER DEFAULT 0)
- CREATE USER SA PASSWORD "" ADMIN
- INSERT INTO BD_CUBASDOC VALUES('0001AA1000000003VQGO','0001','1101649','\u4e2d\u56fd\u77ff\u4ea7\u6709\u9650\u8d23\u4efb\u516c\u53f8','\u4e2d\u56fd\u77ff\u4ea7')
- INSERT INTO CMS_DATADICT VALUES('444 ','YHZT',2,'zh_CN','\u6b63\u5f0f\u7528\u6237','2006-10-17 11:22:26',0,'\u7528\u6237\u72b6\u6001')
- INSERT INTO BD_AREACL VALUES('dqda0000000000000002','0001','1101','\u5317\u4eac\u5e02\u533a','dqda0000000000000001','2002-12-18 00:00:00',0,NULL,NULL,NULL,NULL,NULL,NULL)
- INSERT INTO CMS_USER VALUES('PK116055807175866875','KZka','ABC','aaipjgbcboobnhbc','6666666','6666666666',NULL,NULL,0,'66666666666','11111111666','aaa@saf.com',NULL,'\u56db\u5927\u53d1\u9001\u996d','\u963f\u65af\u8482\u82ac','\u5b8c\u5168\u989d','\u5916\u8033\u5b8c\u5168\u989d','dqda0000000000000002','werewewr','666666','6666666666666','6666666666','66666666666','66666','1006',NULL,NULL,2,'2006-11-24 16:30:44',4,'2006-11-24 16:30:44',0)
- INSERT INTO CMS_USER VALUES('PK116055807175866885','kaka','zjy','aaipjgbcboobnhbc','6666666','6666666666',NULL,NULL,0,'66666666666','11111111666','aaa@saf.com',NULL,'\u56db\u5927\u53d1\u9001\u996d','\u963f\u65af\u8482\u82ac','\u5b8c\u5168\u989d','\u5916\u8033\u5b8c\u5168\u989d','dqda0000000000000002','werewewr','666666','6666666666666','6666666666','66666666666','66666','1006',NULL,NULL,2,'2006-11-24 16:30:44',4,'2006-11-24 16:30:44',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116169875984005137','3','2','1','1006','2006-10-24 21:55:12',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116433523110959947','1','1','1','1006','2006-11-24 10:30:07',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116441420549454662','0003','\u7efc\u5408\u4f9b\u5e94\u5546\u7ec4',NULL,'1006','2006-11-25 09:23:02',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116458716029826288','0011','\u9500\u552e\u5ba2\u6237\u7ec4',NULL,'1006','2006-11-27 09:25:45',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116354770995805209','444','\u7cfb\u7edf\u6d4b\u8bd5','\u521d\u671f\u6d4b\u8bd5\u2015\u2015\u4fe1\u606f\u8bc4\u4ef7\u90e8','1006','2006-11-15 08:40:46',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116354840433039098','0001','\u539f\u71c3\u6599\u4f9b\u5e94\u5546\u7ec4','\u539f\u71c3\u6599\u4f9b\u5e94\u5546','1006','2006-11-15 08:52:20',0)
- INSERT INTO CMS_USERGROUP VALUES('PK116354868037463911','test','test',NULL,'1006','2006-11-15 08:56:56',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779950435','PK116433523110959947','PK116349434520962752','2006-11-27 15:25:44',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779925183','PK116433523110959947','PK116349504077321401','2006-11-27 15:25:44',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779908017','PK116433523110959947','PK116063874195957630','2006-11-27 15:25:44',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779949238','PK116433523110959947','PK116229489004712130','2006-11-27 15:25:44',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779916855','PK116433523110959947','PK116363778699299950','2006-11-27 15:25:44',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116441283966919281','PK116354840433039098','PK116424362932510299','2006-11-25 09:00:16',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116458717250926033','PK116458716029826288','PK116458688918253943','2006-11-27 09:25:57',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354777072528935','PK116354770995805209','PK116349423878288523','2006-11-15 08:41:46',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354777072528436','PK116354770995805209','PK116349434520962752','2006-11-15 08:41:46',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354851343863279','PK116169875984005137','PK116349504077321401','2006-11-15 08:54:09',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759089179','PK116354868037463911','PK116349434520962752','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759059525','PK116354868037463911','PK116424376929524473','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759049917','PK116354868037463911','PK116219721663024806','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759090900','PK116354868037463911','PK116349504077321401','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759076081','PK116354868037463911','PK116063874195957630','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759075198','PK116354868037463911','PK116229489004712130','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759033542','PK116354868037463911','PK116349423878288523','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759085854','PK116354868037463911','PK116055807175866885','2006-11-23 10:15:34',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354851343860249','PK116169875984005137','PK116055807175866885','2006-11-15 08:54:09',0)
- INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779999473','PK116433523110959947','PK116055807175866885','2006-11-27 15:25:44',0)
HSQLDB就是从这个*.script文件里面读入表和数据,然后就可以调用各种方法测试里面的数据。需要注意的是,测试类找不到WEB-INF下面的Sql_Map_Config文件,所以拷贝了一份,放到了测试源文件的包根目录下。
大体上就是这些了,写下来,记录一下,也为这段时间的辛勤劳作一个小小的表彰:)
评论
<p>那么这个shutdown到底是执行的什么呢?如果这里不是真实的数据库环境,倒是不如用hsqldb的内存模式来测试吧,这样也就不需要去还原数据库来保证测试不修改数据库数据了。</p>
<p> </p>
<p> </p>
<p> </p>
</div>
<br/>
真实系统也是采用HSQLDB的么?<br/>
<br/>
<br/>
<br/>
<strong>sinokaka 写道:</strong><br/>
<div class='quote_div'>
<p> 项目是用Spring+ibatis+jsp开发,一直再看敏捷开发方面的文章,虽然没有做到TDD,也没有做到事后测试,和每个方法都测试,但是也是在一直向这个方向努力,也在努力构建可测试的系统而努力。以前都是在测试一些工具类,现在努力在各个方面构建测试,努力做到自己的成果都是测试过的。 一直以来,数据库方面的测试都是比较困难的,特别是一些SQL语句是否正确,还有就是数据库中数据的不稳定性导致测试不可预见性。</p>
<p> 从网上找了很多文章,都是HSQLDB测试H<font>ibernate的 ,ibatis的找了很多都没有找到,只能自己一点点摸索,现在基本上稳定了,也可以了。写下来,经验共享一下,也让大家指点一下。废话少说,上代码。</font></p>
<p> 结构Controller + logic(业务代码)+DAO(基本上只用一个工具类DAO)</p>
<div class='code_title'>先看DAO代码,基本上也没有做什么,只是继承了Spring的SqlMapClientDaoSupport</div>
<div class='code_title'>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j'>
<li class='alt'><span><span class='comment'>/** </span> </span> </li>
<li class=''><span><span class='comment'>*数据访问类,所有对数据库访问的DAO都应继承这个抽象类, </span> </span> </li>
<li class='alt'><span><span class='comment'>*可以利用其中一些公用方法 </span> </span> </li>
<li class=''><span><span class='comment'>*/</span><span> </span></span> </li>
<li class='alt'><span/><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> DefaultDAO </span><span class='keyword'>extends</span><span> SqlMapClientDaoSupport { </span> </li>
</ol>
</div>
</div>
<p> </p>
<p>Logic基本上就是调用DAO进行一些操作,和一些业务代码,没有什么可介绍的。</p>
<p>下面介绍测试logic的测试基类</p>
<div class='code_title'>java 代码</div>
<div class='code_title'>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j'>
<li class='alt'><span><span class='keyword'>import</span><span> java.io.Reader; </span></span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span/><span class='keyword'>import</span><span> junit.framework.TestCase; </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span/><span class='keyword'>import</span><span> org.springframework.jdbc.datasource.DriverManagerDataSource; </span> </li>
<li class=''><span/><span class='keyword'>import</span><span> org.springframework.jdbc.datasource.SingleConnectionDataSource; </span> </li>
<li class='alt'><span/><span class='keyword'>import</span><span> org.springframework.orm.ibatis.SqlMapClientFactoryBean; </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span/><span class='keyword'>import</span><span> propertity.config.SystemConfig; </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span/><span class='keyword'>import</span><span> com.ibatis.common.resources.Resources; </span> </li>
<li class=''><span/><span class='keyword'>import</span><span> com.ibatis.sqlmap.client.SqlMapClient; </span> </li>
<li class='alt'><span/><span class='keyword'>import</span><span> com.ibatis.sqlmap.client.SqlMapClientBuilder; </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span/><span class='keyword'>public</span><span> </span><span class='keyword'>abstract</span><span> </span><span class='keyword'>class</span><span> DefaultLogicTest </span><span class='keyword'>extends</span><span> TestCase { </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='keyword'>private</span><span> SingleConnectionDataSource m_dataSource; </span> </li>
<li class=''><span> </span><span class='keyword'>private</span><span> SqlMapClient m_sqlMapClient; </span><span class='comment'>// Actually initialized in superclass </span><span> </span> </li>
<li class='alt'><span> </span><span class='keyword'>private</span><span> DefaultDAO m_dao; </span> </li>
<li class=''><span> </span><span class='keyword'>protected</span><span> </span><span class='keyword'>void</span><span> setUp() </span><span class='keyword'>throws</span><span> Exception { </span> </li>
<li class='alt'><span> </span><span class='keyword'>super</span><span>.setUp(); </span> </li>
<li class=''><span> </span><span class='comment'>// 构造DataSource </span><span> </span> </li>
<li class='alt'><span> m_dataSource = </span><span class='keyword'>new</span><span> SingleConnectionDataSource(); </span> </li>
<li class=''><span> m_dataSource.setDriverClassName(</span><span class='string'>"org.hsqldb.jdbcDriver"</span><span>); </span> </li>
<li class='alt'><span> m_dataSource.setUrl(</span><span class='string'>"jdbc:hsqldb:file:"</span><span>+ SystemConfig.WORKSPACE_PATH + getDBScriptPath()); </span> </li>
<li class=''><span> m_dataSource.setUsername(</span><span class='string'>"sa"</span><span>); </span> </li>
<li class='alt'><span> m_dataSource.setPassword(</span><span class='string'>""</span><span>); </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> m_dataSource.getConnection().setAutoCommit(</span><span class='keyword'>false</span><span>); </span> </li>
<li class=''><span> m_dataSource.setSuppressClose(</span><span class='keyword'>false</span><span>); </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>// 构在SQLMapClient </span><span> </span> </li>
<li class='alt'><span> Reader reader = Resources.getResourceAsReader(SystemConfig.SQL_MAP_CONFIG_RESOURCE); </span> </li>
<li class=''><span> m_sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); </span> </li>
<li class='alt'><span> m_sqlMapClient.setUserConnection(m_dataSource.getConnection()); </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='comment'>// 构造默认的DAO </span><span> </span> </li>
<li class=''><span> m_dao = </span><span class='keyword'>new</span><span> DefaultDAO(); </span> </li>
<li class='alt'><span> m_dao.setDataSource(m_dataSource); </span> </li>
<li class=''><span> m_dao.setSqlMapClient(m_sqlMapClient); </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='comment'>/** </span> </li>
<li class=''><span><span class='comment'> * 得到DAO </span> </span> </li>
<li class='alt'><span><span class='comment'> * @return </span> </span> </li>
<li class=''><span><span class='comment'> */</span><span> </span></span> </li>
<li class='alt'><span> </span><span class='keyword'>protected</span><span> DefaultDAO getDao() { </span> </li>
<li class=''><span> </span><span class='keyword'>return</span><span> m_dao; </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='comment'>/** </span> </li>
<li class=''><span><span class='comment'> * 得到数据库的位置 </span> </span> </li>
<li class='alt'><span><span class='comment'> * @return </span> </span> </li>
<li class=''><span><span class='comment'> */</span><span> </span></span> </li>
<li class='alt'><span> </span><span class='keyword'>protected</span><span> String getDBScriptPath() { </span> </li>
<li class=''><span> </span><span class='keyword'>return</span><span> </span><span class='string'>"/com/aaaa/bbbb/cccc/dddd/action/map/action"</span><span>; </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='comment'>/* (non-Javadoc) </span> </li>
<li class=''><span><span class='comment'> * @see junit.framework.TestCase#tearDown() </span> </span> </li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span> </li>
<li class=''><span> </span><span class='keyword'>protected</span><span> </span><span class='keyword'>void</span><span> tearDown() </span><span class='keyword'>throws</span><span> Exception { </span> </li>
<li class='alt'><span> </span><span class='keyword'>super</span><span>.tearDown(); </span> </li>
<li class=''><span> m_sqlMapClient.setUserConnection(m_dataSource.getConnection()); </span> </li>
<li class='alt'><span> m_sqlMapClient.update(</span><span class='string'>"HsqlDB.shutdown"</span><span>, </span><span class='keyword'>null</span><span>); </span> </li>
<li class=''><span> m_dataSource.getConnection().close(); </span> </li>
<li class='alt'><span> m_sqlMapClient.setUserConnection(</span><span class='keyword'>null</span><span>); </span> </li>
<li class=''><span> } </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span>} </span> </li>
</ol>
</div>
</div>
<p> </p>
<p> 这个里面需要注意的就是那个得到数据库位置的方法,因为我为每个测试类指定不同的数据库内容,如果不写就默认的,需要写数据库文件后面的.script后缀。</p>
<p>还有就是那个tearDown中的【shutdown】sql,因为Hsqldb如果不调用这句话的话,就会改变Script里面的内容,这个让我困惑了一阵子:) ,还有就是Url中的SystemConfig.WORKSPACE_PATH 常量,主要是自己找了半天资料,也找不到相对路径的写法,于是就定义了一个常量</p>
<p>下面就是具体的测试类</p>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-j'>
<li class='alt'><span><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> UserLogicTest </span><span class='keyword'>extends</span><span> DefaultLogicTest { </span></span> </li>
<li class=''><span> </span><span class='keyword'>private</span><span> UserLogic logic; </span> </li>
<li class='alt'><span> </span><span class='keyword'>protected</span><span> </span><span class='keyword'>void</span><span> setUp() </span><span class='keyword'>throws</span><span> Exception { </span> </li>
<li class=''><span> </span><span class='keyword'>super</span><span>.setUp(); </span> </li>
<li class='alt'><span> logic = </span><span class='keyword'>new</span><span> UserLogic(); </span> </li>
<li class=''><span> logic.setDefaultDao(</span><span class='keyword'>super</span><span>.getDao()); </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='comment'>/** </span> </li>
<li class=''><span><span class='comment'> * 没有检索用户销售区域 </span> </span> </li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span> </li>
<li class=''><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testQueryUserByName() { </span> </li>
<li class='alt'><span> User user = </span><span class='keyword'>new</span><span> User(); </span> </li>
<li class=''><span> user.setCorpID(</span><span class='string'>"1006"</span><span>); </span> </li>
<li class='alt'><span> user.setUserID(</span><span class='string'>"PK116055807175866885"</span><span>); </span> </li>
<li class=''><span> user.setLoginName(</span><span class='string'>"kaka"</span><span>); </span> </li>
<li class='alt'><span> user.setPassword(</span><span class='string'>"1q"</span><span>); </span> </li>
<li class=''><span> User userDB = logic.queryUserByName(user); </span> </li>
<li class='alt'><span> assertNotNull(</span><span class='string'>"销售区域"</span><span>, userDB.getSaleAreaCls()); </span> </li>
<li class=''><span> } </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>/** </span> </li>
<li class='alt'><span><span class='comment'> * 维护用户没有更新用户销售区域 </span> </span> </li>
<li class=''><span><span class='comment'> */</span><span> </span></span> </li>
<li class='alt'><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testMaintenUser() </span><span class='keyword'>throws</span><span> Exception{ </span> </li>
<li class=''><span> User user = </span><span class='keyword'>new</span><span> User(); </span> </li>
<li class='alt'><span> user.setCorpID(</span><span class='string'>"1006"</span><span>); </span> </li>
<li class=''><span> user.setUserID(</span><span class='string'>"PK116055807175866885"</span><span>); </span> </li>
<li class='alt'><span> user.setPassword(</span><span class='string'>"password"</span><span>); </span> </li>
<li class=''><span> user.setSaleAreaCls(</span><span class='string'>"0"</span><span>); </span> </li>
<li class='alt'><span> logic.maintenUser(user); </span> </li>
<li class=''><span> User userDB = logic.queryUserByID(user); </span> </li>
<li class='alt'><span> assertEquals(</span><span class='string'>"销售区域"</span><span>, </span><span class='string'>"0"</span><span>, userDB.getSaleAreaCls()); </span> </li>
<li class=''><span> } </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>/** </span> </li>
<li class='alt'><span><span class='comment'> * 测试修改密码 </span> </span> </li>
<li class=''><span><span class='comment'> */</span><span> </span></span> </li>
<li class='alt'><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testSaveUserPwd() </span><span class='keyword'>throws</span><span> Exception { </span> </li>
<li class=''><span> User user = </span><span class='keyword'>new</span><span> User(); </span> </li>
<li class='alt'><span> user.setCorpID(</span><span class='string'>"1006"</span><span>); </span> </li>
<li class=''><span> user.setUserID(</span><span class='string'>"PK116055807175866885"</span><span>); </span> </li>
<li class='alt'><span> user.setPassword(</span><span class='string'>"password"</span><span>); </span> </li>
<li class=''><span> </span><span class='comment'>// 插入前判断一下 </span><span> </span> </li>
<li class='alt'><span> User userDB = logic.queryUserByID(user); </span> </li>
<li class=''><span> assertFalse(</span><span class='string'>"密码开始"</span><span>, user.getPassword().equals(userDB.getPassword())); </span> </li>
<li class='alt'><span> logic.saveUserPwd(user); </span> </li>
<li class=''><span> userDB = logic.queryUserByID(user); </span> </li>
<li class='alt'><span> assertEquals(</span><span class='string'>"密码结束"</span><span>, userDB.getPassword(), user.getPassword()); </span> </li>
<li class=''><span> } </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>/** </span> </li>
<li class='alt'><span><span class='comment'> * 测试删除用户 </span> </span> </li>
<li class=''><span><span class='comment'> * </span> </span> </li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span> </li>
<li class=''><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testDeleteUserByPK() </span><span class='keyword'>throws</span><span> Exception { </span> </li>
<li class='alt'><span> User user = </span><span class='keyword'>new</span><span> User(); </span> </li>
<li class=''><span> user.setUserID(</span><span class='string'>"PK116055807175866884"</span><span>); </span> </li>
<li class='alt'><span> logic.deleteUserByPK(user.getUserID()); </span> </li>
<li class=''><span> User userDB = logic.queryUserByID(user); </span> </li>
<li class='alt'><span> assertNull(</span><span class='string'>"成功删除用户"</span><span>, userDB); </span> </li>
<li class=''><span> </span><span class='keyword'>super</span><span>.getDao().getDataSource().getConnection().rollback(); </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testQueryUserRelationAndNotGroupListMap() { </span> </li>
<li class=''><span> User user = </span><span class='keyword'>new</span><span> User(); </span> </li>
<li class='alt'><span> user.setUserID(</span><span class='string'>"PK116055807175866885"</span><span>); </span> </li>
<li class=''><span> Map groupMap = logic.queryUserRelationAndNotGroupListMap(user.getUserID()); </span> </li>
<li class='alt'><span> List relationGroupList = (List)groupMap.get(</span><span class='string'>"RELATION"</span><span>); </span> </li>
<li class=''><span> List notRelationGroupList = (List)groupMap.get(</span><span class='string'>"NOT_RELATION"</span><span>); </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>// 关联的 </span><span> </span> </li>
<li class='alt'><span> assertEquals(</span><span class='string'>"关联的是3个"</span><span>, </span><span class='number'>3</span><span>, relationGroupList.size()); </span> </li>
<li class=''><span> </span><span class='comment'>// 顺序 1,2,test </span><span> </span> </li>
<li class='alt'><span> testSeq(</span><span class='keyword'>new</span><span> String[]{</span><span class='string'>"1"</span><span>, </span><span class='string'>"2"</span><span>, </span><span class='string'>"test"</span><span>}, relationGroupList); </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>// 没有关联的 </span><span> </span> </li>
<li class='alt'><span> assertEquals(</span><span class='string'>"没有关联的是4个"</span><span>, </span><span class='number'>4</span><span>, notRelationGroupList.size()); </span> </li>
<li class=''><span> testSeq(</span><span class='keyword'>new</span><span> String[]{</span><span class='string'>"原燃料供应商组"</span><span>, </span><span class='string'>"综合供应商组"</span><span>, </span><span class='string'>"销售客户组"</span><span>, </span><span class='string'>"系统测试"</span><span>}, notRelationGroupList); </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='keyword'>private</span><span> </span><span class='keyword'>void</span><span> testSeq(String[] seqNem, List groupList) { </span> </li>
<li class=''><span> </span><span class='keyword'>for</span><span> (</span><span class='keyword'>int</span><span> i = </span><span class='number'>0</span><span>; i < seqNem.length; i++) { </span> </li>
<li class='alt'><span> UserGroup vo = (UserGroup)groupList.get(i); </span> </li>
<li class=''><span> assertEquals(</span><span class='string'>"名称"</span><span> + i,seqNem[i], vo.getUserGroupName()); </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> } </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>/** </span> </li>
<li class='alt'><span><span class='comment'> * 检查排序问题,大写字母的排在前面 </span> </span> </li>
<li class=''><span><span class='comment'> * </span> </span> </li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span> </li>
<li class=''><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testQueryAllUsers() { </span> </li>
<li class='alt'><span> List userList = logic.queryAllUsers(</span><span class='string'>"1006"</span><span>); </span> </li>
<li class=''><span> User user = (User)userList.get(</span><span class='number'>0</span><span>); </span> </li>
<li class='alt'><span> assertEquals(</span><span class='string'>"第一个不是大写"</span><span>, </span><span class='string'>"kaka"</span><span>, user.getLoginName()); </span> </li>
<li class=''><span> } </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span> </span><span class='comment'>/** </span> </li>
<li class='alt'><span><span class='comment'> * 保存用户和用户组关联 </span> </span> </li>
<li class=''><span><span class='comment'> * </span> </span> </li>
<li class='alt'><span><span class='comment'> */</span><span> </span></span> </li>
<li class=''><span> </span><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> testSaveRelation() </span><span class='keyword'>throws</span><span> Exception { </span> </li>
<li class='alt'><span> RelationGroupFormVO vo = </span><span class='keyword'>new</span><span> RelationGroupFormVO(); </span> </li>
<li class=''><span> vo.setUserID(</span><span class='string'>"PK116055807175866885"</span><span>); </span> </li>
<li class='alt'><span> vo.setPk_corp(</span><span class='string'>"1006"</span><span>); </span> </li>
<li class=''><span> vo.setRel_sel(</span><span class='keyword'>new</span><span> String[]{</span><span class='string'>"PK116441420549454662"</span><span>, </span><span class='string'>"PK116458716029826288"</span><span>}); </span> </li>
<li class='alt'><span> logic.saveRelation(vo); </span> </li>
<li class=''><span> Map groupMap = logic.queryUserRelationAndNotGroupListMap(vo.getUserID()); </span> </li>
<li class='alt'><span> List relationList = (List)groupMap.get(</span><span class='string'>"RELATION"</span><span>); </span> </li>
<li class=''><span> assertEquals(</span><span class='string'>"长度"</span><span>, </span><span class='number'>2</span><span>, relationList.size()); </span> </li>
<li class='alt'><span> </span><span class='keyword'>if</span><span> (relationList.size() <= </span><span class='number'>0</span><span>) { </span> </li>
<li class=''><span> </span><span class='keyword'>return</span><span>; </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> testSeq(</span><span class='keyword'>new</span><span> String[]{</span><span class='string'>"综合供应商组"</span><span>, </span><span class='string'>"销售客户组"</span><span>}, relationList); </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span><span class='comment'>/* (non-Javadoc) </span> </li>
<li class=''><span><span class='comment'> * */</span><span> </span></span> </li>
<li class='alt'><span> </span><span class='keyword'>protected</span><span> String getDBScriptPath() { </span> </li>
<li class=''><span> </span><span class='keyword'>return</span><span> </span><span class='string'>"/com/ufida/cvms/basemanagement/usermanager/map/user"</span><span>; </span> </li>
<li class='alt'><span> } </span> </li>
<li class=''><span> </span> </li>
<li class='alt'><span> </span> </li>
<li class=''><span>} </span> </li>
</ol>
</div>
<p>还有就是数据库文件了</p>
<div class='code_title'>sql 代码</div>
<div class='dp-highlighter'>
<div class='bar'> </div>
<ol class='dp-sql'>
<li class='alt'><span><span class='keyword'>CREATE</span><span> </span><span class='keyword'>TABLE</span><span> BD_CUBASDOC(PK_CUBASDOC </span><span class='keyword'>CHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,PK_CORP </span><span class='keyword'>CHAR</span><span>(4) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,CUSTCODE </span><span class='keyword'>VARCHAR</span><span>(30) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,CUSTNAME </span><span class='keyword'>VARCHAR</span><span>(100) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,CUSTSHORTNAME </span><span class='keyword'>VARCHAR</span><span>(40) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>) </span></span> </li>
<li class=''><span/><span class='keyword'>CREATE</span><span> </span><span class='keyword'>TABLE</span><span> CMS_DATADICT(PK_DATADICT </span><span class='keyword'>CHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,VTYPE </span><span class='keyword'>VARCHAR</span><span>(20),IVALUE </span><span class='keyword'>INTEGER</span><span>,CLOCALE </span><span class='keyword'>CHAR</span><span>(5) </span><span class='keyword'>DEFAULT</span><span> 'zh_CN',VVALUEDESC </span><span class='keyword'>VARCHAR</span><span>(64),TS </span><span class='keyword'>CHAR</span><span>(19),DR </span><span class='keyword'>INTEGER</span><span> </span><span class='keyword'>DEFAULT</span><span> 0,VTYPENAME </span><span class='keyword'>VARCHAR</span><span>(30)) </span> </li>
<li class='alt'><span/><span class='keyword'>CREATE</span><span> </span><span class='keyword'>TABLE</span><span> BD_AREACL(PK_AREACL </span><span class='keyword'>CHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,PK_CORP </span><span class='keyword'>CHAR</span><span>(4) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,AREACLCODE </span><span class='keyword'>VARCHAR</span><span>(12) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,AREACLNAME </span><span class='keyword'>VARCHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,PK_FATHERAREA </span><span class='keyword'>CHAR</span><span>(20),TS </span><span class='keyword'>CHAR</span><span>(19),DR </span><span class='keyword'>INTEGER</span><span>,DEF1 </span><span class='keyword'>VARCHAR</span><span>(100),DEF2 </span><span class='keyword'>VARCHAR</span><span>(100),DEF3 </span><span class='keyword'>VARCHAR</span><span>(100),DEF4 </span><span class='keyword'>VARCHAR</span><span>(100),DEF5 </span><span class='keyword'>VARCHAR</span><span>(100),MNECODE </span><span class='keyword'>VARCHAR</span><span>(10)) </span> </li>
<li class=''><span/><span class='keyword'>CREATE</span><span> </span><span class='keyword'>TABLE</span><span> CMS_USER(PK_USER </span><span class='keyword'>CHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,VLOGINNAME </span><span class='keyword'>VARCHAR</span><span>(28),VTRUENAME </span><span class='keyword'>VARCHAR</span><span>(32),VPASSWORD </span><span class='keyword'>VARCHAR</span><span>(30),VCERTCODE </span><span class='keyword'>VARCHAR</span><span>(50),VTEL </span><span class='keyword'>VARCHAR</span><span>(30),CCUBASID </span><span class='keyword'>CHAR</span><span>(20),CCUMANID </span><span class='keyword'>CHAR</span><span>(20),ISALEAREACLS </span><span class='keyword'>INTEGER</span><span>,VMOBILE </span><span class='keyword'>VARCHAR</span><span>(30),VFAX </span><span class='keyword'>VARCHAR</span><span>(30),VEMAIL </span><span class='keyword'>VARCHAR</span><span>(50),VMEMO </span><span class='keyword'>VARCHAR</span><span>(100),VCORPFULLNAME </span><span class='keyword'>VARCHAR</span><span>(128),VCORPSHORTNAME </span><span class='keyword'>VARCHAR</span><span>(64),VJURIDICAL </span><span class='keyword'>VARCHAR</span><span>(50),VCOUNTRY </span><span class='keyword'>VARCHAR</span><span>(64),CAREACLSID </span><span class='keyword'>CHAR</span><span>(20),VADDRESS </span><span class='keyword'>VARCHAR</span><span>(256),VPOSTALCODE </span><span class='keyword'>CHAR</span><span>(6),VTAXNO </span><span class='keyword'>VARCHAR</span><span>(32),VMASTERBUSS </span><span class='keyword'>VARCHAR</span><span>(128),VBANKNAME </span><span class='keyword'>VARCHAR</span><span>(256),VBANKACCOUNT </span><span class='keyword'>VARCHAR</span><span>(20),PK_CORP </span><span class='keyword'>CHAR</span><span>(4),DACTIVEDATE </span><span class='keyword'>CHAR</span><span>(10),DINVALIDATE </span><span class='keyword'>CHAR</span><span>(10),IUSERSTATUS </span><span class='keyword'>INTEGER</span><span>,DLASTLOGINDATE </span><span class='keyword'>CHAR</span><span>(19),IUSERTYPE </span><span class='keyword'>INTEGER</span><span>,TS </span><span class='keyword'>CHAR</span><span>(19),DR </span><span class='keyword'>INTEGER</span><span>) </span> </li>
<li class='alt'><span/><span class='keyword'>CREATE</span><span> </span><span class='keyword'>TABLE</span><span> CMS_USERGROUP(PK_USERGROUP </span><span class='keyword'>CHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,VGROUPCODE </span><span class='keyword'>VARCHAR</span><span>(28),VGROUPNAME </span><span class='keyword'>VARCHAR</span><span>(50),VGROUPDES </span><span class='keyword'>VARCHAR</span><span>(50),PK_CORP </span><span class='keyword'>CHAR</span><span>(4),TS </span><span class='keyword'>CHAR</span><span>(19),DR </span><span class='keyword'>INTEGER</span><span> </span><span class='keyword'>DEFAULT</span><span> 0) </span> </li>
<li class=''><span/><span class='keyword'>CREATE</span><span> </span><span class='keyword'>TABLE</span><span> CMS_USER_GROUP_RELATION(PK_USERGROUP_B </span><span class='keyword'>CHAR</span><span>(20) </span><span class='op'>NOT</span><span> </span><span class='op'>NULL</span><span>,CUSERGROUPID </span><span class='keyword'>CHAR</span><span>(20),CUSERID </span><span class='keyword'>CHAR</span><span>(20),TS </span><span class='keyword'>CHAR</span><span>(19),DR </span><span class='keyword'>INTEGER</span><span> </span><span class='keyword'>DEFAULT</span><span> 0) </span> </li>
<li class='alt'><span/><span class='keyword'>CREATE</span><span> </span><span class='func'>USER</span><span> SA </span><span class='keyword'>PASSWORD</span><span> </span><span class='string'>""</span><span> ADMIN </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> BD_CUBASDOC </span><span class='keyword'>VALUES</span><span>('0001AA1000000003VQGO','0001','1101649','\u4e2d\u56fd\u77ff\u4ea7\u6709\u9650\u8d23\u4efb\u516c\u53f8','\u4e2d\u56fd\u77ff\u4ea7') </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_DATADICT </span><span class='keyword'>VALUES</span><span>('444 ','YHZT',2,'zh_CN','\u6b63\u5f0f\u7528\u6237','2006-10-17 11:22:26',0,'\u7528\u6237\u72b6\u6001') </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> BD_AREACL </span><span class='keyword'>VALUES</span><span>('dqda0000000000000002','0001','1101','\u5317\u4eac\u5e02\u533a','dqda0000000000000001','2002-12-18 00:00:00',0,</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER </span><span class='keyword'>VALUES</span><span>('PK116055807175866875','KZka','ABC','aaipjgbcboobnhbc','6666666','6666666666',</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,0,'66666666666','11111111666','aaa@saf.com',</span><span class='op'>NULL</span><span>,'\u56db\u5927\u53d1\u9001\u996d','\u963f\u65af\u8482\u82ac','\u5b8c\u5168\u989d','\u5916\u8033\u5b8c\u5168\u989d','dqda0000000000000002','werewewr','666666','6666666666666','6666666666','66666666666','66666','1006',</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,2,'2006-11-24 16:30:44',4,'2006-11-24 16:30:44',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER </span><span class='keyword'>VALUES</span><span>('PK116055807175866885','kaka','zjy','aaipjgbcboobnhbc','6666666','6666666666',</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,0,'66666666666','11111111666','aaa@saf.com',</span><span class='op'>NULL</span><span>,'\u56db\u5927\u53d1\u9001\u996d','\u963f\u65af\u8482\u82ac','\u5b8c\u5168\u989d','\u5916\u8033\u5b8c\u5168\u989d','dqda0000000000000002','werewewr','666666','6666666666666','6666666666','66666666666','66666','1006',</span><span class='op'>NULL</span><span>,</span><span class='op'>NULL</span><span>,2,'2006-11-24 16:30:44',4,'2006-11-24 16:30:44',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116169875984005137','3','2','1','1006','2006-10-24 21:55:12',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116433523110959947','1','1','1','1006','2006-11-24 10:30:07',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116441420549454662','0003','\u7efc\u5408\u4f9b\u5e94\u5546\u7ec4',</span><span class='op'>NULL</span><span>,'1006','2006-11-25 09:23:02',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116458716029826288','0011','\u9500\u552e\u5ba2\u6237\u7ec4',</span><span class='op'>NULL</span><span>,'1006','2006-11-27 09:25:45',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116354770995805209','444','\u7cfb\u7edf\u6d4b\u8bd5','\u521d\u671f\u6d4b\u8bd5\u2015\u2015\u4fe1\u606f\u8bc4\u4ef7\u90e8','1006','2006-11-15 08:40:46',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116354840433039098','0001','\u539f\u71c3\u6599\u4f9b\u5e94\u5546\u7ec4','\u539f\u71c3\u6599\u4f9b\u5e94\u5546','1006','2006-11-15 08:52:20',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USERGROUP </span><span class='keyword'>VALUES</span><span>('PK116354868037463911','test','test',</span><span class='op'>NULL</span><span>,'1006','2006-11-15 08:56:56',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116461221779950435','PK116433523110959947','PK116349434520962752','2006-11-27 15:25:44',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116461221779925183','PK116433523110959947','PK116349504077321401','2006-11-27 15:25:44',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116461221779908017','PK116433523110959947','PK116063874195957630','2006-11-27 15:25:44',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116461221779949238','PK116433523110959947','PK116229489004712130','2006-11-27 15:25:44',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116461221779916855','PK116433523110959947','PK116363778699299950','2006-11-27 15:25:44',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116441283966919281','PK116354840433039098','PK116424362932510299','2006-11-25 09:00:16',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116458717250926033','PK116458716029826288','PK116458688918253943','2006-11-27 09:25:57',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116354777072528935','PK116354770995805209','PK116349423878288523','2006-11-15 08:41:46',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116354777072528436','PK116354770995805209','PK116349434520962752','2006-11-15 08:41:46',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116354851343863279','PK116169875984005137','PK116349504077321401','2006-11-15 08:54:09',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759089179','PK116354868037463911','PK116349434520962752','2006-11-23 10:15:34',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759059525','PK116354868037463911','PK116424376929524473','2006-11-23 10:15:34',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759049917','PK116354868037463911','PK116219721663024806','2006-11-23 10:15:34',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759090900','PK116354868037463911','PK116349504077321401','2006-11-23 10:15:34',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759076081','PK116354868037463911','PK116063874195957630','2006-11-23 10:15:34',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759075198','PK116354868037463911','PK116229489004712130','2006-11-23 10:15:34',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759033542','PK116354868037463911','PK116349423878288523','2006-11-23 10:15:34',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116424456759085854','PK116354868037463911','PK116055807175866885','2006-11-23 10:15:34',0) </span> </li>
<li class=''><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116354851343860249','PK116169875984005137','PK116055807175866885','2006-11-15 08:54:09',0) </span> </li>
<li class='alt'><span/><span class='keyword'>INSERT</span><span> </span><span class='keyword'>INTO</span><span> CMS_USER_GROUP_RELATION </span><span class='keyword'>VALUES</span><span>('PK116461221779999473','PK116433523110959947','PK116055807175866885','2006-11-27 15:25:44',0) </span> </li>
</ol>
</div>
<p>HSQLDB就是从这个*.script文件里面读入表和数据,然后就可以调用各种方法测试里面的数据。需要注意的是,测试类找不到WEB-INF下面的Sql_Map_Config文件,所以拷贝了一份,放到了测试源文件的包根目录下。</p>
<p>大体上就是这些了,写下来,记录一下,也为这段时间的辛勤劳作一个小小的表彰:)</p>
</div>
<br/>
<br/>
<br/>
这个东西最不可理解了...
给仔细说说是怎么放到内存数据库中的....?
发表评论
-
项目总结--事务管理自动代理
2007-02-10 23:03 2461项目使用了Spring的声明式事务管理,其是 ... -
Spring 流水线
2006-10-20 14:40 1544这两天一直在看《J2EE Development wi ... -
A Look At Design
2006-09-19 09:19 1126在开始介绍各种Controller之前,我们先来讨论个 ... -
HandlerMapping
2006-09-19 09:21 3314一个WEB应用程序基本上都要依赖于URL与请求处理器之间的映射 ... -
URLPath匹配原则
2006-09-19 09:23 1799路径匹配原则(Path Matching) Spring MV ...
相关推荐
总之,"spring+hibernate+hsqldb 测试"项目展示了如何在Java应用中整合Spring、Hibernate和HSQLDB进行数据持久化操作的测试实践,这对于理解和学习Java企业级开发以及相关框架的集成具有很高的价值。
在Spring中,可以通过`SqlMapClientTemplate`类对iBATIS(现为MyBatis)进行操作。它提供了一组与`HibernateTemplate`类似的模板方法,用于执行iBATIS的SQL映射文件中的SQL语句。 4. **JPA(Java Persistence API...
标题中的"lib1 flex+spring+struts2+ibatis需要的jar 1 完整的jar 需要下载我提供的资源lib2"表明这是一个关于Java Web开发的库集合,其中包含了四个关键的技术框架:Flex、Spring、Struts2和iBatis。这些框架在构建...
jPetStore是一个经典的开源项目,它展示了如何使用Spring、Struts和Ibatis等技术构建一个完整的MVC(Model-View-Controller)架构的Web应用程序。这个项目是Java开发者学习和实践这些技术的绝佳案例。最新版本的...
通过整合Struts、Spring与ibatis,JpetStore 4.0不仅展现了ibatis在数据持久化方面的高效与灵活性,也展示了Struts与Spring在构建高效、可维护的J2EE应用程序中的协同优势。这种模式下的开发,不仅减少了代码量,...
Spring+EasyJWeb+iBatis版j2ee在线购物jpetstore系统,业务层及持久层使用springframework上的jpetsotre源码,表示层使用EasyJWeb,该系统是一个简单的J2EE网上商店系统,包括商品列表、购物车、用户管理、在线订单...
HSQldb是一个轻量级的关系型...HSQldb的灵活性和易用性使其成为开发人员的首选数据库之一,特别是在快速迭代和测试环境中。其强大的特性,如内存数据库、自动创建数据库以及内置的管理工具,都极大地简化了数据库管理。
这个jar文件包含了运行HSQldb所需的所有类和资源,开发者可以直接将其引入项目中使用。描述中的"一份中文使用说明"是为了帮助中国用户更好地理解和使用HSQldb,提供了详细的中文操作指南,这对于初学者来说是非常有...
HSQLDB常被用作开发和测试环境中的数据库,因为它易于设置和使用。例如,Spring Boot默认使用HSQLDB作为内存数据库。此外,很多Java IDE,如IntelliJ IDEA,都内置了对HSQLDB的支持,方便开发者进行数据库操作。 ##...
我们可以使用内存数据库(如H2)或者嵌入式数据库(如HSQLDB)来避免在测试中实际访问生产数据库。同时,使用JPA或Hibernate等持久层框架的测试工具,如Hibernate Test或者Spring Data JPA的@...
**jbpm4测试例子(项目中含hsqldb数据库)** jbpm4 是一个开源的工作流管理系统,它提供了业务流程管理(BPM)和工作流服务。jbpm4的测试例子是一个很好的学习资源,帮助开发者了解如何在实际项目中集成和使用jbpm4。...
ibatis可以使用简单的XML或注解进行配置和原始映射,将接口和Java的POJOs(Plain Old Java Objects,普通的Java对象)映射成数据库中的记录。 #### 二、ibatis配置文件解析 ibatis的核心配置文件是`SqlMapConfig.xml...
- **开发和测试**:HSQLDB常用于开发环境中的单元测试和集成测试,因为它快速启动、无需额外配置,且能模拟多种数据库行为。 - **嵌入式系统**:在资源有限的嵌入式设备上,HSQLDB作为内置数据库,能够提供高效的...
标题和描述中提到的"lib1 flex+struts2+spring+ibatis jar 完整的jar 需要下载本人资源lib2"是一个关于Java Web开发中的关键库集合,这些库是构建基于Flex前端、Struts2作为MVC框架、Spring作为依赖注入和整体应用...
- **安装步骤**:无需复杂安装,只需将HSQLDB包解压至所需的目录即可使用。 #### 三、HSQLDB的运行与使用 - **运行工具**:包括HsqldbServer、HsqldbWebServer等。 - **HsqldbServer**:提供数据库服务的服务器端...