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

📄 testelerrorstag.java

📁 jakarta-struts-1.2.4-src
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//      */
//     public void testProperty()
//                       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, 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);

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

//     public void endProperty(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();
//         }
//     }

//     /**
//      * Just like "testPropertySpecified", but the "property" value is an EL
//      * expression, evaluating to the same value as in the other test.
//      */
//     public void testPropertySpecifiedEL()
//                                  throws ServletException, JspException {
//         String varName = "targetVar";
//         pageContext.setAttribute(varName, PROPERTY_KEY);
//         elErrorsTag.setPropertyExpr("${" + varName + "}");
//         testPropertySpecified();
//     }

//     public void endPropertySpecifiedEL(com.meterware.httpunit.WebResponse testResponse) {
//         endPropertySpecified(testResponse);
//     }

//     /**
//      * Tests one error in errors list, set to a property, and the "property"
//      * attribute set to that property key.
//      */
//     public void testPropertySpecified()
//                                throws ServletException, JspException {
//         elErrorsTag.setPropertyExpr(PROPERTY_KEY);

//         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, 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);

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

//     public void endPropertySpecified(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 in the errors list, set to a property, and the
//      * "property" attribute set to a different property key.
//      */
//     public void testPropertySpecifiedWrong()
//                                     throws ServletException, JspException {
//         elErrorsTag.setPropertyExpr(PROPERTY_KEY + "x");

//         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, error);
//         pageContext.setAttribute(elErrorsTag.getName(), errors, 
//                                  PageContext.REQUEST_SCOPE);

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

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

//     public void endPropertySpecifiedWrong(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();
//         }
//     }

//     public void tearDown() {
//         elErrorsTag = null;
//     }

//     /**
//      * Tests a single error in errors list, with the "header" and "footer"
//      * resource set to non-empty strings.
//      */
//     public void testHeaderFooter()
//                           throws ServletException, JspException {
//         HashMapMessageResources messageResources = new HashMapMessageResources(
//                                                            null, null, true);
//         messageResources.addMessage("error.misc", XXX_VALUE);
//         messageResources.addMessage("errors.header", HEADER_VALUE);
//         messageResources.addMessage("errors.footer", FOOTER_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 = HEADER_VALUE + " " + XXX_VALUE + 
//                                            " " + FOOTER_VALUE;
//         response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);

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

//     public void endHeaderFooter(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();
//         }
//     }
}

⌨️ 快捷键说明

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