<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    [原創(chuàng)]基于驗(yàn)證框架的action的測試

    當(dāng)引用了驗(yàn)證框架的時(shí)候,測試 action 的時(shí)候,程序會(huì)自動(dòng)去找驗(yàn)證框架進(jìn)行驗(yàn)證,那么如何進(jìn)行這種情況下的 action 測試呢?經(jīng)過一天的研究,發(fā)現(xiàn)必須先將驗(yàn)證所需要的 xml 文件夾在進(jìn)去,然后才能夠順利的進(jìn)行!具體的實(shí)施如下:

    ??? protected void setUp() throws Exception {

    ??????? super .setUp();

    ??????? // set WEB-INF directory

    ??????? setContextDirectory( new File( "WebContent" ));

    ??????? // set struts- test -config.xml

    ??????? setConfigFile( "/WEB-INF/test/struts-test-config.xml" );

    ???????

    ??????? // set request's attribute for test

    ??????? // 創(chuàng)建一個(gè) MessageResourcesFactory 類,目的是得到下面的 MessageResources, 作為其中的一個(gè)參數(shù)

    MessageResourcesFactory messageResourcesFactory = new PropertyMessageResourcesFactory();

    // 獲得 MessageResources

    MessageResources messageResources = new PropertyMessageResources(messageResourcesFactory, "org.apache.struts.action.ActionResources" );? ?
    ?
    getActionServlet().getServletContext().setAttribute( "org.apache.commons.validator.VALIDATOR_RESOURCES" ,getResources());

    ???????? ???????????????????????? ?
    getActionServlet().getServletContext().setAttribute( "org.apache.struts.action.MESSAGE" ,messageResources);

    ??? }

    ?

    以下的方法為了得到一個(gè) MessageResources ,是從 org.apache.struts.validator. ValidatorPlugIn 中的 initResources ()方法得到的!

    /**

    ? * get the validator resources.

    ? *

    ? * @throws IOException ????? if an input/output error is encountered

    ? * @throws ServletException if we cannot initialize these resources

    ? */

    protected ValidatorResources getResources() throws IOException, ServletException {

    String pathnames = "/WEB-INF/validator-rules.xml,/WEB-INF/test/struts-test-config.xml" ;

    ??????? StringTokenizer st = new StringTokenizer(pathnames, "," );

    ?

    ??????? List streamList = new ArrayList();

    ??????? try {

    ??????????? while (st.hasMoreTokens()) {

    ??????????????? String validatorRules = st.nextToken().trim();

    ??????????????? if (log.isInfoEnabled()) {

    ??????????????????? log.info( "Loading validation rules file from '" + validatorRules + "'" );

    ??????????????? }

    ?

    ??????????????? InputStream input =getActionServlet().getServletContext().getResourceAsStream(validatorRules);

    ???????????????

    ??????????????? // If the config isn't in the servlet context, try the class loader

    ??????????????? // which allows the config files to be stored in a jar

    ??????????????? if (input == null ) {

    ??????????????????? input = getClass().getResourceAsStream(validatorRules);

    ??????????????? }

    ?

    ??????????????? if (input != null ) {

    ??????????????????? BufferedInputStream bis = new BufferedInputStream(input);

    ??????????????????? streamList.add(bis);

    ??????????????? } else {

    ??????????????????? throw new ServletException( "Skipping validation rules file from '"

    ??????????????????????????? ? + validatorRules + "'.? No stream could be opened." );

    ??????????????? }

    ??????????? }

    ??????????? int streamSize = streamList.size();

    ??????????? InputStream[] streamArray = new InputStream[streamSize];

    ??????????? for ( int streamIndex = 0;streamIndex < streamSize;streamIndex++) {

    ??????????????? InputStream is = (InputStream) streamList.get(streamIndex);

    ??????????????? streamArray[streamIndex] = is;

    ??????????? }

    ?

    ??????????? return new ValidatorResources(streamArray);

    ??????? } catch (SAXException sex) {

    ??????????? log.error( "Skipping all validation" ,sex);

    ??????????? throw new ServletException(sex);

    ??????? } finally {

    ??????????? Iterator streamIterator = streamList.iterator();

    ??????????? while (streamIterator.hasNext()) {

    ??????????????? InputStream is = (InputStream) streamIterator.next();

    ??????????????? is.close();

    ??????????? }

    ??????? }

    ??? }

    ?

    通過這樣的配置以后,就可以正常的對于 action 進(jìn)行測試了!

    posted on 2006-03-17 13:31 扭轉(zhuǎn)乾坤 閱讀(257) 評論(0)  編輯  收藏 所屬分類: 測試相關(guān)

    <2006年3月>
    2627281234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(2)

    隨筆分類(31)

    隨筆檔案(30)

    文章分類(32)

    文章檔案(33)

    相冊

    PHP小站-首頁

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产精品无码亚洲一区二区三区| 国产亚洲精aa成人网站| 亚洲AV无码乱码国产麻豆| 一本到卡二卡三卡免费高| 四虎免费久久影院| 亚洲Av无码国产一区二区| 青青草国产免费久久久91| 亚洲乱人伦中文字幕无码| 国产男女猛烈无遮挡免费视频网站| 亚洲依依成人亚洲社区| 白白国产永久免费视频| 在线观看亚洲专区| 精品国产人成亚洲区| 精品亚洲永久免费精品| 伊人久久综在合线亚洲2019| xxxxwww免费| 亚洲精品无码久久久久久| 国产极品粉嫩泬免费观看| 又大又硬又粗又黄的视频免费看| 97在线线免费观看视频在线观看| 亚洲伊人色一综合网| 在线精品免费视频无码的| 人人狠狠综合久久亚洲| 亚洲午夜福利精品无码| 永久免费A∨片在线观看| 亚洲自偷自拍另类图片二区| 无码国产精品久久一区免费| 色天使色婷婷在线影院亚洲| 久久亚洲国产精品五月天婷| 一级毛片在线免费看| 在线aⅴ亚洲中文字幕| 亚洲AV日韩精品一区二区三区| 99在线热播精品免费99热| 亚洲第一页在线视频| 又黄又大又爽免费视频| 天黑黑影院在线观看视频高清免费 | 亚洲伦理一二三四| 亚洲视频在线精品| 在线视频精品免费| jizz18免费视频| 亚洲乱码卡一卡二卡三|