`
sinokaka
  • 浏览: 327093 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Spring中使用HSQLDB测试ibatis的dao

阅读更多

         项目是用Spring+ibatis+jsp开发,一直再看敏捷开发方面的文章,虽然没有做到TDD,也没有做到事后测试,和每个方法都测试,但是也是在一直向这个方向努力,也在努力构建可测试的系统而努力。以前都是在测试一些工具类,现在努力在各个方面构建测试,努力做到自己的成果都是测试过的。 一直以来,数据库方面的测试都是比较困难的,特别是一些SQL语句是否正确,还有就是数据库中数据的不稳定性导致测试不可预见性。

        从网上找了很多文章,都是HSQLDB测试Hibernate的 ,ibatis的找了很多都没有找到,只能自己一点点摸索,现在基本上稳定了,也可以了。写下来,经验共享一下,也让大家指点一下。废话少说,上代码。

      结构Controller + logic(业务代码)+DAO(基本上只用一个工具类DAO)

先看DAO代码,基本上也没有做什么,只是继承了Spring的SqlMapClientDaoSupport
java 代码
  1. /**   
  2. *数据访问类,所有对数据库访问的DAO都应继承这个抽象类,  
  3. *可以利用其中一些公用方法   
  4. */  
  5. public class DefaultDAO extends SqlMapClientDaoSupport {   

 

Logic基本上就是调用DAO进行一些操作,和一些业务代码,没有什么可介绍的。

下面介绍测试logic的测试基类

java 代码
java 代码
  1. import java.io.Reader;   
  2.   
  3. import junit.framework.TestCase;   
  4.   
  5. import org.springframework.jdbc.datasource.DriverManagerDataSource;   
  6. import org.springframework.jdbc.datasource.SingleConnectionDataSource;   
  7. import org.springframework.orm.ibatis.SqlMapClientFactoryBean;   
  8.   
  9. import propertity.config.SystemConfig;   
  10.   
  11. import com.ibatis.common.resources.Resources;   
  12. import com.ibatis.sqlmap.client.SqlMapClient;   
  13. import com.ibatis.sqlmap.client.SqlMapClientBuilder;   
  14.   
  15. public abstract class DefaultLogicTest extends TestCase {   
  16.   
  17.     private SingleConnectionDataSource m_dataSource;   
  18.     private SqlMapClient m_sqlMapClient; // Actually initialized in superclass   
  19.     private DefaultDAO m_dao;   
  20.     protected void setUp() throws Exception {   
  21.         super.setUp();   
  22.         // 构造DataSource   
  23.         m_dataSource = new SingleConnectionDataSource();   
  24.         m_dataSource.setDriverClassName("org.hsqldb.jdbcDriver");   
  25.         m_dataSource.setUrl("jdbc:hsqldb:file:"+ SystemConfig.WORKSPACE_PATH + getDBScriptPath());   
  26.         m_dataSource.setUsername("sa");   
  27.         m_dataSource.setPassword("");   
  28.            
  29.         m_dataSource.getConnection().setAutoCommit(false);   
  30.         m_dataSource.setSuppressClose(false);   
  31.            
  32.         // 构在SQLMapClient   
  33.         Reader reader = Resources.getResourceAsReader(SystemConfig.SQL_MAP_CONFIG_RESOURCE);   
  34.         m_sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);   
  35.         m_sqlMapClient.setUserConnection(m_dataSource.getConnection());   
  36.   
  37.         // 构造默认的DAO   
  38.         m_dao = new DefaultDAO();   
  39.         m_dao.setDataSource(m_dataSource);   
  40.         m_dao.setSqlMapClient(m_sqlMapClient);   
  41.     }   
  42.        
  43.     /**  
  44.      * 得到DAO  
  45.      * @return  
  46.      */  
  47.     protected DefaultDAO getDao() {   
  48.         return m_dao;   
  49.     }   
  50.        
  51.     /**  
  52.      * 得到数据库的位置  
  53.      * @return  
  54.      */  
  55.     protected String getDBScriptPath() {   
  56.         return "/com/aaaa/bbbb/cccc/dddd/action/map/action";   
  57.     }   
  58.   
  59.     /* (non-Javadoc)  
  60.      * @see junit.framework.TestCase#tearDown()  
  61.      */  
  62.     protected void tearDown() throws Exception {   
  63.         super.tearDown();   
  64.         m_sqlMapClient.setUserConnection(m_dataSource.getConnection());   
  65.         m_sqlMapClient.update("HsqlDB.shutdown"null);   
  66.         m_dataSource.getConnection().close();   
  67.         m_sqlMapClient.setUserConnection(null);   
  68.     }   
  69.        
  70.        
  71. }   

 

         这个里面需要注意的就是那个得到数据库位置的方法,因为我为每个测试类指定不同的数据库内容,如果不写就默认的,需要写数据库文件后面的.script后缀。

还有就是那个tearDown中的【shutdown】sql,因为Hsqldb如果不调用这句话的话,就会改变Script里面的内容,这个让我困惑了一阵子:) ,还有就是Url中的SystemConfig.WORKSPACE_PATH 常量,主要是自己找了半天资料,也找不到相对路径的写法,于是就定义了一个常量

下面就是具体的测试类

java 代码
  1. public class UserLogicTest extends DefaultLogicTest {   
  2.     private UserLogic logic;   
  3.     protected void setUp() throws Exception {   
  4.         super.setUp();   
  5.         logic = new UserLogic();   
  6.         logic.setDefaultDao(super.getDao());   
  7.     }   
  8.   
  9.     /**  
  10.      * 没有检索用户销售区域  
  11.      */  
  12.     public void testQueryUserByName() {   
  13.         User user = new User();   
  14.         user.setCorpID("1006");   
  15.         user.setUserID("PK116055807175866885");   
  16.         user.setLoginName("kaka");   
  17.         user.setPassword("1q");   
  18.         User userDB = logic.queryUserByName(user);   
  19.         assertNotNull("销售区域", userDB.getSaleAreaCls());   
  20.     }   
  21.        
  22.     /**  
  23.      * 维护用户没有更新用户销售区域  
  24.      */  
  25.     public void testMaintenUser() throws Exception{   
  26.         User user = new User();   
  27.         user.setCorpID("1006");   
  28.         user.setUserID("PK116055807175866885");   
  29.         user.setPassword("password");   
  30.         user.setSaleAreaCls("0");   
  31.         logic.maintenUser(user);   
  32.         User userDB = logic.queryUserByID(user);   
  33.         assertEquals("销售区域""0", userDB.getSaleAreaCls());   
  34.     }   
  35.        
  36.     /**  
  37.      * 测试修改密码  
  38.      */  
  39.     public void testSaveUserPwd() throws Exception {   
  40.         User user = new User();   
  41.         user.setCorpID("1006");   
  42.         user.setUserID("PK116055807175866885");   
  43.         user.setPassword("password");   
  44.         // 插入前判断一下   
  45.         User userDB = logic.queryUserByID(user);   
  46.         assertFalse("密码开始", user.getPassword().equals(userDB.getPassword()));   
  47.         logic.saveUserPwd(user);   
  48.         userDB = logic.queryUserByID(user);   
  49.         assertEquals("密码结束", userDB.getPassword(), user.getPassword());   
  50.     }   
  51.   
  52.     /**  
  53.      * 测试删除用户  
  54.      *  
  55.      */  
  56.     public void testDeleteUserByPK() throws Exception {   
  57.         User user = new User();   
  58.         user.setUserID("PK116055807175866884");   
  59.         logic.deleteUserByPK(user.getUserID());   
  60.         User userDB = logic.queryUserByID(user);   
  61.         assertNull("成功删除用户", userDB);   
  62.         super.getDao().getDataSource().getConnection().rollback();   
  63.     }   
  64.        
  65.     public void testQueryUserRelationAndNotGroupListMap() {   
  66.         User user = new User();   
  67.         user.setUserID("PK116055807175866885");   
  68.         Map groupMap = logic.queryUserRelationAndNotGroupListMap(user.getUserID());   
  69.         List relationGroupList = (List)groupMap.get("RELATION");   
  70.         List notRelationGroupList = (List)groupMap.get("NOT_RELATION");   
  71.            
  72.         // 关联的   
  73.         assertEquals("关联的是3个"3, relationGroupList.size());   
  74.         // 顺序 1,2,test   
  75.         testSeq(new String[]{"1""2""test"}, relationGroupList);   
  76.            
  77.            
  78.         // 没有关联的   
  79.         assertEquals("没有关联的是4个"4, notRelationGroupList.size());   
  80.         testSeq(new String[]{"原燃料供应商组""综合供应商组""销售客户组""系统测试"}, notRelationGroupList);   
  81.     }   
  82.        
  83.     private void testSeq(String[] seqNem, List groupList) {   
  84.         for (int i = 0; i < seqNem.length; i++) {   
  85.             UserGroup vo = (UserGroup)groupList.get(i);   
  86.             assertEquals("名称" + i,seqNem[i], vo.getUserGroupName());   
  87.         }   
  88.     }   
  89.        
  90.     /**  
  91.      *  检查排序问题,大写字母的排在前面  
  92.      *  
  93.      */  
  94.     public void testQueryAllUsers() {   
  95.         List userList = logic.queryAllUsers("1006");   
  96.         User user = (User)userList.get(0);   
  97.         assertEquals("第一个不是大写""kaka", user.getLoginName());   
  98.     }   
  99.        
  100.     /**  
  101.      * 保存用户和用户组关联  
  102.      *  
  103.      */  
  104.     public void testSaveRelation() throws Exception {   
  105.         RelationGroupFormVO vo = new RelationGroupFormVO();   
  106.         vo.setUserID("PK116055807175866885");   
  107.         vo.setPk_corp("1006");   
  108.         vo.setRel_sel(new String[]{"PK116441420549454662""PK116458716029826288"});   
  109.         logic.saveRelation(vo);   
  110.         Map groupMap = logic.queryUserRelationAndNotGroupListMap(vo.getUserID());   
  111.         List relationList = (List)groupMap.get("RELATION");   
  112.         assertEquals("长度"2, relationList.size());   
  113.         if (relationList.size() <= 0) {   
  114.             return;   
  115.         }   
  116.         testSeq(new String[]{"综合供应商组""销售客户组"}, relationList);   
  117.     }   
  118.        
  119.     /* (non-Javadoc)  
  120.      *   */  
  121.     protected String getDBScriptPath() {   
  122.         return "/com/ufida/cvms/basemanagement/usermanager/map/user";   
  123.     }   
  124.        
  125.        
  126. }   

还有就是数据库文件了

sql 代码
  1. 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)   
  2. 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))   
  3. 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))   
  4. 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)   
  5. 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)   
  6. 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)   
  7. CREATE USER SA PASSWORD "" ADMIN   
  8. INSERT INTO BD_CUBASDOC VALUES('0001AA1000000003VQGO','0001','1101649','\u4e2d\u56fd\u77ff\u4ea7\u6709\u9650\u8d23\u4efb\u516c\u53f8','\u4e2d\u56fd\u77ff\u4ea7')   
  9. 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')   
  10. 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)   
  11. 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)   
  12. 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)   
  13. INSERT INTO CMS_USERGROUP VALUES('PK116169875984005137','3','2','1','1006','2006-10-24 21:55:12',0)   
  14. INSERT INTO CMS_USERGROUP VALUES('PK116433523110959947','1','1','1','1006','2006-11-24 10:30:07',0)   
  15. INSERT INTO CMS_USERGROUP VALUES('PK116441420549454662','0003','\u7efc\u5408\u4f9b\u5e94\u5546\u7ec4',NULL,'1006','2006-11-25 09:23:02',0)   
  16. INSERT INTO CMS_USERGROUP VALUES('PK116458716029826288','0011','\u9500\u552e\u5ba2\u6237\u7ec4',NULL,'1006','2006-11-27 09:25:45',0)   
  17. 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)   
  18. 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)   
  19. INSERT INTO CMS_USERGROUP VALUES('PK116354868037463911','test','test',NULL,'1006','2006-11-15 08:56:56',0)   
  20. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779950435','PK116433523110959947','PK116349434520962752','2006-11-27 15:25:44',0)   
  21. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779925183','PK116433523110959947','PK116349504077321401','2006-11-27 15:25:44',0)   
  22. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779908017','PK116433523110959947','PK116063874195957630','2006-11-27 15:25:44',0)   
  23. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779949238','PK116433523110959947','PK116229489004712130','2006-11-27 15:25:44',0)   
  24. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779916855','PK116433523110959947','PK116363778699299950','2006-11-27 15:25:44',0)   
  25. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116441283966919281','PK116354840433039098','PK116424362932510299','2006-11-25 09:00:16',0)   
  26. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116458717250926033','PK116458716029826288','PK116458688918253943','2006-11-27 09:25:57',0)   
  27. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354777072528935','PK116354770995805209','PK116349423878288523','2006-11-15 08:41:46',0)   
  28. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354777072528436','PK116354770995805209','PK116349434520962752','2006-11-15 08:41:46',0)   
  29. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354851343863279','PK116169875984005137','PK116349504077321401','2006-11-15 08:54:09',0)   
  30. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759089179','PK116354868037463911','PK116349434520962752','2006-11-23 10:15:34',0)   
  31. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759059525','PK116354868037463911','PK116424376929524473','2006-11-23 10:15:34',0)   
  32. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759049917','PK116354868037463911','PK116219721663024806','2006-11-23 10:15:34',0)   
  33. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759090900','PK116354868037463911','PK116349504077321401','2006-11-23 10:15:34',0)   
  34. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759076081','PK116354868037463911','PK116063874195957630','2006-11-23 10:15:34',0)   
  35. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759075198','PK116354868037463911','PK116229489004712130','2006-11-23 10:15:34',0)   
  36. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759033542','PK116354868037463911','PK116349423878288523','2006-11-23 10:15:34',0)   
  37. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116424456759085854','PK116354868037463911','PK116055807175866885','2006-11-23 10:15:34',0)   
  38. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116354851343860249','PK116169875984005137','PK116055807175866885','2006-11-15 08:54:09',0)   
  39. INSERT INTO CMS_USER_GROUP_RELATION VALUES('PK116461221779999473','PK116433523110959947','PK116055807175866885','2006-11-27 15:25:44',0)   

HSQLDB就是从这个*.script文件里面读入表和数据,然后就可以调用各种方法测试里面的数据。需要注意的是,测试类找不到WEB-INF下面的Sql_Map_Config文件,所以拷贝了一份,放到了测试源文件的包根目录下。

大体上就是这些了,写下来,记录一下,也为这段时间的辛勤劳作一个小小的表彰:)

分享到:
评论
4 楼 spiritfrog 2007-05-25  
<div class='quote_div'>
<p>那么这个shutdown到底是执行的什么呢?如果这里不是真实的数据库环境,倒是不如用hsqldb的内存模式来测试吧,这样也就不需要去还原数据库来保证测试不修改数据库数据了。</p>
<p> </p>
<p> </p>
<p> </p>
</div>
3 楼 hiwzg 2007-05-21  
不太想在TestCase中写很多类似的准备参数的代码。<br/>
<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 &lt; 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() &lt;= </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/>
2 楼 sinokaka 2006-11-29  
修改了一下文章,把数据库脚本也贴上了
1 楼 抛出异常的爱 2006-11-29  
引用
还有就是数据库文件了

这个东西最不可理解了...
给仔细说说是怎么放到内存数据库中的....?

相关推荐

    spring+hibernate+hsqldb 测试

    总之,"spring+hibernate+hsqldb 测试"项目展示了如何在Java应用中整合Spring、Hibernate和HSQLDB进行数据持久化操作的测试实践,这对于理解和学习Java企业级开发以及相关框架的集成具有很高的价值。

    spring几种Dao支持配置

    在Spring中,可以通过`SqlMapClientTemplate`类对iBATIS(现为MyBatis)进行操作。它提供了一组与`HibernateTemplate`类似的模板方法,用于执行iBATIS的SQL映射文件中的SQL语句。 4. **JPA(Java Persistence API...

    lib1 flex+spring+struts2+ibatis需要的jar 1 完整的jar 需要下载我提供的资源lib2

    标题中的"lib1 flex+spring+struts2+ibatis需要的jar 1 完整的jar 需要下载我提供的资源lib2"表明这是一个关于Java Web开发的库集合,其中包含了四个关键的技术框架:Flex、Spring、Struts2和iBatis。这些框架在构建...

    jpetstore (spring+strust+ibatis)

    jPetStore是一个经典的开源项目,它展示了如何使用Spring、Struts和Ibatis等技术构建一个完整的MVC(Model-View-Controller)架构的Web应用程序。这个项目是Java开发者学习和实践这些技术的绝佳案例。最新版本的...

    struts+spring+ibatis.doc

    通过整合Struts、Spring与ibatis,JpetStore 4.0不仅展现了ibatis在数据持久化方面的高效与灵活性,也展示了Struts与Spring在构建高效、可维护的J2EE应用程序中的协同优势。这种模式下的开发,不仅减少了代码量,...

    Spring+EasyJWeb+iBatis版j2ee在线购物jpetstore系统源码

    Spring+EasyJWeb+iBatis版j2ee在线购物jpetstore系统,业务层及持久层使用springframework上的jpetsotre源码,表示层使用EasyJWeb,该系统是一个简单的J2EE网上商店系统,包括商品列表、购物车、用户管理、在线订单...

    hsqldb使用(转载)

    HSQldb是一个轻量级的关系型...HSQldb的灵活性和易用性使其成为开发人员的首选数据库之一,特别是在快速迭代和测试环境中。其强大的特性,如内存数据库、自动创建数据库以及内置的管理工具,都极大地简化了数据库管理。

    hsqldb包和使用说明

    这个jar文件包含了运行HSQldb所需的所有类和资源,开发者可以直接将其引入项目中使用。描述中的"一份中文使用说明"是为了帮助中国用户更好地理解和使用HSQldb,提供了详细的中文操作指南,这对于初学者来说是非常有...

    <转>HSQLDB 安装与使用

    HSQLDB常被用作开发和测试环境中的数据库,因为它易于设置和使用。例如,Spring Boot默认使用HSQLDB作为内存数据库。此外,很多Java IDE,如IntelliJ IDEA,都内置了对HSQLDB的支持,方便开发者进行数据库操作。 ##...

    junit针对spring mvc三层测试

    我们可以使用内存数据库(如H2)或者嵌入式数据库(如HSQLDB)来避免在测试中实际访问生产数据库。同时,使用JPA或Hibernate等持久层框架的测试工具,如Hibernate Test或者Spring Data JPA的@...

    jbpm4 测试例子(项目中含hsqldb数据库)

    **jbpm4测试例子(项目中含hsqldb数据库)** jbpm4 是一个开源的工作流管理系统,它提供了业务流程管理(BPM)和工作流服务。jbpm4的测试例子是一个很好的学习资源,帮助开发者了解如何在实际项目中集成和使用jbpm4。...

    ibatis 配置文件详解

    ibatis可以使用简单的XML或注解进行配置和原始映射,将接口和Java的POJOs(Plain Old Java Objects,普通的Java对象)映射成数据库中的记录。 #### 二、ibatis配置文件解析 ibatis的核心配置文件是`SqlMapConfig.xml...

    HSQLDB

    - **开发和测试**:HSQLDB常用于开发环境中的单元测试和集成测试,因为它快速启动、无需额外配置,且能模拟多种数据库行为。 - **嵌入式系统**:在资源有限的嵌入式设备上,HSQLDB作为内置数据库,能够提供高效的...

    lib1 flex+struts2+spring+ibatis jar 完整的jar 需要下载本人资源lib2

    标题和描述中提到的"lib1 flex+struts2+spring+ibatis jar 完整的jar 需要下载本人资源lib2"是一个关于Java Web开发中的关键库集合,这些库是构建基于Flex前端、Struts2作为MVC框架、Spring作为依赖注入和整体应用...

    HSQLDB中文帮助文档

    - **安装步骤**:无需复杂安装,只需将HSQLDB包解压至所需的目录即可使用。 #### 三、HSQLDB的运行与使用 - **运行工具**:包括HsqldbServer、HsqldbWebServer等。 - **HsqldbServer**:提供数据库服务的服务器端...

Global site tag (gtag.js) - Google Analytics