craigmcc 2004/08/28 00:44:54
Modified: contrib/struts-faces/src/java/org/apache/struts/faces/renderer
FormRenderer.java
contrib/struts-faces/web/systest/WEB-INF struts-config.xml
Added: contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient
ContextTestCase.java
contrib/struts-faces/src/systest/org/apache/struts/faces/systest
ContextAction.java
contrib/struts-faces/web/systest context.jsp context1.jsp
Log:
Add system integration tests to validate the values returned by property
getters on FacesContext, ExternalContext, and HttpServletRequest.
The current test is based on the use of a wrapper around the servlet request,
that was introduced because of bug report #29809. It is not yet clear what
the final resolution of this issue is, but it may involve further refinements
in the functionality of the Struts-Faces integration library before a 1.0
release.
Revision Changes Path
1.8 +4 -2
jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/FormRenderer.java
Index: FormRenderer.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/FormRenderer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FormRenderer.java 8 Mar 2004 02:49:54 -0000 1.7
+++ FormRenderer.java 28 Aug 2004 07:44:54 -0000 1.8
@@ -112,7 +112,9 @@
ModuleConfig moduleConfig = form.lookupModuleConfig(context);
ActionConfig actionConfig = moduleConfig.findActionConfig(action);
String beanName = actionConfig.getAttribute();
- form.getAttributes().put("beanName", beanName);
+ if (beanName != null) {
+ form.getAttributes().put("beanName", beanName);
+ }
// Look up attribute values we need
String clientId = component.getClientId(context);
1.1
jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/ContextTestCase.java
Index: ContextTestCase.java
===================================================================
/*
* Copyright 2002,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.struts.faces.sysclient;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlBase;
import com.gargoylesoftware.htmlunit.html.HtmlBody;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlHead;
import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
import com.gargoylesoftware.htmlunit.html.HtmlLink;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlResetInput;
import com.gargoylesoftware.htmlunit.html.HtmlSpan;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* <p>Test case for verifying <code>FacesContext</code> information against
* what is visible in the Struts <code>Action</code> method that is invoked.</p>
*
* @version $Revision: 1.1 $ $Date: 2004/08/28 07:44:54 $
*/
public class ContextTestCase extends AbstractTestCase {
// ------------------------------------------------------------ Constructors
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Name of the new test case
*/
public ContextTestCase(String name) {
super(name);
}
// ------------------------------------------------------ Instance Variables
// ------------------------------------------------------ Test Setup Methods
/**
* <p>Set up the instance variables required for this test case.</p>
*/
public void setUp() throws Exception {
super.setUp();
page("/context.faces");
}
/**
* <p>Return the set of tests included in this test suite.</p>
*/
public static Test suite() {
return (new TestSuite(ContextTestCase.class));
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
public void tearDown() {
super.tearDown();
}
// ------------------------------------------------- Individual Test Methods
/**
* <p>Verify the content of a pristine page returned when executing this
* view for the first time.</p>
*/
public void testPristine() throws Exception {
HtmlSpan span = null;
assertEquals("context", title());
// Validate FacesContext Values
span = (HtmlSpan) element("form:renderKitIdFC");
assertEquals("HTML_BASIC", span.asText());
span = (HtmlSpan) element("form:viewIdFC");
assertEquals("/context.jsp", span.asText());
// Validate ExternalContext Values
span = (HtmlSpan) element("form:authTypeEC");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:remoteUserEC");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:requestContextPathEC");
assertEquals("/struts-faces-systest", span.asText()); // FIXME - Ant
property?
span = (HtmlSpan) element("form:requestLocaleEC");
String formRequestLocaleEC = span.asText(); // FIXME - validate this
span = (HtmlSpan) element("form:requestPathInfoEC");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:requestServletPathEC");
assertEquals("/context.jsp", span.asText());
// Validate HttpServletRequest Values
span = (HtmlSpan) element("form:authTypeRQ");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:contextPathRQ");
assertEquals("/struts-faces-systest", span.asText()); // FIXME - Ant
property?
span = (HtmlSpan) element("form:localeRQ");
assertEquals(formRequestLocaleEC, span.asText());
span = (HtmlSpan) element("form:pathInfoRQ");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:remoteUserRQ");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:servletPathRQ");
assertEquals("/context.jsp", span.asText());
// Validate ServletContext Values
span = (HtmlSpan) element("form:majorVersionSC");
assertEquals("2", span.asText());
span = (HtmlSpan) element("form:minorVersionSC");
assertTrue("3".equals(span.asText()) || "4".equals(span.asText()));
}
/**
* <p>Submit the initial form and validate the resulting values.</p>
*/
public void testSubmit() throws Exception {
HtmlSpan span = null;
HtmlSpan spanCA = null;
HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
submit(submit);
assertEquals("context1", title());
// Validate FacesContext Values
span = (HtmlSpan) element("form:renderKitIdFC");
assertEquals("HTML_BASIC", span.asText());
span = (HtmlSpan) element("form:viewIdFC");
assertEquals("/context1.jsp", span.asText());
// Validate ExternalContext Values
span = (HtmlSpan) element("form:authTypeEC");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:remoteUserEC");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:requestContextPathEC");
assertEquals("/struts-faces-systest", span.asText()); // FIXME - Ant
property?
span = (HtmlSpan) element("form:requestLocaleEC");
String formRequestLocaleEC = span.asText(); // FIXME - validate this
span = (HtmlSpan) element("form:requestPathInfoEC");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:requestServletPathEC");
assertEquals("/context1.jsp", span.asText());
// Validate HttpServletRequest Values
span = (HtmlSpan) element("form:authTypeRQ");
assertEquals("", span.asText());
span = (HtmlSpan) element("form:contextPathRQ");
assertEquals("/struts-faces-systest", span.asText()); // FIXME - Ant
property?
spanCA = (HtmlSpan) element("form:contextPathCA");
assertEquals(span.asText(), spanCA.asText());
span = (HtmlSpan) element("form:localeRQ");
assertEquals(formRequestLocaleEC, span.asText());
spanCA = (HtmlSpan) element("form:localeCA");
assertEquals(span.asText(), spanCA.asText());
span = (HtmlSpan) element("form:pathInfoRQ");
assertEquals("", span.asText());
spanCA = (HtmlSpan) element("form:pathInfoCA");
assertEquals(span.asText(), spanCA.asText());
span = (HtmlSpan) element("form:remoteUserRQ");
assertEquals("", span.asText());
spanCA = (HtmlSpan) element("form:remoteUserCA");
assertEquals(span.asText(), spanCA.asText());
/* FIXME - define the correct test here
span = (HtmlSpan) element("form:servletPathRQ");
assertEquals("/context1.jsp", span.asText());
spanCA = (HtmlSpan) element("form:servletPathCA");
assertEquals(span.asText(), spanCA.asText());
*/
// Validate ServletContext Values
span = (HtmlSpan) element("form:majorVersionSC");
assertEquals("2", span.asText());
span = (HtmlSpan) element("form:minorVersionSC");
assertTrue("3".equals(span.asText()) || "4".equals(span.asText()));
}
}
1.1
jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/ContextAction.java
Index: ContextAction.java
===================================================================
/*
* Copyright 2002,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.struts.faces.systest;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
/**
* <p>Action to render properties from ExternalContext and the corresponding
* request and application context objects.</p>
*/
public class ContextAction extends Action {
private static final Log log = LogFactory.getLog(ContextAction.class);
private String authType = null;
private String contextPath = null;
private Locale locale = null;
private String pathInfo = null;
private String remoteUser = null;
private String servletPath = null;
public String getAuthType() { return (this.authType); }
public String getContextPath() { return (this.contextPath); }
public Locale getLocale() { return (this.locale); }
public String getPathInfo() { return (this.pathInfo); }
public String getRemoteUser() { return (this.remoteUser); }
public String getServletPath() { return (this.servletPath); }
/**
* <p>Process an attempted logon.</p>
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
this.authType = request.getAuthType();
this.contextPath = request.getContextPath();
this.locale = request.getLocale();
this.pathInfo = request.getPathInfo();
this.remoteUser = request.getRemoteUser();
this.servletPath = request.getServletPath();
request.setAttribute("contextAction", this);
return (mapping.findForward("context1"));
}
}
1.1 jakarta-struts/contrib/struts-faces/web/systest/context.jsp
Index: context.jsp
===================================================================
<!--
Copyright 2002,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.
-->
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="s" uri="http://jakarta.apache.org/struts/tags-faces" %>
<f:view>
<s:html locale="true" xhtml="true">
<head>
<title>context</title>
</head>
<body>
<s:form id="form"
action="/context">
<h:panelGrid columns="2">
<%-- ViewRoot Values --%>
<h:outputText value="FacesContext.getViewRoot()"/>
<h:outputText value="==============================================="/>
<h:outputText value="renderKitId"/>
<h:outputText id="renderKitIdFC"
value="#{facesContext.viewRoot.renderKitId}"/>
<h:outputText value="viewId"/>
<h:outputText id="viewIdFC"
value="#{facesContext.viewRoot.viewId}"/>
<%-- ExternalContext Values --%>
<h:outputText value="ExternalContext"/>
<h:outputText value="==============================================="/>
<h:outputText value="authType"/>
<h:outputText id="authTypeEC"
value="#{facesContext.externalContext.authType}"/>
<h:outputText value="remoteUser"/>
<h:outputText id="remoteUserEC"
value="#{facesContext.externalContext.remoteUser}"/>
<h:outputText value="requestContextPath"/>
<h:outputText id="requestContextPathEC"
value="#{facesContext.externalContext.requestContextPath}"/>
<h:outputText value="requestLocale"/>
<h:outputText id="requestLocaleEC"
value="#{facesContext.externalContext.requestLocale}"/>
<h:outputText value="requestPathInfo"/>
<h:outputText id="requestPathInfoEC"
value="#{facesContext.externalContext.requestPathInfo}"/>
<h:outputText value="requestServletPath"/>
<h:outputText id="requestServletPathEC"
value="#{facesContext.externalContext.requestServletPath}"/>
<%-- Request Values --%>
<h:outputText value="HttpServletRequest"/>
<h:outputText value="==============================================="/>
<h:outputText value="authType"/>
<h:outputText id="authTypeRQ"
value="#{facesContext.externalContext.request.authType}"/>
<h:outputText value="contextPath"/>
<h:outputText id="contextPathRQ"
value="#{facesContext.externalContext.request.contextPath}"/>
<h:outputText value="locale"/>
<h:outputText id="localeRQ"
value="#{facesContext.externalContext.request.locale}"/>
<h:outputText value="pathInfo"/>
<h:outputText id="pathInfoRQ"
value="#{facesContext.externalContext.request.pathInfo}"/>
<h:outputText value="remoteUser"/>
<h:outputText id="remoteUserRQ"
value="#{facesContext.externalContext.request.remoteUser}"/>
<h:outputText value="servletPath"/>
<h:outputText id="servletPathRQ"
value="#{facesContext.externalContext.request.servletPath}"/>
<%-- ServletContext Values --%>
<h:outputText value="ServletContext"/>
<h:outputText value="==============================================="/>
<h:outputText value="majorVersion"/>
<h:outputText id="majorVersionSC"
value="#{facesContext.externalContext.context.majorVersion}"/>
<h:outputText value="minorVersion"/>
<h:outputText id="minorVersionSC"
value="#{facesContext.externalContext.context.minorVersion}"/>
<h:outputText value="serverInfo"/>
<h:outputText id="serverInfoSC"
value="#{facesContext.externalContext.context.serverInfo}"/>
<h:outputText value="servletContextName"/>
<h:outputText id="servletContextNameSC"
value="#{facesContext.externalContext.context.servletContextName}"/>
<%-- Submit Buttons --%>
<h:commandButton id="submit"
type="SUBMIT"
value="Submit"/>
<h:commandButton id="reset"
type="RESET"
value="Reset"/>
</h:panelGrid>
</s:form>
</body>
</s:html>
</f:view>
1.1 jakarta-struts/contrib/struts-faces/web/systest/context1.jsp
Index: context1.jsp
===================================================================
<!--
Copyright 2002,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.
-->
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="s" uri="http://jakarta.apache.org/struts/tags-faces" %>
<f:view>
<s:html locale="true" xhtml="true">
<head>
<title>context1</title>
</head>
<body>
<s:form id="form"
action="/context">
<h:panelGrid columns="3">
<%-- ViewRoot Values --%>
<h:outputText value="FacesContext.getViewRoot()"/>
<h:outputText value="====================================="/>
<h:outputText value="====================================="/>
<h:outputText value="renderKitId"/>
<h:outputText id="renderKitIdFC"
value="#{facesContext.viewRoot.renderKitId}"/>
<h:outputText value=""/>
<h:outputText value="viewId"/>
<h:outputText id="viewIdFC"
value="#{facesContext.viewRoot.viewId}"/>
<h:outputText value=""/>
<%-- ExternalContext Values --%>
<h:outputText value="ExternalContext"/>
<h:outputText value="====================================="/>
<h:outputText value="====================================="/>
<h:outputText value="authType"/>
<h:outputText id="authTypeEC"
value="#{facesContext.externalContext.authType}"/>
<h:outputText value=""/>
<h:outputText value="remoteUser"/>
<h:outputText id="remoteUserEC"
value="#{facesContext.externalContext.remoteUser}"/>
<h:outputText value=""/>
<h:outputText value="requestContextPath"/>
<h:outputText id="requestContextPathEC"
value="#{facesContext.externalContext.requestContextPath}"/>
<h:outputText value=""/>
<h:outputText value="requestLocale"/>
<h:outputText id="requestLocaleEC"
value="#{facesContext.externalContext.requestLocale}"/>
<h:outputText value=""/>
<h:outputText value="requestPathInfo"/>
<h:outputText id="requestPathInfoEC"
value="#{facesContext.externalContext.requestPathInfo}"/>
<h:outputText value=""/>
<h:outputText value="requestServletPath"/>
<h:outputText id="requestServletPathEC"
value="#{facesContext.externalContext.requestServletPath}"/>
<h:outputText value=""/>
<%-- Request Values --%>
<h:outputText value="HttpServletRequest"/>
<h:outputText value="====================================="/>
<h:outputText value="====================================="/>
<h:outputText value="authType"/>
<h:outputText id="authTypeRQ"
value="#{facesContext.externalContext.request.authType}"/>
<h:outputText id="authTypeCA"
value="#{contextAction.authType}"/>
<h:outputText value="contextPath"/>
<h:outputText id="contextPathRQ"
value="#{facesContext.externalContext.request.contextPath}"/>
<h:outputText id="contextPathCA"
value="#{contextAction.contextPath}"/>
<h:outputText value="locale"/>
<h:outputText id="localeRQ"
value="#{facesContext.externalContext.request.locale}"/>
<h:outputText id="localeCA"
value="#{contextAction.locale}"/>
<h:outputText value="pathInfo"/>
<h:outputText id="pathInfoRQ"
value="#{facesContext.externalContext.request.pathInfo}"/>
<h:outputText id="pathInfoCA"
value="#{contextAction.pathInfo}"/>
<h:outputText value="remoteUser"/>
<h:outputText id="remoteUserRQ"
value="#{facesContext.externalContext.request.remoteUser}"/>
<h:outputText id="remoteUserCA"
value="#{contextAction.remoteUser}"/>
<h:outputText value="servletPath"/>
<h:outputText id="servletPathRQ"
value="#{facesContext.externalContext.request.servletPath}"/>
<h:outputText id="servletPathCA"
value="#{contextAction.servletPath}"/>
<%-- ServletContext Values --%>
<h:outputText value="ServletContext"/>
<h:outputText value="====================================="/>
<h:outputText value="====================================="/>
<h:outputText value="majorVersion"/>
<h:outputText id="majorVersionSC"
value="#{facesContext.externalContext.context.majorVersion}"/>
<h:outputText value=""/>
<h:outputText value="minorVersion"/>
<h:outputText id="minorVersionSC"
value="#{facesContext.externalContext.context.minorVersion}"/>
<h:outputText value=""/>
<h:outputText value="serverInfo"/>
<h:outputText id="serverInfoSC"
value="#{facesContext.externalContext.context.serverInfo}"/>
<h:outputText value=""/>
<h:outputText value="servletContextName"/>
<h:outputText id="servletContextNameSC"
value="#{facesContext.externalContext.context.servletContextName}"/>
<h:outputText value=""/>
</h:panelGrid>
</s:form>
</body>
</s:html>
</f:view>
1.4 +8 -0
jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/struts-config.xml
Index: struts-config.xml
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/struts-config.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- struts-config.xml 8 Aug 2004 03:28:35 -0000 1.3
+++ struts-config.xml 28 Aug 2004 07:44:54 -0000 1.4
@@ -49,6 +49,9 @@
<!-- ========== Global Forward Definitions ============================== -->
<global-forwards>
+ <forward name="context1"
+ path="/context1.jsp"/>
+
<forward name="logon"
path="/logon.jsp"/>
@@ -60,6 +63,11 @@
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
+
+ <!-- Render Context Values Action -->
+ <action path="/context"
+ type="org.apache.struts.faces.systest.ContextAction"
+ validate="false"/>
<!-- Execute Logon Action -->
<action path="/logon"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]