Web工程中spring+ibatis的单元测试
作者:网络转载 发布时间:[ 2015/3/26 14:31:46 ] 推荐标签:单元测试 软件测试 应用程序
三 第二步中涉及DataSource,其配置信息包含在 jdbc-template.properties 文件中 文件路径为
工程目录confjdbc-template.properties 代码如下
# Properties file with JDBC-related settings.
# Applied by PropertyPlaceholderConfigurer from "applicationContext.xml".
# Targeted at system administrators, to avoid touching the context XML files.
#jdbc.driverClassName=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://localhost:3306/mps
#jdbc.username=root
#jdbc.password=skywin
jdbc.initialSize=1
jdbc.maxActive=10
jdbc.driverClassName=oracle.jdbc.OracleDriver
#jdbc.url=jdbc:oracle:thin:@10.244.112.130:41521:gmcctes
#jdbc.url=jdbc:oracle:thin:@10.244.112.130:1521:gmccmpp
jdbc.url=jdbc:oracle:thin:@192.168.100.235:1521:mpptest
jdbc.username=gmcc
jdbc.password=skywin
#imageDatabase.lobHandler=oracleLobHandler
第二步中的 <property name="configLocation" value="sqlmap-config-template.xml"/> 为ibatis的中枢文件 文件路径是 工程目录confsqlmap-config-template.xml 代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<!-- Leonel Wong 2008-11-6 17:24:04 -->
<sqlMapConfig>
<sqlMap resource="ibatis-conf/MpsAppendixInf.xml" />
<sqlMap resource="ibatis-conf/MpsDispatchLog.xml" />
<sqlMap resource="ibatis-conf/MpsFunctionType.xml" />
<sqlMap resource="ibatis-conf/MpsFundType.xml" />
<sqlMap resource="ibatis-conf/MpsInGatewayInf.xml" />
<sqlMap resource="ibatis-conf/MpsModuleInf.xml" />
<sqlMap resource="ibatis-conf/MpsOperationType.xml" />
<sqlMap resource="ibatis-conf/MpsOrderClaimant.xml" />
<sqlMap resource="ibatis-conf/MpsPayType.xml" />
<sqlMap resource="ibatis-conf/MpsProcessApproveLog.xml" />
<sqlMap resource="ibatis-conf/MpsProcessLog.xml" />
<sqlMap resource="ibatis-conf/MpsProcessRemark.xml" />
<sqlMap resource="ibatis-conf/MpsReceiveOrderLog.xml" />
<sqlMap resource="ibatis-conf/MpsServiceInfo.xml" />
<sqlMap resource="ibatis-conf/MpsUploadFile.xml" />
<sqlMap resource="ibatis-conf/MpsUrgentLevel.xml" />
<sqlMap resource="ibatis-conf/MpsVerifyLog.xml" />
<sqlMap resource="ibatis-conf/MpsWorkOrder.xml" />
<sqlMap resource="ibatis-conf/MpsWorkOrderCancelLog.xml" />
<sqlMap resource="ibatis-conf/MpsWorkOrderCloseLog.xml" />
<sqlMap resource="ibatis-conf/MpsWorkOrderType.xml" />
<sqlMap resource="ibatis-conf/MpsOperatorInf.xml" />
<sqlMap resource="ibatis-conf/MpsOrderServiceInfo.xml" />
<sqlMap resource="ibatis-conf/MpsTree.xml" />
<sqlMap resource="ibatis-conf/MpsOperatorTree.xml" />
<sqlMap resource="ibatis-conf/MpsTest.xml" />
<sqlMap resource="ibatis-conf/MpsSpInfo.xml" />
</sqlMapConfig>
四 ormpping文件,这里以MpsTest.xml文件为例子,该文件路径是
工程目录/confibatis-confMpsTest.xml 代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<!-- qjk 2009-02-02 -->
<sqlMap namespace="MpsTest">
<resultMap id="result" class="com.skywin.workorder.model.MpsTest">
<result property="testId" column="testid" columnIndex="1" />
<result property="mpsWorkOrder.orderId" column="orderid" columnIndex="2" />
<result property="wfid" column="wfid" columnIndex="3" />
<result property="testResult" column="testResult" columnIndex="4" />
<result property="testDate" column="testdate" columnIndex="5" />
<result property="testPerson" column="testPerson" columnIndex="6" />
<result property="testDesc" column="testDesc" columnIndex="7" />
</resultMap>
<insert id="saveMpsTest">
insert into wo_test(testid,orderid,wfid,testResult,testdate,testPerson,testDesc)
values(#testId#,#mpsWorkOrder.orderId#,#wfid#,#testResult#,#testDate#,#testPerson#,#testDesc#)
</insert>
<delete id="deleteMpsTestById">
delete from wo_test where testid=#value#
</delete>
<select id="findAllMpsTest" resultMap="result">
select * from wo_test
</select>
<select id="findAllMpsTestCount" resultClass="Long">
select count(*) from wo_test
</select>
<select id="findMpsTestNextSeq" resultClass="Long">
select wo_test_seq.nextval from dual
</select>
</sqlMap>
五 dao实现类代码:
package com.skywin.workorder.dao.Impl;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.skywin.workorder.dao.MpsTestDao;
import com.skywin.workorder.model.MpsTest;
import com.skywin.workorder.util.ListResult;
public class MpsTestDaoImpl extends SqlMapClientDaoSupport implements MpsTestDao {
public int deleteMpsTestById(Long testId) {
return getSqlMapClientTemplate().delete("deleteMpsTestById", testId);
}
public List findAllMpsTest(int pagesize, int pageIndex) {
return getSqlMapClientTemplate().queryForList("findAllMpsTest", null, pageIndex*pagesize, pagesize);
}
public Long findAllMpsTestCount() {
return (Long) getSqlMapClientTemplate().queryForObject("findAllMpsTestCount", null);
}
public ListResult pageAllMpsTest(int pagesize, int pageIndex) {
ListResult listResult=new ListResult();
listResult.setResult(findAllMpsTest(pagesize,pageIndex));
listResult.setCount(findAllMpsTestCount());
return listResult;
}
public MpsTest saveMpsTest(MpsTest mpsTest) {
getSqlMapClientTemplate().insert("saveMpsTest",mpsTest);
return mpsTest;
}
public Long findMpsTestNextSeq() {
return (Long) getSqlMapClientTemplate().queryForObject("findMpsTestNextSeq", null);
}
}
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
iOS单元测试mocha、chai、sinon和istanbul实现百分之百的单元测试覆盖率关于单元测试的总结及思考编写更好的Java单元测试的7个技巧Android单元测试框架Robolectric3.0介绍(一)使用Kiwi单元测试总结单元测试如此重要,为什么你不知道Python单元测试??使用装饰器实现测试跳过和预期故障对Controller的单元测试写好单元测试的10个技巧单元测试的重要性Angular单元测试系列??Component、Directive、Pipe 以及ServiceAndroid单元测试的整理提升单元测试体验的利器--Mockito使用总结iOS UnitTest单元测试Vue的单元测试探索(二)
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11热门文章
常见的移动App Bug??崩溃的测试用例设计如何用Jmeter做压力测试QC使用说明APP压力测试入门教程移动app测试中的主要问题jenkins+testng+ant+webdriver持续集成测试使用JMeter进行HTTP负载测试Selenium 2.0 WebDriver 使用指南