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

📄 testelerrorstag.java

📁 jakarta-struts-1.2.4-src
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Header: /home/cvs/jakarta-struts/contrib/struts-el/src/test/org/apache/strutsel/taglib/html/TestELErrorsTag.java,v 1.6 2004/06/24 01:27:31 jmitchell Exp $
 * $Revision: 1.6 $
 * $Date: 2004/06/24 01:27:31 $
 *
 * Copyright 1999-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.strutsel.taglib.html;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.strutsel.taglib.utils.JspTagTestCase;


public class TestELErrorsTag
    extends JspTagTestCase {
    protected static final String FOOTER_VALUE            = "zzz";
    protected static final String HEADER_VALUE            = "aaa";
    protected static final String PREFIX_VALUE            = "[[[";
    protected static final String PROPERTY_KEY            = "property";
    protected static final String REQUIRED_TEXT_VALUE_KEY = 
            "RequiredTextValue";
    protected static final String SUFFIX_VALUE            = "]]]";
    protected static final String XXX_VALUE               = "xxx";
    protected static final String YYY_VALUE               = "yyy";
    protected ELErrorsTag         elErrorsTag             = null;
    private static Log            log                     = 
            LogFactory.getLog(TestELErrorsTag.class);

    public TestELErrorsTag(String theName) {
        super(theName);
    }

    public static void main(String[] args) {
        junit.awtui.TestRunner.main(
                new String[] { TestELErrorsTag.class.getName() });
    }

    public static Test suite() {
        return new TestSuite(TestELErrorsTag.class);
    }

    public void setUp() {
        elErrorsTag = new ELErrorsTag();
        elErrorsTag.setPageContext(pageContext);
    }

    public void testDummy()
    {
    }

//     /**
//      * Tests simple global error with all tag attributes set to default, and no
//      * header, footer, prefix or suffix.
//      */
//     public void testPlain()
//                    throws ServletException, JspException {
//         HashMapMessageResources messageResources = new HashMapMessageResources(
//                                                            null, null, true);
//         messageResources.addMessage("error.misc", XXX_VALUE);
//         String bundle   = elErrorsTag.getBundle();
//         if (bundle == null)
//             bundle   = Action.MESSAGES_KEY;
//         pageContext.setAttribute(bundle, messageResources, 
//                                  PageContext.APPLICATION_SCOPE);

//         ActionErrors errors = new ActionErrors();
//         ActionError  error = new ActionError("error.misc");
//         errors.add(ActionErrors.GLOBAL_ERROR, error);
//         pageContext.setAttribute(elErrorsTag.getName(), errors, 
//                                  PageContext.REQUEST_SCOPE);

//         HttpServletResponse response     = (HttpServletResponse)pageContext.getResponse();
//         String              requiredText = XXX_VALUE;
//         response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);

//         System.out.println("pageContext[" + pageContext + "]");
//         System.out.println("name[" + elErrorsTag.getName() + "]");
//         System.out.println("request[" + pageContext.getRequest() + "]");
//         System.out.println("session[" + pageContext.getSession() + "]");
//         int startTagReturn  = elErrorsTag.doStartTag();
//         int afterBodyReturn = elErrorsTag.doAfterBody();
//         int endTagReturn    = elErrorsTag.doEndTag();
//     }

//     public void endPlain(com.meterware.httpunit.WebResponse testResponse) {
//         try {
//             TestHelper.printResponse(testResponse);

//             org.w3c.dom.Document document = testResponse.getDOM();
//             DOMHelper.printNode(document.getDocumentElement());

//             String nodeText = DOMHelper.getNodeText(document, "/html/body");
//             log.debug("nodeText[" + nodeText + "]");

//             String requiredTextValue = (String)testResponse.getHeaderField(
//                                                REQUIRED_TEXT_VALUE_KEY);

//             if (!nodeText.equals(requiredTextValue)) {
//                 fail("The <errors> tag instance should have resulted " + 
//                      "in the text " + "\"" + requiredTextValue + 
//                      "\", but instead had the value \"" + nodeText + "\".");
//             }
//         } catch (Exception ex) {
//             ex.printStackTrace();
//             fail();
//         }
//     }

//     /**
//      * Tests multiple errors put in errors list, with two different property
//      * names, but referring to the same error, but still using the default
//      * value of "property", which will cause both errors to be retrieved.
//      */
//     public void testMultiProperties()
//                              throws ServletException, JspException {
//         HashMapMessageResources messageResources = new HashMapMessageResources(
//                                                            null, null, true);
//         messageResources.addMessage("error.misc", XXX_VALUE);
//         String bundle   = elErrorsTag.getBundle();
//         if (bundle == null)
//             bundle   = Action.MESSAGES_KEY;
//         pageContext.setAttribute(bundle, messageResources, 
//                                  PageContext.APPLICATION_SCOPE);

//         ActionErrors errors = new ActionErrors();
//         ActionError  error = new ActionError("error.misc");
//         errors.add(PROPERTY_KEY + "1", error);
//         errors.add(PROPERTY_KEY + "2", error);
//         pageContext.setAttribute(elErrorsTag.getName(), errors, 
//                                  PageContext.REQUEST_SCOPE);

//         HttpServletResponse response     = (HttpServletResponse)pageContext.getResponse();
//         String              requiredText = XXX_VALUE + " " + XXX_VALUE;
//         response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);

//         int startTagReturn  = elErrorsTag.doStartTag();
//         int afterBodyReturn = elErrorsTag.doAfterBody();
//         int endTagReturn    = elErrorsTag.doEndTag();
//     }

//     public void endMultiProperties(com.meterware.httpunit.WebResponse testResponse) {
//         try {
//             TestHelper.printResponse(testResponse);

//             org.w3c.dom.Document document = testResponse.getDOM();
//             DOMHelper.printNode(document.getDocumentElement());

//             String nodeText = DOMHelper.getNodeText(document, "/html/body");
//             log.debug("nodeText[" + nodeText + "]");

//             String requiredTextValue = (String)testResponse.getHeaderField(
//                                                REQUIRED_TEXT_VALUE_KEY);

//             if (!nodeText.equals(requiredTextValue)) {
//                 fail("The <errors> tag instance should have resulted " + 
//                      "in the text " + "\"" + requiredTextValue + 
//                      "\", but instead had the value \"" + nodeText + "\".");
//             }
//         } catch (Exception ex) {
//             ex.printStackTrace();
//             fail();
//         }
//     }

//     /**
//      * Tests putting in two errors in errors list, with two different property
//      * names, and referring to two different error keys, and the "property"
//      * attribute set to only one of them.
//      */
//     public void testOnlyWantOneProperty()
//                                  throws ServletException, JspException {
//         elErrorsTag.setPropertyExpr(PROPERTY_KEY + "2");

//         HashMapMessageResources messageResources = new HashMapMessageResources(
//                                                            null, null, true);
//         messageResources.addMessage("error1.misc", XXX_VALUE);
//         messageResources.addMessage("error2.misc", YYY_VALUE);
//         String bundle   = elErrorsTag.getBundle();
//         if (bundle == null)
//             bundle   = Action.MESSAGES_KEY;
//         pageContext.setAttribute(bundle, messageResources, 
//                                  PageContext.APPLICATION_SCOPE);

//         ActionErrors errors = new ActionErrors();
//         errors.add(PROPERTY_KEY + "1", new ActionError("error1.misc"));
//         errors.add(PROPERTY_KEY + "2", new ActionError("error2.misc"));
//         pageContext.setAttribute(elErrorsTag.getName(), errors, 
//                                  PageContext.REQUEST_SCOPE);

//         HttpServletResponse response     = (HttpServletResponse)pageContext.getResponse();
//         String              requiredText = YYY_VALUE;
//         response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);

//         int startTagReturn  = elErrorsTag.doStartTag();
//         int afterBodyReturn = elErrorsTag.doAfterBody();
//         int endTagReturn    = elErrorsTag.doEndTag();
//     }

//     public void endOnlyWantOneProperty(com.meterware.httpunit.WebResponse testResponse) {
//         try {
//             TestHelper.printResponse(testResponse);

//             org.w3c.dom.Document document = testResponse.getDOM();
//             DOMHelper.printNode(document.getDocumentElement());

//             String nodeText = DOMHelper.getNodeText(document, "/html/body");
//             log.debug("nodeText[" + nodeText + "]");

//             String requiredTextValue = (String)testResponse.getHeaderField(
//                                                REQUIRED_TEXT_VALUE_KEY);

//             if (!nodeText.equals(requiredTextValue)) {
//                 fail("The <errors> tag instance should have resulted " + 
//                      "in the text " + "\"" + requiredTextValue + 
//                      "\", but instead had the value \"" + nodeText + "\".");
//             }
//         } catch (Exception ex) {
//             ex.printStackTrace();
//             fail();
//         }
//     }

//     /**
//      * Tests one error on a specific property, with "property" attribute set to
//      * default.

⌨️ 快捷键说明

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