Author: alexsmirnov
Date: 2008-11-12 04:11:15 -0500 (Wed, 12 Nov 2008)
New Revision: 11102
Modified:
trunk/framework/jsf-test/pom.xml
trunk/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
trunk/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
Log:
Start progress in AJAX tests
Modified: trunk/framework/jsf-test/pom.xml
===================================================================
--- trunk/framework/jsf-test/pom.xml 2008-11-12 09:10:00 UTC (rev 11101)
+++ trunk/framework/jsf-test/pom.xml 2008-11-12 09:11:15 UTC (rev 11102)
@@ -23,12 +23,8 @@
</dependency>
<dependency>
<groupId>javax.faces</groupId>
-
<artifactId>jsf-impl</artifactId>
-
<version>1.2_10</version>
-
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>el-impl</groupId>
@@ -70,5 +66,40 @@
<artifactId>nekohtml</artifactId>
<version>1.9.9</version>
</dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>jstl</groupId>
+ <artifactId>jstl</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>1.2_10</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.0</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-12
09:10:00 UTC (rev 11101)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-12
09:11:15 UTC (rev 11102)
@@ -71,30 +71,16 @@
}
}
facesServer = new StagingServer();
- ServletContainer facesServletContainer = new ServletContainer("*.jsf", new
FacesServlet());
- facesServletContainer.setName("Faces Servlet");
- try {
- // Check for an ajax4jsf filter.
- Class<? extends Filter> ajaxFilterClass = contextClassLoader
- .loadClass("org.ajax4jsf.Filter")
- .asSubclass(Filter.class);
- Filter ajaxFilter = ajaxFilterClass.newInstance();
- FilterContainer filterContainer = new
FilterContainer(ajaxFilter,facesServletContainer);
- filterContainer.setName("ajax4jsf");
- facesServer.addResource("/WEB-INF/web.xml",
- "org/richfaces/test/ajax-web.xml");
- facesServer.addServlet(filterContainer);
- } catch (ClassNotFoundException e) {
- // No Richfaces filter, uses servlet directly.
- facesServer.addResource("/WEB-INF/web.xml",
- "org/richfaces/test/web.xml");
- facesServer.addServlet(facesServletContainer);
- }
- facesServer.addInitParameter(
- StateManager.STATE_SAVING_METHOD_PARAM_NAME,
- StateManager.STATE_SAVING_METHOD_SERVER);
- facesServer.addInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
- ".xhtml");
+ setupFacesServlet();
+ setupFacesListener();
+ setupWebContent();
+ facesServer.init();
+ }
+
+ /**
+ *
+ */
+ protected void setupFacesListener() {
EventListener listener = null;
try {
Class<? extends EventListener> listenerClass = contextClassLoader
@@ -121,10 +107,41 @@
throw new TestException("Error instantiate JSF RI listener", e);
}
facesServer.addWebListener(listener);
- setupWebContent(facesServer);
- facesServer.init();
}
+ /**
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ protected void setupFacesServlet() {
+ ServletContainer facesServletContainer = new ServletContainer("*.jsf", new
FacesServlet());
+ facesServletContainer.setName("Faces Servlet");
+ try {
+ // Check for an ajax4jsf filter.
+ Class<? extends Filter> ajaxFilterClass = contextClassLoader
+ .loadClass("org.ajax4jsf.Filter")
+ .asSubclass(Filter.class);
+ Filter ajaxFilter = ajaxFilterClass.newInstance();
+ FilterContainer filterContainer = new
FilterContainer(ajaxFilter,facesServletContainer);
+ filterContainer.setName("ajax4jsf");
+ facesServer.addResource("/WEB-INF/web.xml",
+ "org/richfaces/test/ajax-web.xml");
+ facesServer.addServlet(filterContainer);
+ } catch (ClassNotFoundException e) {
+ // No Richfaces filter, uses servlet directly.
+ facesServer.addResource("/WEB-INF/web.xml",
+ "org/richfaces/test/web.xml");
+ facesServer.addServlet(facesServletContainer);
+ } catch (Exception e) {
+ throw new TestException(e);
+ }
+ facesServer.addInitParameter(
+ StateManager.STATE_SAVING_METHOD_PARAM_NAME,
+ StateManager.STATE_SAVING_METHOD_SERVER);
+ facesServer.addInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
+ ".xhtml");
+ }
+
protected void setupMyFaces() {
// Do nothing by default.
}
@@ -134,7 +151,7 @@
facesServer.addInitParameter("com.sun.faces.verifyObjects",
"true");
}
- protected void setupWebContent(StagingServer facesServer){
+ protected void setupWebContent(){
}
Modified: trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-12
09:10:00 UTC (rev 11101)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-12
09:11:15 UTC (rev 11102)
@@ -4,6 +4,7 @@
package org.richfaces.test;
import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebConnection;
@@ -24,6 +25,7 @@
public LocalWebClient(StagingServer server) {
super();
this.server = server;
+ setAjaxController(new NicelyResynchronizingAjaxController());
}
/**
@@ -32,6 +34,7 @@
public LocalWebClient(StagingServer server,BrowserVersion browserVersion) {
super(browserVersion);
this.server = server;
+ setAjaxController(new NicelyResynchronizingAjaxController());
}
/**
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java 2008-11-12
09:10:00 UTC (rev 11101)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java 2008-11-12
09:11:15 UTC (rev 11102)
@@ -13,6 +13,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
@@ -40,6 +41,8 @@
*/
public class StagingConnection {
+ private static final Logger log = ServerLogger.SERVER.getLogger();
+
private final StagingServer server;
final URL url;
@@ -137,6 +140,8 @@
}
public void start() {
+ log.fine("start "+getMethod()+" request processing for file
"+url.getFile());
+ log.fine("request parameters: "+requestParameters);
server.requestStarted(request);
started = true;
}
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java 2008-11-12
09:10:00 UTC (rev 11101)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java 2008-11-12
09:11:15 UTC (rev 11102)
@@ -15,15 +15,17 @@
import javax.servlet.ServletResponse;
public class FilterContainer implements RequestChain {
-
+
private final Filter filter;
-
+
private final RequestChain next;
-
- private String name = "Default";
+ private String name = "Default";
+
private final Map<String, String> initParameters;
+ private boolean initialized = false;
+
/**
* @param filter
* @param next
@@ -44,21 +46,21 @@
public void execute(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
- FilterChain chain = new FilterChain(){
+ FilterChain chain = new FilterChain() {
public void doFilter(ServletRequest request,
ServletResponse response) throws IOException,
ServletException {
next.execute(request, response);
-
+
}
-
+
};
filter.doFilter(request, response, chain);
-
+
}
-
- public void addInitParameter(String name, String value){
+
+ public void addInitParameter(String name, String value) {
initParameters.put(name, value);
}
@@ -67,32 +69,39 @@
}
public void destroy() {
- next.destroy();
- filter.destroy();
+ if (initialized) {
+ next.destroy();
+ filter.destroy();
+ initialized = false;
+ }
}
- public void init(final StagingServletContext context) throws ServletException {
- filter.init(new FilterConfig(){
+ public void init(final StagingServletContext context)
+ throws ServletException {
+ if (!initialized) {
+ filter.init(new FilterConfig() {
- public String getFilterName() {
- return name;
- }
+ public String getFilterName() {
+ return name;
+ }
- public String getInitParameter(String name) {
- return initParameters.get(name);
- }
+ public String getInitParameter(String name) {
+ return initParameters.get(name);
+ }
- @SuppressWarnings("unchecked")
- public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
- }
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
- public ServletContext getServletContext() {
- return context;
- }
-
- });
- next.init(context);
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ });
+ next.init(context);
+ initialized = true;
+ }
}
public String getPathInfo(String path) {
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java 2008-11-12
09:10:00 UTC (rev 11101)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java 2008-11-12
09:11:15 UTC (rev 11102)
@@ -19,31 +19,32 @@
import org.richfaces.test.ServerLogger;
-
/**
* @author asmirnov
- *
+ *
*/
public class ServletContainer implements RequestChain {
-
+
private static final Logger log = ServerLogger.SERVER.getLogger();
-
+
private final Servlet servlet;
-
+
private final boolean prefixMapped;
-
+
private final String mapping;
-
+
private final Map<String, String> initParameters;
-
+
private String name = "Default";
+ private boolean initialized = false;
+
/**
* @param mapping
* @param servlet
*/
public ServletContainer(String mapping, Servlet servlet) {
- if(null == mapping){
+ if (null == mapping) {
this.prefixMapped = true;
this.mapping = "";
} else if (mapping.startsWith("*")) {
@@ -51,18 +52,18 @@
this.mapping = mapping.substring(1);
} else if (mapping.endsWith("*")) {
this.prefixMapped = true;
- this.mapping = mapping.substring(0,mapping.length()-1);
+ this.mapping = mapping.substring(0, mapping.length() - 1);
} else {
- throw new IllegalArgumentException("Invalid mapping "+mapping);
+ throw new IllegalArgumentException("Invalid mapping " + mapping);
}
this.servlet = servlet;
this.initParameters = new HashMap<String, String>();
}
-
-
- public void addInitParameter(String name, String value){
+
+ public void addInitParameter(String name, String value) {
initParameters.put(name, value);
}
+
/**
* @return the name
*/
@@ -71,80 +72,96 @@
}
/**
- * @param name the name to set
+ * @param name
+ * the name to set
*/
public void setName(String name) {
this.name = name;
}
- /* (non-Javadoc)
- * @see org.richfaces.test.staging.RequestChain#isApplicable(java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.test.staging.RequestChain#isApplicable(java.lang.String)
*/
public boolean isApplicable(String path) {
- if(prefixMapped && path.startsWith(mapping)){
+ if (prefixMapped && path.startsWith(mapping)) {
return true;
- } else if(!prefixMapped && path.endsWith(mapping)){
+ } else if (!prefixMapped && path.endsWith(mapping)) {
return true;
} else {
return false;
}
}
- public String getServletPath(String path){
+ public String getServletPath(String path) {
if (!isApplicable(path)) {
return null;
}
- if(prefixMapped){
+ if (prefixMapped) {
return mapping;
} else {
return path;
}
}
-
+
public String getPathInfo(String path) {
if (!isApplicable(path)) {
return null;
}
- if(prefixMapped){
+ if (prefixMapped) {
return path.substring(mapping.length());
} else {
return null;
}
-
+
}
-
- public void init(final StagingServletContext context) throws ServletException {
- servlet.init(new ServletConfig(){
- public String getInitParameter(String name) {
- return initParameters.get(name);
- }
+ public void init(final StagingServletContext context)
+ throws ServletException {
+ if (!initialized) {
+ servlet.init(new ServletConfig() {
- @SuppressWarnings("unchecked")
- public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
- }
+ public String getInitParameter(String name) {
+ return initParameters.get(name);
+ }
- public ServletContext getServletContext() {
- return context;
- }
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
- public String getServletName() {
- return name;
- }
-
- });
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ public String getServletName() {
+ return name;
+ }
+
+ });
+ initialized = true;
+ }
}
- /* (non-Javadoc)
- * @see org.richfaces.test.staging.RequestChain#execute(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.test.staging.RequestChain#execute(javax.servlet.ServletRequest
+ * , javax.servlet.ServletResponse)
*/
- public void execute(ServletRequest request, ServletResponse response) throws
ServletException, IOException {
+ public void execute(ServletRequest request, ServletResponse response)
+ throws ServletException, IOException {
this.servlet.service(request, response);
-
+
}
public void destroy() {
- this.servlet.destroy();
+ if (initialized) {
+ this.servlet.destroy();
+ initialized = false;
+ }
}
}
Modified: trunk/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
===================================================================
---
trunk/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-12
09:10:00 UTC (rev 11101)
+++
trunk/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-12
09:11:15 UTC (rev 11102)
@@ -48,7 +48,7 @@
}
@Override
- protected void setupWebContent(StagingServer facesServer) {
+ protected void setupWebContent() {
facesServer.addResource("/WEB-INF/faces-config.xml",
"org/richfaces/test/faces-config.xml");
facesServer.addResource("/hello.xhtml",
"org/richfaces/test/hello.xhtml");