Author: alexsmirnov
Date: 2008-11-11 19:43:49 -0500 (Tue, 11 Nov 2008)
New Revision: 11095
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/EventInvoker.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/NotImplementedException.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/RequestChain.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/web.xml
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/response.xhtml
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/wave.med.gif
Removed:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalServer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/ServerConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpRequest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpResponse.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpSession.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubServletConfig.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubServletContext.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/faces-config.xml
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/web.xml
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourcePathTest.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourceTest.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServletTest.java
Log:
Finish test framework implementation
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,159 @@
+/**
+ *
+ */
+package org.richfaces.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.EventListener;
+import java.util.logging.LogManager;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.webapp.FacesServlet;
+
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class AbstractFacesTest {
+
+ private ClassLoader contextClassLoader;
+
+ protected StagingServer facesServer;
+
+ protected StagingConnection connection;
+
+ protected FacesContext facesContext;
+
+ protected Lifecycle lifecycle;
+
+ protected Application application;
+
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUpServer() throws Exception {
+ contextClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(
+ this.getClass().getClassLoader());
+ InputStream stream = FacesServerTest.class
+ .getResourceAsStream("logging.properties");
+ if (null != stream) {
+ try {
+ LogManager.getLogManager().readConfiguration(stream);
+ } catch (Exception e) {
+ // Ignore it.
+ } finally {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Ignore it.
+ }
+ }
+ }
+ facesServer = new StagingServer();
+ facesServer.addServlet("*.jsf", new FacesServlet());
+ facesServer.addResource("/WEB-INF/web.xml",
+ "org/richfaces/test/web.xml");
+ facesServer.addResource("/WEB-INF/faces-config.xml",
+ "org/richfaces/test/faces-config.xml");
+ facesServer.addInitParameter(
+ StateManager.STATE_SAVING_METHOD_PARAM_NAME,
+ StateManager.STATE_SAVING_METHOD_SERVER);
+ facesServer.addInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
+ ".xhtml");
+ facesServer.addInitParameter("com.sun.faces.validateXml", "true");
+ facesServer.addInitParameter("com.sun.faces.verifyObjects",
"true");
+ EventListener listener = null;
+ try {
+ Class<? extends EventListener> listenerClass = contextClassLoader
+ .loadClass("com.sun.faces.config.ConfigureListener")
+ .asSubclass(EventListener.class);
+ listener = listenerClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ // No JSF RI listener
+ Class<? extends EventListener> listenerClass;
+ try {
+ listenerClass = contextClassLoader
+ .loadClass(
+ "org.apache.myfaces.webapp.StartupServletContextListener")
+ .asSubclass(EventListener.class);
+ listener = listenerClass.newInstance();
+ } catch (ClassNotFoundException e1) {
+ throw new TestException("No JSF listeners have been found", e1);
+ } catch (Exception e2) {
+ throw new TestException("Error instantiate MyFaces listener", e2);
+ }
+ } catch (Exception e) {
+ throw new TestException("Error instantiate JSF RI listener", e);
+ }
+ facesServer.addWebListener(listener);
+ setupWebContent(facesServer);
+ facesServer.init();
+ }
+
+ protected void setupWebContent(StagingServer facesServer){
+
+ }
+
+
+
+ protected void setupFacesRequest() throws Exception {
+ connection = facesServer.getConnection(new
URL("http://localhost/index.jsf"));
+ setupConnection(connection);
+ connection.start();
+ ApplicationFactory applicationFactory = (ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ application = applicationFactory.getApplication();
+ LifecycleFactory lifecycleFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ FacesContextFactory facesContextFactory = (FacesContextFactory)
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = facesContextFactory.getFacesContext(facesServer.getContext(),
connection.getRequest(), connection.getResponse(), lifecycle);
+ facesContext.setViewRoot(setupView());
+ }
+
+ protected UIViewRoot setupView() {
+ return null;
+ }
+
+ protected void setupConnection(StagingConnection connection) {
+
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDownServer() throws Exception {
+ if(null != facesContext){
+ facesContext.release();
+ facesContext = null;
+ }
+ if(null != connection){
+ if(!connection.isFinished()){
+ connection.finish();
+ }
+ connection = null;
+ }
+ facesServer.destroy();
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+ facesServer = null;
+ application = null;
+ lifecycle = null;
+ }
+
+}
Property changes on:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/EventInvoker.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/EventInvoker.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/EventInvoker.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+package org.richfaces.test;
+
+import java.util.EventListener;
+
+public interface EventInvoker<T extends EventListener> {
+ public void invoke(T listener);
+}
\ No newline at end of file
Property changes on:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/EventInvoker.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalServer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalServer.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalServer.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,234 +0,0 @@
-package org.richfaces.test;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.EventListener;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextAttributeEvent;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
-
-import org.richfaces.test.stub.ClasspathServerResource;
-import org.richfaces.test.stub.ServerResource;
-import org.richfaces.test.stub.ServerResourcePath;
-import org.richfaces.test.stub.ServerResourcesDirectory;
-import org.richfaces.test.stub.ServletContainer;
-import org.richfaces.test.stub.StaticServlet;
-import org.richfaces.test.stub.StubHttpSession;
-import org.richfaces.test.stub.StubServletContext;
-
-
-/**
- * Hello world!
- *
- */
-public class LocalServer {
-
-
- private List<ServletContainer> servlets = new
ArrayList<ServletContainer>();
-
- private ServletContainer defaultServlet;
-
- private List<EventListener> contextListeners = new
ArrayList<EventListener>();
-
- private Map<String,String> initParameters=new HashMap<String, String>();
-
- private ServerResource serverRoot = new ServerResourcesDirectory();
-
- private class LocalContext extends StubServletContext{
-
- @Override
- protected void valueBound(ServletContextAttributeEvent event) {
- // inform listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof ServletContextAttributeListener) {
- ServletContextAttributeListener contextListener = (ServletContextAttributeListener)
listener;
- contextListener.attributeAdded(event);
- }
- }
- }
-
- @Override
- protected void valueReplaced(ServletContextAttributeEvent event) {
- // inform listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof ServletContextAttributeListener) {
- ServletContextAttributeListener contextListener = (ServletContextAttributeListener)
listener;
- contextListener.attributeReplaced(event);
- }
- }
- }
-
- @Override
- protected void valueUnbound(
- ServletContextAttributeEvent event) {
- // inform listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof ServletContextAttributeListener) {
- ServletContextAttributeListener contextListener = (ServletContextAttributeListener)
listener;
- contextListener.attributeRemoved(event);
- }
- }
- }
-
- @Override
- /**
- * @param path
- * @return
- */
- protected ServerResource getServerResource(String path) {
- return serverRoot.getResource(new ServerResourcePath(path));
- }
-
- }
-
- private StubServletContext context;
-
- private class ServerHttpSession extends StubHttpSession {
-
- public ServletContext getServletContext() {
- return context;
- }
-
- @Override
- protected void valueBound(HttpSessionBindingEvent sessionBindingEvent) {
- // inform session listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof HttpSessionAttributeListener) {
- HttpSessionAttributeListener contextListener = (HttpSessionAttributeListener)
listener;
- contextListener.attributeAdded(sessionBindingEvent);
- }
- }
- }
-
- @Override
- protected void valueUnbound(HttpSessionBindingEvent sessionBindingEvent) {
- // inform session listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof HttpSessionAttributeListener) {
- HttpSessionAttributeListener contextListener = (HttpSessionAttributeListener)
listener;
- contextListener.attributeRemoved(sessionBindingEvent);
- }
- }
- }
-
- }
-
- private ServerHttpSession session;
-
-
- public void addServlet(String mapping,Servlet servlet){
- servlets.add(new ServletContainer(mapping,servlet));
- }
-
- public ServletContainer getServlet(String path) {
- ServletContainer result = defaultServlet;
- for (ServletContainer servlet : servlets) {
- if(servlet.isApplicable(path)){
- result = servlet;
- break;
- }
- }
- return result;
- }
-
- public void addInitParameter(String name, String value) {
- initParameters.put(name, value);
- }
-
- public void addResource(String path, String resource){
- serverRoot.addResource(new ServerResourcePath(path), new
ClasspathServerResource(resource));
- }
-
- public void addWebListener(EventListener listener) {
- contextListeners.add(listener);
- }
-
- public HttpSession getSession(){
- return getSession(true);
- }
-
- public HttpSession getSession(boolean create){
- if(null == this.session && create){
- this.session = new ServerHttpSession();
- // inform session listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof HttpSessionListener) {
- HttpSessionListener contextListener = (HttpSessionListener) listener;
- contextListener.sessionCreated(new HttpSessionEvent(session));
- }
- }
- }
- return session;
- }
-
- public void init() throws ServletException {
- // Create context.
- this.context = new LocalContext();
- // Create init parameters
- context.addInitParameters(initParameters);
- // Inform listeners
- for (EventListener listener : contextListeners) {
- if (listener instanceof ServletContextListener) {
- ServletContextListener contextListener = (ServletContextListener) listener;
- contextListener.contextInitialized(new ServletContextEvent(context));
-
- }
- }
- // Init servlets
- for (ServletContainer servlet : servlets) {
- // init servlet
- servlet.init(this.context);
- }
- defaultServlet = new ServletContainer(null,new StaticServlet());
- defaultServlet.init(getContext());
-
- }
-
- public void destroy(){
- // Destroy session
- if (null != this.session) {
- // inform session listeners.
- for (EventListener listener : contextListeners) {
- if (listener instanceof HttpSessionListener) {
- HttpSessionListener contextListener = (HttpSessionListener) listener;
- contextListener.sessionDestroyed(new HttpSessionEvent(session));
- }
- }
- session.destroy();
- }
- // Inform listeners
- for (EventListener listener : contextListeners) {
- if (listener instanceof ServletContextListener) {
- ServletContextListener contextListener = (ServletContextListener) listener;
- contextListener.contextDestroyed(new ServletContextEvent(context));
-
- }
- }
- // Destroy servlets
- for (ServletContainer servlet : servlets) {
- servlet.destroy();
- }
- defaultServlet.destroy();
- }
-
- public ServerConnection getConnection(URL url) {
- return new ServerConnection(this,url);
- }
-
- public StubServletContext getContext() {
- return context;
- }
-}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -14,14 +14,14 @@
@SuppressWarnings("serial")
public class LocalWebClient extends WebClient {
- private final LocalServer server;
+ private final StagingServer server;
private transient WebConnection webConnection;
/**
*
*/
- public LocalWebClient(LocalServer server) {
+ public LocalWebClient(StagingServer server) {
super();
this.server = server;
}
@@ -29,7 +29,7 @@
/**
* @param browserVersion
*/
- public LocalWebClient(LocalServer server,BrowserVersion browserVersion) {
+ public LocalWebClient(StagingServer server,BrowserVersion browserVersion) {
super(browserVersion);
this.server = server;
}
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -7,23 +7,28 @@
import javax.servlet.ServletException;
+import org.apache.commons.httpclient.NameValuePair;
+
import com.gargoylesoftware.htmlunit.WebConnection;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
public final class LocalWebConnection implements WebConnection {
- private final LocalServer localServer;
+ private final StagingServer localServer;
/**
* @param localServer
*/
- public LocalWebConnection(LocalServer localServer) {
+ public LocalWebConnection(StagingServer localServer) {
this.localServer = localServer;
}
public WebResponse getResponse(WebRequestSettings settings)
throws IOException {
- ServerConnection connection = localServer.getConnection(settings.getUrl());
+ StagingConnection connection = localServer.getConnection(settings.getUrl());
+ for (NameValuePair param : settings.getRequestParameters()) {
+ connection.addRequestParameter(param.getName(), param.getValue());
+ }
try {
connection.execute();
} catch (ServletException e) {
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -18,9 +18,9 @@
public final class LocalWebResponse implements WebResponse {
private final WebRequestSettings settings;
- private final ServerConnection serverConnection;
+ private final StagingConnection serverConnection;
- public LocalWebResponse(WebRequestSettings settings,ServerConnection serverConnection)
{
+ public LocalWebResponse(WebRequestSettings settings,StagingConnection serverConnection)
{
this.settings = settings;
this.serverConnection = serverConnection;
}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/ServerConnection.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/ServerConnection.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/ServerConnection.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,355 +0,0 @@
-/**
- *
- */
-package org.richfaces.test;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.richfaces.test.stub.ServletContainer;
-import org.richfaces.test.stub.StubHttpRequest;
-import org.richfaces.test.stub.StubHttpResponse;
-import org.richfaces.test.stub.StubServletContext;
-
-import com.gargoylesoftware.htmlunit.WebRequestSettings;
-import com.gargoylesoftware.htmlunit.WebResponse;
-
-/**
- * This class represent single connection to the server.
- *
- * @author asmirnov
- *
- */
-public class ServerConnection {
-
- private final LocalServer server;
-
- final URL url;
-
- private ConnectionRequest request;
-
- ConnectionResponse response;
-
- private final ServletContainer servlet;
-
- private HttpMethod method = HttpMethod.GET;
-
- private static final Cookie[] COOKIE = new Cookie[] {};
-
- private List<Cookie> cookies = new ArrayList<Cookie>();
-
- private Map<String, String[]> requestParameters = new HashMap<String,
String[]>();
-
- private final String pathInfo;
-
- private final String servletPath;
-
- private boolean finished = false;
-
- public ServerConnection(LocalServer localServer, URL url) {
- this.server = localServer;
- this.url = url;
- String path = url.getPath();
- servlet = localServer.getServlet(path);
- if (null == servlet) {
- throw new IllegalArgumentException();
- }
- this.pathInfo = servlet.getPathInfo(path);
- this.servletPath = servlet.getServletPath(path);
- this.request = new ConnectionRequest();
- this.response = new ConnectionResponse();
- this.request.setAttribute("javax.servlet.include.path_info",
- this.pathInfo);
- this.request.setAttribute("javax.servlet.include.servlet_path",
- this.servletPath);
- }
-
- /**
- * @return the finished
- */
- public boolean isFinished() {
- return finished;
- }
-
- /**
- * @param finished
- * the finished to set
- */
- public void setFinished(boolean finished) {
- this.finished = finished;
- }
-
- private void checkFinished() {
- if (!isFinished()) {
- throw new IllegalStateException("request have not been executed");
- }
- }
-
- public void execute() throws ServletException, IOException {
- if (isFinished()) {
- throw new IllegalStateException(
- "request already have been executed");
- }
- this.servlet.execute(request, response);
- setFinished(true);
- }
-
- /**
- * @return the method
- */
- public HttpMethod getMethod() {
- return method;
- }
-
- /**
- * @param method
- * the method to set
- */
- public void setMethod(HttpMethod method) {
- this.method = method;
- }
-
- /**
- * @return the url
- */
- public URL getUrl() {
- return url;
- }
-
- public void addRequestParameter(String name, String value) {
- String[] values = requestParameters.get(name);
- if (null == values) {
- values = new String[1];
- } else {
- String[] newValues = new String[values.length + 1];
- System.arraycopy(values, 0, newValues, 0, values.length);
- values = newValues;
- }
- values[values.length - 1] = value;
- requestParameters.put(name, values);
- }
-
- public String getContentAsString() {
- checkFinished();
- String content = response.getWriterContent();
- if (null == content) {
- byte[] streamContent = response.getStreamContent();
- if (null != streamContent) {
- String encoding = response.getCharacterEncoding();
- if (null != encoding) {
- try {
- content = new String(streamContent, encoding);
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- }
- } else {
- content = new String(streamContent);
- }
- }
- }
- return content;
- }
-
- public byte[] getResponseBody() {
- checkFinished();
- byte[] content = response.getStreamContent();
- if (null == content) {
- String writerContent = response.getWriterContent();
- if (null != writerContent) {
- try {
- content = writerContent.getBytes(response
- .getCharacterEncoding());
- } catch (UnsupportedEncodingException e) {
- content = writerContent.getBytes();
- }
- } else {
- content = new byte[0];
- }
- }
- return content;
- }
-
- /**
- * @return the cookies
- */
- public List<Cookie> getCookies() {
- return cookies;
- }
-
- /**
- * @return the request
- */
- public StubHttpRequest getRequest() {
- return request;
- }
-
- /**
- * @return the response
- */
- public StubHttpResponse getResponse() {
- return response;
- }
-
- private class ConnectionRequest extends StubHttpRequest {
-
- public Cookie[] getCookies() {
- return cookies.toArray(COOKIE);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getMethod()
- */
- public String getMethod() {
- return method.toString();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getServletPath()
- */
- public String getServletPath() {
- return servletPath;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getPathInfo()
- */
- public String getPathInfo() {
- return pathInfo;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getQueryString()
- */
- public String getQueryString() {
- return url.getQuery();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getRequestURI()
- */
- public String getRequestURI() {
- return url.getPath();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
- */
- public String getParameter(String name) {
- String[] values = requestParameters.get(name);
- if (null != values && values.length > 0) {
- return values[0];
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getParameterMap()
- */
- @SuppressWarnings("unchecked")
- public Map getParameterMap() {
- return Collections.unmodifiableMap(requestParameters);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getParameterNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getParameterNames() {
- return Collections.enumeration(requestParameters.keySet());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.ServletRequest#getParameterValues(java.lang.String)
- */
- public String[] getParameterValues(String name) {
- return requestParameters.get(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getSession()
- */
- public HttpSession getSession() {
- return server.getSession();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
- */
- public HttpSession getSession(boolean create) {
- return server.getSession(create);
- }
-
- }
-
- private class ConnectionResponse extends StubHttpResponse {
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http
- * .Cookie )
- */
- public void addCookie(Cookie cookie) {
- cookies.add(cookie);
-
- }
-
- }
-
- public String getCharacterEncoding() {
- checkFinished();
- return response.getCharacterEncoding();
- }
-
- public String getContentType() {
- checkFinished();
- return response.getContentType();
- }
-
- public int getStatus() {
- checkFinished();
- return response.getStatus();
- }
-
- public String getErrorMessage() {
- checkFinished();
- return response.getErrorMessage();
- }
-
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
(from rev 11071,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/ServerConnection.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingConnection.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,440 @@
+/**
+ *
+ */
+package org.richfaces.test;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.richfaces.test.staging.RequestChain;
+import org.richfaces.test.staging.StagingHttpRequest;
+import org.richfaces.test.staging.StagingHttpResponse;
+import org.richfaces.test.staging.StagingServletContext;
+
+import com.gargoylesoftware.htmlunit.WebRequestSettings;
+import com.gargoylesoftware.htmlunit.WebResponse;
+
+/**
+ * This class represent single connection to the server.
+ *
+ * @author asmirnov
+ *
+ */
+public class StagingConnection {
+
+ private final StagingServer server;
+
+ final URL url;
+
+ private ConnectionRequest request;
+
+ ConnectionResponse response;
+
+ private final RequestChain servlet;
+
+ private HttpMethod method = HttpMethod.GET;
+
+ private static final Cookie[] COOKIE = new Cookie[] {};
+
+ private List<Cookie> cookies = new ArrayList<Cookie>();
+
+ private Map<String, String[]> requestParameters = new HashMap<String,
String[]>();
+
+ private final String pathInfo;
+
+ private final String servletPath;
+
+ private boolean finished = false;
+
+ private boolean started = false;
+
+ private String queryString;
+
+ public StagingConnection(StagingServer localServer, URL url) {
+ this.server = localServer;
+ this.url = url;
+ String path = url.getPath();
+ servlet = localServer.getServlet(path);
+ if (null == servlet) {
+ throw new IllegalArgumentException();
+ }
+ this.pathInfo = servlet.getPathInfo(path);
+ this.servletPath = servlet.getServletPath(path);
+ this.request = new ConnectionRequest();
+ this.response = new ConnectionResponse();
+ this.request.setAttribute("javax.servlet.include.path_info",
+ this.pathInfo);
+ this.request.setAttribute("javax.servlet.include.servlet_path",
+ this.servletPath);
+ queryString = url.getQuery();
+ if (null != queryString) {
+ String[] queryParams = queryString.split("&");
+ for (int i = 0; i < queryParams.length; i++) {
+ String par = queryParams[i];
+ int eqIndex = par.indexOf('=');
+ if(eqIndex>=0){
+ addRequestParameter(par.substring(0, eqIndex),
par.substring(eqIndex+1));
+ } else {
+ addRequestParameter(par, null);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * @return the finished
+ */
+ public boolean isFinished() {
+ return finished;
+ }
+
+ /**
+ * @return the started
+ */
+ public boolean isStarted() {
+ return started;
+ }
+
+
+
+ private void checkStarted() {
+ if (!isFinished()) {
+ throw new IllegalStateException("request have not been started");
+ }
+ }
+
+ public void execute() throws ServletException, IOException {
+ if (isStarted() || isFinished()) {
+ throw new IllegalStateException("request have already been executed");
+ }
+ start();
+ this.servlet.execute(request, response);
+ finish();
+ }
+
+ public void finish() {
+ server.requestFinished(request);
+ finished = true;
+ }
+
+ public void start() {
+ server.requestStarted(request);
+ started = true;
+ }
+
+ /**
+ * @return the method
+ */
+ public HttpMethod getMethod() {
+ return method;
+ }
+
+ /**
+ * @param method
+ * the method to set
+ */
+ public void setMethod(HttpMethod method) {
+ this.method = method;
+ }
+
+ /**
+ * @return the url
+ */
+ public URL getUrl() {
+ return url;
+ }
+
+ public void addRequestParameter(String name, String value) {
+ String[] values = requestParameters.get(name);
+ if (null == values) {
+ values = new String[1];
+ } else {
+ String[] newValues = new String[values.length + 1];
+ System.arraycopy(values, 0, newValues, 0, values.length);
+ values = newValues;
+ }
+ values[values.length - 1] = value;
+ requestParameters.put(name, values);
+ }
+
+ public String getContentAsString() {
+ checkStarted();
+ String content = response.getWriterContent();
+ if (null == content) {
+ byte[] streamContent = response.getStreamContent();
+ if (null != streamContent) {
+ String encoding = response.getCharacterEncoding();
+ if (null != encoding) {
+ try {
+ content = new String(streamContent, encoding);
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ }
+ } else {
+ content = new String(streamContent);
+ }
+ }
+ }
+ return content;
+ }
+
+ public byte[] getResponseBody() {
+ checkStarted();
+ byte[] content = response.getStreamContent();
+ if (null == content) {
+ String writerContent = response.getWriterContent();
+ if (null != writerContent) {
+ try {
+ content = writerContent.getBytes(response
+ .getCharacterEncoding());
+ } catch (UnsupportedEncodingException e) {
+ content = writerContent.getBytes();
+ }
+ } else {
+ content = new byte[0];
+ }
+ }
+ return content;
+ }
+
+ /**
+ * @return the cookies
+ */
+ public List<Cookie> getCookies() {
+ return cookies;
+ }
+
+ /**
+ * @return the request
+ */
+ public StagingHttpRequest getRequest() {
+ return request;
+ }
+
+ /**
+ * @return the response
+ */
+ public StagingHttpResponse getResponse() {
+ return response;
+ }
+
+ private class ConnectionRequest extends StagingHttpRequest {
+
+ public Cookie[] getCookies() {
+ return cookies.toArray(COOKIE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getMethod()
+ */
+ public String getMethod() {
+ return method.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getServletPath()
+ */
+ public String getServletPath() {
+ return servletPath;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getPathInfo()
+ */
+ public String getPathInfo() {
+ return pathInfo;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getQueryString()
+ */
+ public String getQueryString() {
+ return queryString;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getRequestURI()
+ */
+ public String getRequestURI() {
+ return url.getPath();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
+ */
+ public String getParameter(String name) {
+ String[] values = requestParameters.get(name);
+ if (null != values && values.length > 0) {
+ return values[0];
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getParameterMap()
+ */
+ @SuppressWarnings("unchecked")
+ public Map getParameterMap() {
+ return Collections.unmodifiableMap(requestParameters);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getParameterNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getParameterNames() {
+ return Collections.enumeration(requestParameters.keySet());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.ServletRequest#getParameterValues(java.lang.String)
+ */
+ public String[] getParameterValues(String name) {
+ return requestParameters.get(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getSession()
+ */
+ public HttpSession getSession() {
+ return server.getSession();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
+ */
+ public HttpSession getSession(boolean create) {
+ return server.getSession(create);
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(String path) {
+ RequestDispatcher dispatcher = null;
+ if(!path.startsWith("/")){
+ try {
+ URL absoluteUrl = new URL(url,path);
+ path = absoluteUrl.getFile();
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ final RequestChain dispatchedServlet = server.getServlet(path);
+ if(null != dispatchedServlet){
+ dispatcher = new RequestDispatcher(){
+
+ public void forward(ServletRequest request,
+ ServletResponse response) throws ServletException,
+ IOException {
+ response.reset();
+ dispatchedServlet.execute(request, response);
+ }
+
+ public void include(ServletRequest request,
+ ServletResponse response) throws ServletException,
+ IOException {
+ dispatchedServlet.execute(request, response);
+ }
+
+ };
+ }
+ return dispatcher;
+ }
+
+ @Override
+ protected void attributeAdded(String name, Object o) {
+ server.requestAttributeAdded(this,name,o);
+
+ }
+
+ @Override
+ protected void attributeRemoved(String name, Object removed) {
+ server.requestAttributeRemoved(this,name,removed);
+
+ }
+
+ @Override
+ protected void attributeReplaced(String name, Object o) {
+ server.requestAttributeReplaced(this,name,o);
+
+ }
+
+ }
+
+ private class ConnectionResponse extends StagingHttpResponse {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http
+ * .Cookie )
+ */
+ public void addCookie(Cookie cookie) {
+ cookies.add(cookie);
+
+ }
+
+ }
+
+ public String getCharacterEncoding() {
+ checkStarted();
+ return response.getCharacterEncoding();
+ }
+
+ public String getContentType() {
+ checkStarted();
+ return response.getContentType();
+ }
+
+ public int getStatus() {
+ checkStarted();
+ return response.getStatus();
+ }
+
+ public String getErrorMessage() {
+ checkStarted();
+ return response.getErrorMessage();
+ }
+
+}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java
(from rev 11071,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalServer.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/StagingServer.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,336 @@
+package org.richfaces.test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestAttributeEvent;
+import javax.servlet.ServletRequestAttributeListener;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.richfaces.test.staging.ClasspathServerResource;
+import org.richfaces.test.staging.RequestChain;
+import org.richfaces.test.staging.ServerResource;
+import org.richfaces.test.staging.ServerResourcePath;
+import org.richfaces.test.staging.ServerResourcesDirectory;
+import org.richfaces.test.staging.RequestChain;
+import org.richfaces.test.staging.ServletContainer;
+import org.richfaces.test.staging.StaticServlet;
+import org.richfaces.test.staging.StagingHttpSession;
+import org.richfaces.test.staging.StagingServletContext;
+
+
+/**
+ * Hello world!
+ *
+ */
+public class StagingServer {
+
+
+ private static final Class<ServletRequestListener> REQUEST_LISTENER_CLASS =
ServletRequestListener.class;
+
+ private static final Class<ServletRequestAttributeListener>
REQUEST_ATTRIBUTE_LISTENER_CLASS = ServletRequestAttributeListener.class;
+
+ private static final Class<ServletContextListener> CONTEXT_LISTENER_CLASS =
ServletContextListener.class;
+
+ private static final Class<HttpSessionListener> SESSION_LISTENER_CLASS =
HttpSessionListener.class;
+
+ private static final Class<HttpSessionAttributeListener>
SESSION_ATTRIBUTE_LISTENER_CLASS = HttpSessionAttributeListener.class;
+
+ private List<RequestChain> servlets = new ArrayList<RequestChain>();
+
+ private RequestChain defaultServlet;
+
+ private List<EventListener> contextListeners = new
ArrayList<EventListener>();
+
+ private Map<String,String> initParameters=new HashMap<String, String>();
+
+ private ServerResource serverRoot = new ServerResourcesDirectory();
+
+ private class LocalContext extends StagingServletContext{
+
+ @Override
+ protected void valueBound(ServletContextAttributeEvent event) {
+ // inform listeners.
+ for (EventListener listener : contextListeners) {
+ if (listener instanceof ServletContextAttributeListener) {
+ ServletContextAttributeListener contextListener = (ServletContextAttributeListener)
listener;
+ contextListener.attributeAdded(event);
+ }
+ }
+ }
+
+ @Override
+ protected void valueReplaced(ServletContextAttributeEvent event) {
+ // inform listeners.
+ for (EventListener listener : contextListeners) {
+ if (listener instanceof ServletContextAttributeListener) {
+ ServletContextAttributeListener contextListener = (ServletContextAttributeListener)
listener;
+ contextListener.attributeReplaced(event);
+ }
+ }
+ }
+
+ @Override
+ protected void valueUnbound(
+ ServletContextAttributeEvent event) {
+ // inform listeners.
+ for (EventListener listener : contextListeners) {
+ if (listener instanceof ServletContextAttributeListener) {
+ ServletContextAttributeListener contextListener = (ServletContextAttributeListener)
listener;
+ contextListener.attributeRemoved(event);
+ }
+ }
+ }
+
+ @Override
+ /**
+ * @param path
+ * @return
+ */
+ protected ServerResource getServerResource(String path) {
+ return serverRoot.getResource(new ServerResourcePath(path));
+ }
+
+ }
+
+ private StagingServletContext context;
+
+ private class ServerHttpSession extends StagingHttpSession {
+
+
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ @Override
+ protected void valueBound(final HttpSessionBindingEvent sessionBindingEvent) {
+ // inform session listeners.
+ fireEvent(SESSION_ATTRIBUTE_LISTENER_CLASS,new
EventInvoker<HttpSessionAttributeListener>(){
+ public void invoke(HttpSessionAttributeListener listener) {
+ listener.attributeAdded(sessionBindingEvent);
+ }
+ });
+ }
+
+ @Override
+ protected void valueUnbound(final HttpSessionBindingEvent sessionBindingEvent) {
+ // inform session listeners.
+ fireEvent(SESSION_ATTRIBUTE_LISTENER_CLASS,new
EventInvoker<HttpSessionAttributeListener>(){
+ public void invoke(HttpSessionAttributeListener listener) {
+ listener.attributeRemoved(sessionBindingEvent);
+ }
+ });
+ }
+
+ @Override
+ protected void valueReplaced(final HttpSessionBindingEvent sessionBindingEvent) {
+ // inform session listeners.
+ fireEvent(SESSION_ATTRIBUTE_LISTENER_CLASS,new
EventInvoker<HttpSessionAttributeListener>(){
+ public void invoke(HttpSessionAttributeListener listener) {
+ listener.attributeReplaced(sessionBindingEvent);
+ }
+ });
+ }
+ }
+
+ private ServerHttpSession session;
+
+
+ public void addServlet(RequestChain servlet) {
+ servlets.add(servlet);
+ }
+
+ public void addServlet(String mapping,Servlet servlet){
+ servlets.add(new ServletContainer(mapping,servlet));
+ }
+
+ public RequestChain getServlet(String path) {
+ RequestChain result = null;
+ for (RequestChain servlet : servlets) {
+ if(servlet.isApplicable(path)){
+ result = servlet;
+ break;
+ }
+ }
+ if(null == result){
+ try {
+ URL resource = context.getResource(path);
+ if(null != resource){
+ result = defaultServlet;
+ }
+ } catch (MalformedURLException e) {
+ // do nothing, just return no servlet.
+ }
+ }
+ return result;
+ }
+
+ public void addInitParameter(String name, String value) {
+ initParameters.put(name, value);
+ }
+
+ public void addResource(String path, String resource){
+ serverRoot.addResource(new ServerResourcePath(path), new
ClasspathServerResource(resource));
+ }
+
+ public void addWebListener(EventListener listener) {
+ contextListeners.add(listener);
+ }
+
+ public HttpSession getSession(){
+ return getSession(true);
+ }
+
+ public HttpSession getSession(boolean create){
+ if(null == this.session && create){
+ this.session = new ServerHttpSession();
+ // inform session listeners.
+ final HttpSessionEvent event = new HttpSessionEvent(session);
+ fireEvent(SESSION_LISTENER_CLASS,new EventInvoker<HttpSessionListener>(){
+ public void invoke(HttpSessionListener listener) {
+ listener.sessionCreated(event);
+ }
+ });
+ }
+ return session;
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("unchecked")
+ private <T extends EventListener> void fireEvent(Class<T>
listenerClass,EventInvoker<T> invoker) {
+ for (EventListener listener : contextListeners) {
+ if (listenerClass.isInstance(listener)) {
+ invoker.invoke((T) listener);
+ }
+ }
+ }
+
+ public void init() {
+ // Create context.
+ this.context = new LocalContext();
+ // Create init parameters
+ context.addInitParameters(initParameters);
+ // Inform listeners
+ final ServletContextEvent event = new ServletContextEvent(context);
+ fireEvent(CONTEXT_LISTENER_CLASS,new EventInvoker<ServletContextListener>(){
+ public void invoke(ServletContextListener listener) {
+ listener.contextInitialized(event);
+ }
+ });
+ // Init servlets
+ try {
+ for (RequestChain servlet : servlets) {
+ // init servlet
+ servlet.init(this.context);
+ }
+ defaultServlet = new ServletContainer(null,new StaticServlet());
+ defaultServlet.init(getContext());
+ } catch(ServletException e){
+ throw new TestException(e);
+ }
+ }
+
+ public void destroy(){
+ // Destroy session
+ if (null != this.session) {
+ // inform session listeners.
+ final HttpSessionEvent event = new HttpSessionEvent(session);
+ fireEvent(SESSION_LISTENER_CLASS,new EventInvoker<HttpSessionListener>(){
+ public void invoke(HttpSessionListener listener) {
+ listener.sessionDestroyed(event);
+ }
+ });
+ session.destroy();
+ }
+ // Inform listeners
+ final ServletContextEvent event = new ServletContextEvent(context);
+ fireEvent(CONTEXT_LISTENER_CLASS,new EventInvoker<ServletContextListener>(){
+ public void invoke(ServletContextListener listener) {
+ listener.contextDestroyed(event);
+ }
+ });
+ // Destroy servlets
+ for (RequestChain servlet : servlets) {
+ servlet.destroy();
+ }
+ defaultServlet.destroy();
+ }
+
+ public StagingConnection getConnection(URL url) {
+ return new StagingConnection(this,url);
+ }
+
+ public StagingServletContext getContext() {
+ return context;
+ }
+
+ public void requestStarted(ServletRequest request) {
+ final ServletRequestEvent event = new ServletRequestEvent(context,request);
+ fireEvent(REQUEST_LISTENER_CLASS, new EventInvoker<ServletRequestListener>(){
+ public void invoke(ServletRequestListener listener) {
+ listener.requestInitialized(event);
+
+ }
+ });
+ }
+
+ public void requestFinished(ServletRequest request) {
+ final ServletRequestEvent event = new ServletRequestEvent(context,request);
+ fireEvent(REQUEST_LISTENER_CLASS, new EventInvoker<ServletRequestListener>(){
+ public void invoke(ServletRequestListener listener) {
+ listener.requestDestroyed(event);
+ }
+ });
+ }
+
+ public void requestAttributeAdded(ServletRequest request,
+ String name, Object o) {
+ final ServletRequestAttributeEvent event = new
ServletRequestAttributeEvent(context,request,name,o);
+ fireEvent(REQUEST_ATTRIBUTE_LISTENER_CLASS, new
EventInvoker<ServletRequestAttributeListener>(){
+ public void invoke(ServletRequestAttributeListener listener) {
+ listener.attributeAdded(event);
+ }
+ });
+ }
+
+ public void requestAttributeRemoved(ServletRequest request,
+ String name, Object removed) {
+ final ServletRequestAttributeEvent event = new
ServletRequestAttributeEvent(context,request,name,removed);
+ fireEvent(REQUEST_ATTRIBUTE_LISTENER_CLASS, new
EventInvoker<ServletRequestAttributeListener>(){
+ public void invoke(ServletRequestAttributeListener listener) {
+ listener.attributeRemoved(event);
+ }
+ });
+ }
+
+ public void requestAttributeReplaced(ServletRequest request,
+ String name, Object value) {
+ final ServletRequestAttributeEvent event = new
ServletRequestAttributeEvent(context,request,name,value);
+ fireEvent(REQUEST_ATTRIBUTE_LISTENER_CLASS, new
EventInvoker<ServletRequestAttributeListener>(){
+ public void invoke(ServletRequestAttributeListener listener) {
+ listener.attributeReplaced(event);
+ }
+ });
+ }
+}
Copied: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging (from
rev 10973, branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub)
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ClasspathServerResource.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,97 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Collections;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.ServletResponse;
-
-import org.richfaces.test.ServerLogger;
-
-/**
- * @author asmirnov
- *
- */
-public class ClasspathServerResource implements ServerResource {
-
- private final String classpath;
-
- private static final Logger log = ServerLogger.RESOURCE.getLogger();
-
-
- /**
- * @param name
- * @param classpath
- */
- public ClasspathServerResource(String classpath) {
- this.classpath = classpath;
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.test.stub.ServerResource#addResource(org.richfaces.test.stub.ServerResource)
- */
- public void addResource(ServerResourcePath path, ServerResource resource) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.test.stub.ServerResource#getResource(org.richfaces.test.stub.ServerResourcePath)
- */
- public ServerResource getResource(ServerResourcePath path) {
- if(null == path){
- throw new NullPointerException();
- }
- if(path.isFile()){
- return this;
- }
- return null;
- }
- /* (non-Javadoc)
- * @see org.richfaces.test.stub.ServerResource#getPaths()
- */
- public Set<String> getPaths() {
- return Collections.emptySet();
- }
-
-
-
- /* (non-Javadoc)
- * @see org.richfaces.test.stub.ServerResource#getAsStream()
- */
- public InputStream getAsStream() throws IOException {
- URL url = getURL();
- if (url != null) {
- URLConnection connection = url.openConnection();
- try {
- connection.setUseCaches(false);
- } catch (IllegalArgumentException e) {
- log.info("RESOURCE_NOT_CACHEABLE");
- }
- return connection.getInputStream();
- } else {
- return null;
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.richfaces.test.stub.ServerResource#getURL()
- */
- public URL getURL() {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if(null == classLoader){
- classLoader = this.getClass().getClassLoader();
- }
- return classLoader.getResource(classpath);
- }
-
-
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ClasspathServerResource.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ClasspathServerResource.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,97 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletResponse;
+
+import org.richfaces.test.ServerLogger;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ClasspathServerResource implements ServerResource {
+
+ private final String classpath;
+
+ private static final Logger log = ServerLogger.RESOURCE.getLogger();
+
+
+ /**
+ * @param name
+ * @param classpath
+ */
+ public ClasspathServerResource(String classpath) {
+ this.classpath = classpath;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.test.staging.ServerResource#addResource(org.richfaces.test.staging.ServerResource)
+ */
+ public void addResource(ServerResourcePath path, ServerResource resource) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.test.staging.ServerResource#getResource(org.richfaces.test.staging.ServerResourcePath)
+ */
+ public ServerResource getResource(ServerResourcePath path) {
+ if(null == path){
+ throw new NullPointerException();
+ }
+ if(path.isFile()){
+ return this;
+ }
+ return null;
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.ServerResource#getPaths()
+ */
+ public Set<String> getPaths() {
+ return Collections.emptySet();
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.ServerResource#getAsStream()
+ */
+ public InputStream getAsStream() throws IOException {
+ URL url = getURL();
+ if (url != null) {
+ URLConnection connection = url.openConnection();
+ try {
+ connection.setUseCaches(false);
+ } catch (IllegalArgumentException e) {
+ log.info("RESOURCE_NOT_CACHEABLE");
+ }
+ return connection.getInputStream();
+ } else {
+ return null;
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.ServerResource#getURL()
+ */
+ public URL getURL() {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if(null == classLoader){
+ classLoader = this.getClass().getClassLoader();
+ }
+ return classLoader.getResource(classpath);
+ }
+
+
+}
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,98 @@
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class FilterContainer implements RequestChain {
+
+ private final Filter filter;
+
+ private final RequestChain next;
+
+ private String name = "Default";
+
+ private final Map<String, String> initParameters;
+
+ /**
+ * @param filter
+ * @param next
+ */
+ public FilterContainer(Filter filter, RequestChain next) {
+ this.filter = filter;
+ this.next = next;
+ this.initParameters = new HashMap<String, String>();
+ }
+
+ public void execute(ServletRequest request, ServletResponse response)
+ throws ServletException, IOException {
+ 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){
+ initParameters.put(name, value);
+ }
+
+ public boolean isApplicable(String path) {
+ return next.isApplicable(path);
+ }
+
+ public void destroy() {
+ next.destroy();
+ filter.destroy();
+ }
+
+ public void init(final StagingServletContext context) throws ServletException {
+ filter.init(new FilterConfig(){
+
+ public String getFilterName() {
+ return name;
+ }
+
+ public String getInitParameter(String name) {
+ return initParameters.get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
+
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ });
+ next.init(context);
+ }
+
+ public String getPathInfo(String path) {
+ return next.getPathInfo(path);
+ }
+
+ public String getServletPath(String path) {
+ return next.getServletPath(path);
+ }
+
+}
Property changes on:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/FilterContainer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/NotImplementedException.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/NotImplementedException.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/NotImplementedException.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/NotImplementedException.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,46 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+/**
+ * This exception indicates feature not yet implemented in the stub server.
+ * @author asmirnov
+ *
+ */
+@SuppressWarnings("serial")
+public class NotImplementedException extends RuntimeException {
+
+ /**
+ *
+ */
+ public NotImplementedException() {
+ super("This feature not yet implemented");
+ }
+
+ /**
+ * @param message
+ */
+ public NotImplementedException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public NotImplementedException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public NotImplementedException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/RequestChain.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/RequestChain.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/RequestChain.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,24 @@
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public interface RequestChain {
+
+ public abstract boolean isApplicable(String path);
+
+ public abstract void execute(ServletRequest request,
+ ServletResponse response) throws ServletException, IOException;
+
+ public abstract void destroy();
+
+ public abstract void init(StagingServletContext context) throws ServletException;
+
+ public abstract String getPathInfo(String path);
+
+ public abstract String getServletPath(String path);
+
+}
\ No newline at end of file
Property changes on:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/RequestChain.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServerResource.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,50 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Set;
-
-/**
- * @author asmirnov
- *
- */
-public interface ServerResource {
-
-
- /**
- * Get URL for a test server resource content. Directories should return null or
"stub"
- * @return
- */
- public URL getURL();
-
- /**
- * Create input stream to read content. Directories returns {@code null}
- * @return
- * @throws IOException
- */
- public InputStream getAsStream() throws IOException;
-
- /**
- * @return strings representing directory content. File-like resources return null.
- */
- public Set<String> getPaths();
-
- /**
- * Append resource to the current directory-like structure.
- * @param path
- * @param resource
- */
- public void addResource(ServerResourcePath path, ServerResource resource);
-
- /**
- * Get resource from the current directory or its subdirectories.
- * @param path
- * @return
- */
- public ServerResource getResource(ServerResourcePath path);
-
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServerResource.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResource.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,50 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Set;
+
+/**
+ * @author asmirnov
+ *
+ */
+public interface ServerResource {
+
+
+ /**
+ * Get URL for a test server resource content. Directories should return null or
"stub"
+ * @return
+ */
+ public URL getURL();
+
+ /**
+ * Create input stream to read content. Directories returns {@code null}
+ * @return
+ * @throws IOException
+ */
+ public InputStream getAsStream() throws IOException;
+
+ /**
+ * @return strings representing directory content. File-like resources return null.
+ */
+ public Set<String> getPaths();
+
+ /**
+ * Append resource to the current directory-like structure.
+ * @param path
+ * @param resource
+ */
+ public void addResource(ServerResourcePath path, ServerResource resource);
+
+ /**
+ * Get resource from the current directory or its subdirectories.
+ * @param path
+ * @return
+ */
+ public ServerResource getResource(ServerResourcePath path);
+
+}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServerResourcePath.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,100 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.util.regex.Pattern;
-
-import javax.servlet.ServletContext;
-
-/**
- * Class to represent web server resources directory path.
- * @author asmirnov
- *
- */
-public class ServerResourcePath {
-
- private static final Pattern SLASH = Pattern.compile("/");
-
- public static final ServerResourcePath WEB_INF=new
ServerResourcePath("/WEB-INF");
-
- public static final ServerResourcePath META_INF=new
ServerResourcePath("/META-INF");
- public static final ServerResourcePath WEB_XML=new
ServerResourcePath("/WEB-INF/web.xml");
- public static final ServerResourcePath FACES_CONFIG=new
ServerResourcePath("/WEB-INF/faces-config.xml");
-
-
- private final String[] pathElements;
-
- /**
- * Private constructor for next sub - path.
- * @param pathElements
- */
- private ServerResourcePath(String[] pathElements) {
- this.pathElements = pathElements;
- }
-
- /**
- * Create path from string representation. Path have to started with training slash, as
required for
- * {@link ServletContext#getResource(String)}
- * @param path
- */
- public ServerResourcePath(String path) {
- if (null == path) {
- throw new NullPointerException();
- }
- if (!path.startsWith("/")) {
- throw new IllegalArgumentException();
- }
- pathElements = SLASH.split(path);
- }
-
- /**
- * Method to detect last element in the path.
- * @return true for a last element in the path.
- */
- public boolean isFile() {
- return pathElements.length <= 1;
- }
-
- /**
- * Name of the next element ( directory or file ) name.
- * For the "/foo/bar/baz" it should be "foo" , /bar/baz :
"bar" , "/" : null.
- * @return name of the next element or null if it is last element in the chain ( file
).
- */
- public String getNextElementName() {
- if (pathElements.length > 1) {
- return pathElements[1];
- } else {
- return null;
- }
- }
-
- /**
- * Create next path of the path chain.
- * Path /foo/bar/baz should be converted to /bar/baz , /bar/baz -> /baz -> / (
empty path )
- * @return next subdirectory path or null.
- */
- public ServerResourcePath getNextPath() {
- if (pathElements.length > 1) {
- String[] nextElenemts = new String[pathElements.length - 1];
- System.arraycopy(pathElements, 1, nextElenemts, 0, nextElenemts.length);
- return new ServerResourcePath(nextElenemts);
- } else {
- return null;
- }
- }
-
- @Override
- public String toString() {
- StringBuilder str = new StringBuilder();
- if (pathElements.length > 1) {
- for (int i = 1; i < pathElements.length; i++) {
- String element = pathElements[i];
- str.append("/").append(element);
- }
- } else {
- str.append("/");
- }
- return str.toString();
- }
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServerResourcePath.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcePath.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,100 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.util.regex.Pattern;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Class to represent web server resources directory path.
+ * @author asmirnov
+ *
+ */
+public class ServerResourcePath {
+
+ private static final Pattern SLASH = Pattern.compile("/");
+
+ public static final ServerResourcePath WEB_INF=new
ServerResourcePath("/WEB-INF");
+
+ public static final ServerResourcePath META_INF=new
ServerResourcePath("/META-INF");
+ public static final ServerResourcePath WEB_XML=new
ServerResourcePath("/WEB-INF/web.xml");
+ public static final ServerResourcePath FACES_CONFIG=new
ServerResourcePath("/WEB-INF/faces-config.xml");
+
+
+ private final String[] pathElements;
+
+ /**
+ * Private constructor for next sub - path.
+ * @param pathElements
+ */
+ private ServerResourcePath(String[] pathElements) {
+ this.pathElements = pathElements;
+ }
+
+ /**
+ * Create path from string representation. Path have to started with training slash, as
required for
+ * {@link ServletContext#getResource(String)}
+ * @param path
+ */
+ public ServerResourcePath(String path) {
+ if (null == path) {
+ throw new NullPointerException();
+ }
+ if (!path.startsWith("/")) {
+ throw new IllegalArgumentException();
+ }
+ pathElements = SLASH.split(path);
+ }
+
+ /**
+ * Method to detect last element in the path.
+ * @return true for a last element in the path.
+ */
+ public boolean isFile() {
+ return pathElements.length <= 1;
+ }
+
+ /**
+ * Name of the next element ( directory or file ) name.
+ * For the "/foo/bar/baz" it should be "foo" , /bar/baz :
"bar" , "/" : null.
+ * @return name of the next element or null if it is last element in the chain ( file
).
+ */
+ public String getNextElementName() {
+ if (pathElements.length > 1) {
+ return pathElements[1];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Create next path of the path chain.
+ * Path /foo/bar/baz should be converted to /bar/baz , /bar/baz -> /baz -> / (
empty path )
+ * @return next subdirectory path or null.
+ */
+ public ServerResourcePath getNextPath() {
+ if (pathElements.length > 1) {
+ String[] nextElenemts = new String[pathElements.length - 1];
+ System.arraycopy(pathElements, 1, nextElenemts, 0, nextElenemts.length);
+ return new ServerResourcePath(nextElenemts);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder str = new StringBuilder();
+ if (pathElements.length > 1) {
+ for (int i = 1; i < pathElements.length; i++) {
+ String element = pathElements[i];
+ str.append("/").append(element);
+ }
+ } else {
+ str.append("/");
+ }
+ return str.toString();
+ }
+}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServerResourcesDirectory.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,86 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author asmirnov
- *
- */
-public class ServerResourcesDirectory implements ServerResource {
-
-
-
- private final Map<String,ServerResource> children = new
HashMap<String,ServerResource>();
-
- /* (non-Javadoc)
- * @see
org.richfaces.test.stub.ServerResource#addResource(org.richfaces.test.stub.ServerResource)
- */
- public void addResource(ServerResourcePath path,ServerResource resource) {
-
- if(null == path || path.isFile()){
- throw new IllegalArgumentException();
- } else if(path.getNextPath().isFile()) {
- children.put(path.getNextElementName(), resource);
- } else {
- ServerResource nextDirectory = children.get(path.getNextElementName());
- if(null == nextDirectory){
- nextDirectory = new ServerResourcesDirectory();
- children.put(path.getNextElementName(), nextDirectory);
- }
- nextDirectory.addResource(path.getNextPath(), resource);
- }
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.test.stub.ServerResource#getResource(org.richfaces.test.stub.ServerResourcePath)
- */
- public ServerResource getResource(ServerResourcePath path) {
- if(null == path){
- throw new NullPointerException();
- }
- ServerResource resource = null; //children.get(path.getName());
- if(path.isFile()){
- resource=this;
- } else {
- resource = children.get(path.getNextElementName());
- if(!path.getNextPath().isFile() && null!=resource){
- resource = resource.getResource(path.getNextPath());
- }
- }
- return resource;
- }
- /* (non-Javadoc)
- * @see org.richfaces.test.stub.ServerResource#getAsStream()
- */
- public InputStream getAsStream() {
- // can't read directory.
- return null;
- }
-
-
- /* (non-Javadoc)
- * @see org.richfaces.test.stub.ServerResource#getPaths()
- */
- public Set<String> getPaths() {
- return children.keySet();
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.test.stub.ServerResource#getURL()
- */
- public URL getURL() {
- // Directory don't have url.
- return null;
- }
-
-
-
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServerResourcesDirectory.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,86 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ServerResourcesDirectory implements ServerResource {
+
+
+
+ private final Map<String,ServerResource> children = new
HashMap<String,ServerResource>();
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.test.staging.ServerResource#addResource(org.richfaces.test.staging.ServerResource)
+ */
+ public void addResource(ServerResourcePath path,ServerResource resource) {
+
+ if(null == path || path.isFile()){
+ throw new IllegalArgumentException();
+ } else if(path.getNextPath().isFile()) {
+ children.put(path.getNextElementName(), resource);
+ } else {
+ ServerResource nextDirectory = children.get(path.getNextElementName());
+ if(null == nextDirectory){
+ nextDirectory = new ServerResourcesDirectory();
+ children.put(path.getNextElementName(), nextDirectory);
+ }
+ nextDirectory.addResource(path.getNextPath(), resource);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.test.staging.ServerResource#getResource(org.richfaces.test.staging.ServerResourcePath)
+ */
+ public ServerResource getResource(ServerResourcePath path) {
+ if(null == path){
+ throw new NullPointerException();
+ }
+ ServerResource resource = null; //children.get(path.getName());
+ if(path.isFile()){
+ resource=this;
+ } else {
+ resource = children.get(path.getNextElementName());
+ if(!path.getNextPath().isFile() && null!=resource){
+ resource = resource.getResource(path.getNextPath());
+ }
+ }
+ return resource;
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.ServerResource#getAsStream()
+ */
+ public InputStream getAsStream() {
+ // can't read directory.
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.ServerResource#getPaths()
+ */
+ public Set<String> getPaths() {
+ return children.keySet();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.ServerResource#getURL()
+ */
+ public URL getURL() {
+ // Directory don't have url.
+ return null;
+ }
+
+
+
+}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServletContainer.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,97 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Map;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-
-/**
- * @author asmirnov
- *
- */
-public class ServletContainer {
-
- private final Servlet servlet;
-
- private final boolean prefixMapped;
-
- private final String mapping;
-
- private final Map<String, String> initParameters;
-
- /**
- * @param mapping
- * @param servlet
- */
- public ServletContainer(String mapping, Servlet servlet, Map<String, String>
initParameters) {
- if(null == mapping){
- this.prefixMapped = true;
- this.mapping = "";
- } else if (mapping.startsWith("*")) {
- this.prefixMapped = false;
- this.mapping = mapping.substring(1);
- } else if (mapping.endsWith("*")) {
- this.prefixMapped = true;
- this.mapping = mapping.substring(0,mapping.length()-1);
- } else {
- throw new IllegalArgumentException("Invalid mapping "+mapping);
- }
- this.servlet = servlet;
- this.initParameters = initParameters;
- }
-
- public ServletContainer(String mapping, Servlet servlet) {
- this(mapping, servlet, Collections.<String, String>emptyMap());
- }
-
- public boolean isApplicable(String path) {
- if(prefixMapped && path.startsWith(mapping)){
- return true;
- } else if(!prefixMapped && path.endsWith(mapping)){
- return true;
- } else {
- return false;
- }
- }
-
- public String getServletPath(String path){
- if (!isApplicable(path)) {
- return null;
- }
- if(prefixMapped){
- return mapping;
- } else {
- return path;
- }
- }
-
- public String getPathInfo(String path) {
- if (!isApplicable(path)) {
- return null;
- }
- if(prefixMapped){
- return path.substring(mapping.length());
- } else {
- return null;
- }
-
- }
-
- public void init(StubServletContext context) throws ServletException {
- StubServletConfig config = new StubServletConfig(context, this.initParameters);
- servlet.init(config);
- }
-
- public void execute(ServletRequest request, ServletResponse response) throws
ServletException, IOException {
- this.servlet.service(request, response);
-
- }
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/ServletContainer.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServletContainer.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,150 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+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";
+
+ /**
+ * @param mapping
+ * @param servlet
+ */
+ public ServletContainer(String mapping, Servlet servlet) {
+ if(null == mapping){
+ this.prefixMapped = true;
+ this.mapping = "";
+ } else if (mapping.startsWith("*")) {
+ this.prefixMapped = false;
+ this.mapping = mapping.substring(1);
+ } else if (mapping.endsWith("*")) {
+ this.prefixMapped = true;
+ this.mapping = mapping.substring(0,mapping.length()-1);
+ } else {
+ throw new IllegalArgumentException("Invalid mapping "+mapping);
+ }
+ this.servlet = servlet;
+ this.initParameters = new HashMap<String, String>();
+ }
+
+
+ public void addInitParameter(String name, String value){
+ initParameters.put(name, value);
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @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)
+ */
+ public boolean isApplicable(String path) {
+ if(prefixMapped && path.startsWith(mapping)){
+ return true;
+ } else if(!prefixMapped && path.endsWith(mapping)){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public String getServletPath(String path){
+ if (!isApplicable(path)) {
+ return null;
+ }
+ if(prefixMapped){
+ return mapping;
+ } else {
+ return path;
+ }
+ }
+
+ public String getPathInfo(String path) {
+ if (!isApplicable(path)) {
+ return null;
+ }
+ 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);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
+
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ public String getServletName() {
+ return name;
+ }
+
+ });
+ }
+
+ /* (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 {
+ this.servlet.service(request, response);
+
+ }
+
+ public void destroy() {
+ this.servlet.destroy();
+ }
+}
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,495 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.richfaces.collections.collect.ImmutableCollection;
+import org.richfaces.collections.collect.ImmutableList;
+import org.richfaces.collections.collect.Multimap;
+import org.richfaces.collections.collect.Multimaps;
+import org.richfaces.test.ServerLogger;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class StagingHttpRequest implements HttpServletRequest {
+
+ private static final Logger log = ServerLogger.CONNECTION.getLogger();
+
+ public static final String LOCALHOST = "localhost";
+ public static final String HTTP = "http";
+ public static final String LOCALHOST_IP = "127.0.0.1";
+ public static final String UTF8 = "UTF-8";
+
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getAuthType()
+ */
+ public String getAuthType() {
+ // TODO configure test auth.
+ log.info("unimplemented request method getAuthType");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getContextPath()
+ */
+ public String getContextPath() {
+ return StagingServletContext.CONTEXT_PATH;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
+ */
+ public long getDateHeader(String name) {
+ // TODO create headers support
+ log.info("unimplemented request method getDateHeader");
+ return -1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
+ */
+ public String getHeader(String name) {
+ // TODO create headers support
+ log.info("unimplemented request method getHeader");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getHeaderNames() {
+ // TODO create headers support
+ log.info("unimplemented request method getHeaderNames");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getHeaders(String name) {
+ // TODO create headers support
+ log.info("unimplemented request method getHeaders");
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
+ */
+ public int getIntHeader(String name) {
+ // TODO create headers support
+ log.info("unimplemented request method getIntHeader");
+ return -1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
+ */
+ public String getPathTranslated() {
+ // we have only 'virtual' server.
+ return null;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
+ */
+ public String getRemoteUser() {
+ // TODO configure test auth.
+ log.info("unimplemented request method getRemoteUser");
+ return null;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getRequestURL()
+ */
+ public StringBuffer getRequestURL() {
+ StringBuffer requestURL = new StringBuffer(HTTP + "://" + LOCALHOST
+ + getRequestURI());
+ return requestURL;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
+ */
+ public String getRequestedSessionId() {
+ return StagingHttpSession.SESSION_ID;
+ }
+
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
+ */
+ public Principal getUserPrincipal() {
+ // TODO implement test auth.
+ log.info("unimplemented request method getUserPrincipal");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
+ */
+ public boolean isRequestedSessionIdFromCookie() {
+ // test do not supports cookie
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
+ */
+ public boolean isRequestedSessionIdFromURL() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
+ */
+ public boolean isRequestedSessionIdFromUrl() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
+ */
+ public boolean isRequestedSessionIdValid() {
+ // TODO - check session.
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
+ */
+ public boolean isUserInRole(String role) {
+ // TODO implement test auth.
+ log.info("unimplemented request method isUserInRole");
+ return false;
+ }
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getAttributeNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getAttributeNames() {
+ return Collections.enumeration(attributes.keySet());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+ return UTF8;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getContentLength()
+ */
+ public int getContentLength() {
+ return -1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getContentType()
+ */
+ public String getContentType() {
+ log.info("unimplemented request method getContentType");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getInputStream()
+ */
+ public ServletInputStream getInputStream() throws IOException {
+ // TODO implement post stream.
+ log.info("unimplemented request method getInputStream");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getLocalAddr()
+ */
+ public String getLocalAddr() {
+ return LOCALHOST_IP;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getLocalName()
+ */
+ public String getLocalName() {
+ return LOCALHOST;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getLocalPort()
+ */
+ public int getLocalPort() {
+ return 80;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getLocale()
+ */
+ public Locale getLocale() {
+ return Locale.US;
+ }
+
+ private final ImmutableCollection<Locale> locales = ImmutableList.of(
+ Locale.US, Locale.GERMANY);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getLocales()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getLocales() {
+ return Collections.enumeration(locales);
+ }
+
+ private String characterEncoding;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getProtocol()
+ */
+ public String getProtocol() {
+ return "HTTP/1.1";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getReader()
+ */
+ public BufferedReader getReader() throws IOException {
+ // TODO implements request buffer.
+ log.info("unimplemented request method getReader");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
+ */
+ public String getRealPath(String path) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getRemoteAddr()
+ */
+ public String getRemoteAddr() {
+ return LOCALHOST_IP;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getRemoteHost()
+ */
+ public String getRemoteHost() {
+ return LOCALHOST;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getRemotePort()
+ */
+ public int getRemotePort() {
+ return 1223340;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
+ */
+ public RequestDispatcher getRequestDispatcher(String path) {
+ // TODO Auto-generated method stub
+ throw new NotImplementedException();
+ // return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getScheme()
+ */
+ public String getScheme() {
+ return HTTP;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getServerName()
+ */
+ public String getServerName() {
+ return LOCALHOST;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#getServerPort()
+ */
+ public int getServerPort() {
+ return 80;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#isSecure()
+ */
+ public boolean isSecure() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ // TODO - inform listeners
+ Object removed = attributes.remove(name);
+ if(null != removed){
+ attributeRemoved(name,removed);
+ }
+ }
+
+ protected abstract void attributeRemoved(String name, Object removed);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
+ * java.lang.Object)
+ */
+ public void setAttribute(String name, Object o) {
+ if(null == o){
+ removeAttribute(name);
+ } else {
+ Object oldValue = attributes.put(name, o);
+ if(null != oldValue){
+ attributeReplaced(name,o);
+ } else {
+ attributeAdded(name,o);
+ }
+ }
+
+ }
+
+ protected abstract void attributeAdded(String name, Object o);
+
+ protected abstract void attributeReplaced(String name, Object o);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
+ */
+ public void setCharacterEncoding(String env)
+ throws UnsupportedEncodingException {
+ this.characterEncoding=env;
+
+ }
+
+}
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,436 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.richfaces.test.ServerLogger;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class StagingHttpResponse implements HttpServletResponse {
+
+
+ private static final Logger log = ServerLogger.CONNECTION.getLogger();
+
+
+ private int status = 200;
+
+ private String redirectLocation = null;
+
+ private String errorMessage = null;
+
+ private int bufferSize = 8196;
+
+ private StringWriter outputWriter;
+
+ private ByteArrayOutputStream outputStream;
+
+ private PrintWriter printWriter;
+
+ private ServletOutputStream servletOutputStream;
+
+ private Locale locale = Locale.US;
+
+ private String contentType="text";
+
+ private String encoding = StagingHttpRequest.UTF8;
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#addDateHeader(java.lang.String,
+ * long)
+ */
+ public void addDateHeader(String name, long date) {
+ log.info("unimplemented response method addDateHeader");
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String,
+ * java.lang.String)
+ */
+ public void addHeader(String name, String value) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method addHeader");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#addIntHeader(java.lang.String,
+ * int)
+ */
+ public void addIntHeader(String name, int value) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method addIntHeader");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String)
+ */
+ public boolean containsHeader(String name) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method containsHeader");
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#encodeRedirectURL(java.lang.String
+ * )
+ */
+ public String encodeRedirectURL(String url) {
+ return url;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#encodeRedirectUrl(java.lang.String
+ * )
+ */
+ public String encodeRedirectUrl(String url) {
+ return encodeRedirectURL(url);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String)
+ */
+ public String encodeURL(String url) {
+ return url;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#encodeUrl(java.lang.String)
+ */
+ public String encodeUrl(String url) {
+ return encodeURL(url);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#sendError(int)
+ */
+ public void sendError(int sc) throws IOException {
+ status = sc;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#sendError(int,
+ * java.lang.String)
+ */
+ public void sendError(int sc, String msg) throws IOException {
+ status = sc;
+ errorMessage = msg;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String)
+ */
+ public void sendRedirect(String location) throws IOException {
+ redirectLocation = location;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String,
+ * long)
+ */
+ public void setDateHeader(String name, long date) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method setDateHeader");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String,
+ * java.lang.String)
+ */
+ public void setHeader(String name, String value) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method setHeader");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.servlet.http.HttpServletResponse#setIntHeader(java.lang.String,
+ * int)
+ */
+ public void setIntHeader(String name, int value) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method setIntHeader");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#setStatus(int)
+ */
+ public void setStatus(int sc) {
+ status = sc;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServletResponse#setStatus(int,
+ * java.lang.String)
+ */
+ public void setStatus(int sc, String sm) {
+ status = sc;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#flushBuffer()
+ */
+ public void flushBuffer() throws IOException {
+ // do nothing
+ log.info("unimplemented response method flushBuffer");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#getBufferSize()
+ */
+ public int getBufferSize() {
+ return bufferSize;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+ return encoding;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#getContentType()
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#getLocale()
+ */
+ public Locale getLocale() {
+ return locale;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#getOutputStream()
+ */
+ public ServletOutputStream getOutputStream() throws IOException {
+ if (null != this.outputWriter) {
+ throw new IllegalStateException();
+ }
+ if (this.outputStream == null) {
+ this.outputStream = new ByteArrayOutputStream(getBufferSize());
+ servletOutputStream = new ServletOutputStream(){
+
+ @Override
+ public void write(int b) throws IOException {
+ StagingHttpResponse.this.outputStream.write(b);
+ }
+
+ };
+ }
+ return servletOutputStream;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#getWriter()
+ */
+ public PrintWriter getWriter() throws IOException {
+ if (null != this.outputStream) {
+ throw new IllegalStateException();
+ }
+ if (this.outputWriter == null) {
+ this.outputWriter = new StringWriter(getBufferSize());
+ printWriter = new PrintWriter(outputWriter);
+ }
+ return printWriter;
+ }
+
+
+ public String getWriterContent() {
+ if(null != this.outputWriter){
+ return this.outputWriter.toString();
+ }
+ return null;
+ }
+
+ public byte[] getStreamContent() {
+ if(null!=outputStream){
+ return outputStream.toByteArray();
+ }
+ return null;
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#isCommitted()
+ */
+ public boolean isCommitted() {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method isCommited");
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#reset()
+ */
+ public void reset() {
+ if(isCommitted()){
+ throw new IllegalStateException();
+ }
+ resetBuffer();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#resetBuffer()
+ */
+ public void resetBuffer() {
+ if(isCommitted()){
+ throw new IllegalStateException();
+ }
+ this.servletOutputStream = null;
+ this.outputStream = null;
+ this.printWriter = null;
+ this.outputWriter = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#setBufferSize(int)
+ */
+ public void setBufferSize(int size) {
+ this.bufferSize = size;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String)
+ */
+ public void setCharacterEncoding(String charset) {
+ encoding = charset;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#setContentLength(int)
+ */
+ public void setContentLength(int len) {
+ // TODO Auto-generated method stub
+ log.info("unimplemented response method setContentLenght");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#setContentType(java.lang.String)
+ */
+ public void setContentType(String type) {
+ contentType = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.ServletResponse#setLocale(java.util.Locale)
+ */
+ public void setLocale(Locale loc) {
+ this.locale = loc;
+
+ }
+
+ /**
+ * @return the status
+ */
+ public int getStatus() {
+ return status;
+ }
+
+ /**
+ * @return the redirectLocation
+ */
+ public String getRedirectLocation() {
+ return redirectLocation;
+ }
+
+ /**
+ * @return the errorMessage
+ */
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+}
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,281 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class StagingHttpSession implements HttpSession {
+
+ private static final int DEFAULT_INACTIVE_TIME = 30;
+
+ public static final String SESSION_ID = "1234567890";
+
+ private final Map<String, Object> attributes = new HashMap<String,
Object>();
+
+ private final long creationTime;
+
+ private int inactiveTime = DEFAULT_INACTIVE_TIME;
+
+ private boolean valid;
+
+ public StagingHttpSession() {
+ this.creationTime = System.currentTimeMillis();
+ this.valid = true;
+ }
+
+ /**
+ *
+ */
+ public void destroy() {
+ // Destroy all session attributes.
+ unboundAttributes();
+ }
+
+ private void unboundAttributes() {
+ for (String name : getValueNames()) {
+ removeAttribute(name);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ checkValid();
+ return attributes.get(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getAttributeNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getAttributeNames() {
+ checkValid();
+ return Collections.enumeration(attributes.keySet());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getCreationTime()
+ */
+ public long getCreationTime() {
+ checkValid();
+ return creationTime;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getId()
+ */
+ public String getId() {
+ return SESSION_ID;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getLastAccessedTime()
+ */
+ public long getLastAccessedTime() {
+ checkValid();
+ // TODO fix accessing time
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
+ */
+ public int getMaxInactiveInterval() {
+ return inactiveTime;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getSessionContext()
+ */
+ @SuppressWarnings("deprecation")
+ public HttpSessionContext getSessionContext() {
+ throw new NotImplementedException("Session context is not implemented");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
+ */
+ public Object getValue(String name) {
+ return getAttribute(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#getValueNames()
+ */
+ public String[] getValueNames() {
+ checkValid();
+ ArrayList<String> names = new ArrayList<String>(attributes.keySet());
+ return names.toArray(new String[names.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#invalidate()
+ */
+ public void invalidate() {
+ checkValid();
+ unboundAttributes();
+ this.valid=false;
+
+ }
+
+ protected void checkValid(){
+ if(!valid){
+ throw new IllegalStateException("Session have been invalidated");
+ }
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#isNew()
+ */
+ public boolean isNew() {
+ checkValid();
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#putValue(java.lang.String,
+ * java.lang.Object)
+ */
+ public void putValue(String name, Object value) {
+ setAttribute(name, value);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ checkValid();
+ Object removed = this.attributes.remove(name);
+ if (null != removed) {
+ removedFromSession(name, removed);
+ }
+
+ }
+
+ protected void removedFromSession(String name, Object removed) {
+ HttpSessionBindingEvent sessionBindingEvent = new HttpSessionBindingEvent(
+ this, name, removed);
+ if (removed instanceof HttpSessionBindingListener) {
+ HttpSessionBindingListener listener = (HttpSessionBindingListener) removed;
+ listener.valueUnbound(sessionBindingEvent);
+ }
+ valueUnbound(sessionBindingEvent);
+ }
+
+ protected abstract void valueUnbound(
+ HttpSessionBindingEvent sessionBindingEvent);
+
+ protected void boundToSession(String name, Object value) {
+ HttpSessionBindingEvent sessionBindingEvent = new HttpSessionBindingEvent(
+ this, name, value);
+ if (value instanceof HttpSessionBindingListener) {
+ HttpSessionBindingListener listener = (HttpSessionBindingListener) value;
+ listener.valueBound(sessionBindingEvent);
+ }
+ valueBound(sessionBindingEvent);
+ }
+
+ protected abstract void valueBound(
+ HttpSessionBindingEvent sessionBindingEvent);
+
+ protected void replacedInSession(String name, Object oldValue, Object value) {
+ HttpSessionBindingEvent sessionBindingEvent = new HttpSessionBindingEvent(
+ this, name, value);
+ if (oldValue instanceof HttpSessionBindingListener) {
+ HttpSessionBindingListener listener = (HttpSessionBindingListener) oldValue;
+ listener.valueUnbound(sessionBindingEvent);
+ }
+ if (value instanceof HttpSessionBindingListener) {
+ HttpSessionBindingListener listener = (HttpSessionBindingListener) value;
+ listener.valueBound(sessionBindingEvent);
+ }
+ valueReplaced(sessionBindingEvent);
+ }
+
+ protected abstract void valueReplaced(
+ HttpSessionBindingEvent sessionBindingEvent);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
+ */
+ public void removeValue(String name) {
+ removeAttribute(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String,
+ * java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ checkValid();
+ if (null == value) {
+ removeAttribute(name);
+ } else {
+ Object oldValue = attributes.put(name, value);
+ if (null != oldValue) {
+ replacedInSession(name, oldValue, value);
+ } else {
+ boundToSession(name, value);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
+ */
+ public void setMaxInactiveInterval(int interval) {
+ this.inactiveTime = interval;
+
+ }
+
+}
Added:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,297 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletException;
+
+import org.richfaces.test.ServerLogger;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class StagingServletContext implements ServletContext {
+
+ private static final Logger log = ServerLogger.SERVER.getLogger();
+
+ public static final String CONTEXT_PATH = "";
+
+ private static final String APPLICATION_NAME = "stub";
+ private final Map<String, Object> attributes = new HashMap<String,
Object>();
+ private Map<String,String> initParameters = new HashMap<String, String>();
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getAttributeNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getAttributeNames() {
+ return Collections.enumeration(attributes.keySet());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getContext(java.lang.String)
+ */
+ public ServletContext getContext(String uripath) {
+ // stub server has only one context.
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getContextPath()
+ */
+ public String getContextPath() {
+ // Test always run in the root context.
+ return CONTEXT_PATH;
+ }
+
+ public void addInitParameters(Map<String,String>parameters) {
+ initParameters.putAll(parameters);
+ }
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String name) {
+ return initParameters.get(name);
+ }
+
+
+ /**
+ * Put new init parameter to the Map.
+ * @param name
+ * @param value
+ */
+ public void setInitParameter(String name, String value) {
+ initParameters.put(name, value);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getInitParameterNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getInitParameterNames() {
+ return Collections.enumeration(initParameters.keySet());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getMajorVersion()
+ */
+ public int getMajorVersion() {
+ return 2;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
+ */
+ public String getMimeType(String file) {
+ // TODO create mime-types table.
+ log.info("unimplemented servlet context method getMimeType");
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getMinorVersion()
+ */
+ public int getMinorVersion() {
+ return 5;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
+ */
+ public RequestDispatcher getNamedDispatcher(String name) {
+ // TODO create stub dispatcher.
+ log.info("unimplemented response method getNamedDispatcher");
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
+ */
+ public String getRealPath(String path) {
+ // we always use 'virtual' configuration.
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
+ */
+ public RequestDispatcher getRequestDispatcher(String path) {
+ // TODO implement stub dispatcher.
+ log.info("unimplemented response method getRequestDispatcher");
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getResource(java.lang.String)
+ */
+ public URL getResource(String path) throws MalformedURLException {
+ URL url = null;
+ ServerResource resource = getServerResource(path);
+ if(null != resource){
+ url = resource.getURL();
+ }
+ return url;
+ }
+
+ /**
+ * @param path
+ * @return
+ */
+ protected abstract ServerResource getServerResource(String path);
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
+ */
+ public InputStream getResourceAsStream(String path) {
+ ServerResource resource = getServerResource(path);
+ if(null != resource){
+ try {
+ return resource.getAsStream();
+ } catch (IOException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ public Set getResourcePaths(String path) {
+ ServerResource resource = getServerResource(path);
+ if(null != resource){
+ return resource.getPaths();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getServerInfo()
+ */
+ public String getServerInfo() {
+ return "Stub test server";
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getServlet(java.lang.String)
+ */
+ public Servlet getServlet(String name) throws ServletException {
+ // always return null.
+ log.info("unimplemented response method getServlet");
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getServletContextName()
+ */
+ public String getServletContextName() {
+ // Stub server has no declared name.
+ return APPLICATION_NAME;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getServletNames()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getServletNames() {
+ log.info("unimplemented response method getServletNames");
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#getServlets()
+ */
+ @SuppressWarnings("unchecked")
+ public Enumeration getServlets() {
+ log.info("unimplemented response method getServlets");
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#log(java.lang.String)
+ */
+ public void log(String msg) {
+ log.finest(msg);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String)
+ */
+ public void log(Exception exception, String msg) {
+ log.log(Level.FINEST, msg, exception);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#log(java.lang.String, java.lang.Throwable)
+ */
+ public void log(String message, Throwable throwable) {
+ log.log(Level.FINEST, message, throwable);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ // TODO - inform listeners
+ Object removed = attributes.remove(name);
+ if(null != removed){
+ valueUnbound(new ServletContextAttributeEvent(this,name,removed));
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String name, Object object) {
+ // TODO - inform listeners
+ if (null == object) {
+ removeAttribute(name);
+ } else {
+ Object oldValue = attributes.put(name, object);
+ ServletContextAttributeEvent event = new
ServletContextAttributeEvent(this,name,object);
+ if(null != oldValue){
+ valueReplaced(event);
+ } else {
+ valueBound(event);
+ }
+ }
+ }
+
+ protected abstract void valueBound(ServletContextAttributeEvent event);
+
+ protected abstract void valueReplaced(ServletContextAttributeEvent event);
+
+ protected abstract void valueUnbound(
+ ServletContextAttributeEvent servletContextAttributeEvent);
+
+}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StaticServlet.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,44 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author asmirnov
- *
- */
-@SuppressWarnings("serial")
-public class StaticServlet extends HttpServlet {
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- InputStream inputStream =
getServletContext().getResourceAsStream(req.getServletPath());
- if(null != inputStream){
- ServletOutputStream outputStream = resp.getOutputStream();
- int c;
- while((c = inputStream.read())>0){
- outputStream.write(c);
- }
- inputStream.close();
- outputStream.close();
- } else {
- resp.sendError(404, "not found");
- }
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doGet(req, resp);
- }
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
(from rev 11094,
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StaticServlet.java)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,44 @@
+/**
+ *
+ */
+package org.richfaces.test.staging;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author asmirnov
+ *
+ */
+@SuppressWarnings("serial")
+public class StaticServlet extends HttpServlet {
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ InputStream inputStream =
getServletContext().getResourceAsStream(req.getServletPath());
+ if(null != inputStream){
+ ServletOutputStream outputStream = resp.getOutputStream();
+ int c;
+ while((c = inputStream.read())>0){
+ outputStream.write(c);
+ }
+ inputStream.close();
+ outputStream.close();
+ } else {
+ resp.sendError(404, "not found");
+ }
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ doGet(req, resp);
+ }
+}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpRequest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StubHttpRequest.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpRequest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,483 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.Principal;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.richfaces.collections.collect.ImmutableCollection;
-import org.richfaces.collections.collect.ImmutableList;
-import org.richfaces.collections.collect.Multimap;
-import org.richfaces.collections.collect.Multimaps;
-
-/**
- * @author asmirnov
- *
- */
-public abstract class StubHttpRequest implements HttpServletRequest {
-
- public static final String LOCALHOST = "localhost";
- public static final String HTTP = "http";
- public static final String LOCALHOST_IP = "127.0.0.1";
- public static final String UTF8 = "UTF-8";
-
-
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getAuthType()
- */
- public String getAuthType() {
- // TODO configure test auth.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getContextPath()
- */
- public String getContextPath() {
- return StubServletContext.CONTEXT_PATH;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
- */
- public long getDateHeader(String name) {
- // TODO create headers support
- return -1;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
- */
- public String getHeader(String name) {
- // TODO create headers support
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getHeaderNames() {
- // TODO create headers support
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
- */
- @SuppressWarnings("unchecked")
- public Enumeration getHeaders(String name) {
- // TODO create headers support
- return Collections.enumeration(Collections.EMPTY_LIST);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
- */
- public int getIntHeader(String name) {
- // TODO create headers support
- return -1;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
- */
- public String getPathTranslated() {
- // we have only 'virtual' server.
- return null;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
- */
- public String getRemoteUser() {
- // TODO configure test auth.
- return null;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getRequestURL()
- */
- public StringBuffer getRequestURL() {
- StringBuffer requestURL = new StringBuffer(HTTP + "://" + LOCALHOST
- + getRequestURI());
- return requestURL;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
- */
- public String getRequestedSessionId() {
- return StubHttpSession.SESSION_ID;
- }
-
-
- private StubHttpSession session;
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getSession()
- */
- public HttpSession getSession() {
- if (session == null) {
- session = new StubHttpSession();
- }
- return session;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
- */
- public HttpSession getSession(boolean create) {
- if (session == null && create) {
- session = new StubHttpSession();
- }
- return session;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
- */
- public Principal getUserPrincipal() {
- // TODO implement test auth.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
- */
- public boolean isRequestedSessionIdFromCookie() {
- // test do not supports cookie
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
- */
- public boolean isRequestedSessionIdFromURL() {
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
- */
- public boolean isRequestedSessionIdFromUrl() {
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
- */
- public boolean isRequestedSessionIdValid() {
- return session != null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
- */
- public boolean isUserInRole(String role) {
- // TODO implement test auth.
- return false;
- }
-
- private Map<String, Object> attributes = new HashMap<String, Object>();
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
- */
- public Object getAttribute(String name) {
- return attributes.get(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getAttributeNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getAttributeNames() {
- return Collections.enumeration(attributes.keySet());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getCharacterEncoding()
- */
- public String getCharacterEncoding() {
- return UTF8;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getContentLength()
- */
- public int getContentLength() {
- return -1;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getContentType()
- */
- public String getContentType() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getInputStream()
- */
- public ServletInputStream getInputStream() throws IOException {
- // TODO implement post stream.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getLocalAddr()
- */
- public String getLocalAddr() {
- return LOCALHOST_IP;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getLocalName()
- */
- public String getLocalName() {
- return LOCALHOST;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getLocalPort()
- */
- public int getLocalPort() {
- return 80;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getLocale()
- */
- public Locale getLocale() {
- return Locale.US;
- }
-
- private final ImmutableCollection<Locale> locales = ImmutableList.of(
- Locale.US, Locale.GERMANY);
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getLocales()
- */
- public Enumeration getLocales() {
- // TODO Auto-generated method stub
- return Collections.enumeration(locales);
- }
-
- private String characterEncoding;
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getProtocol()
- */
- public String getProtocol() {
- return "HTTP/1.1";
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getReader()
- */
- public BufferedReader getReader() throws IOException {
- // TODO implements request buffer.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
- */
- public String getRealPath(String path) {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getRemoteAddr()
- */
- public String getRemoteAddr() {
- return LOCALHOST_IP;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getRemoteHost()
- */
- public String getRemoteHost() {
- return LOCALHOST;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getRemotePort()
- */
- public int getRemotePort() {
- return 1223340;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
- */
- public RequestDispatcher getRequestDispatcher(String path) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getScheme()
- */
- public String getScheme() {
- return HTTP;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getServerName()
- */
- public String getServerName() {
- return LOCALHOST;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#getServerPort()
- */
- public int getServerPort() {
- return 80;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#isSecure()
- */
- public boolean isSecure() {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
- */
- public void removeAttribute(String name) {
- attributes.remove(name);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
- * java.lang.Object)
- */
- public void setAttribute(String name, Object o) {
- attributes.put(name, o);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
- */
- public void setCharacterEncoding(String env)
- throws UnsupportedEncodingException {
- this.characterEncoding=env;
-
- }
-
-}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpResponse.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StubHttpResponse.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpResponse.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,402 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author asmirnov
- *
- */
-public abstract class StubHttpResponse implements HttpServletResponse {
-
-
- private int status = 0;
-
- private String redirectLocation = null;
-
- private String errorMessage = null;
-
- private int bufferSize = 8196;
-
- private StringWriter outputWriter;
-
- private ByteArrayOutputStream outputStream;
-
- private PrintWriter printWriter;
-
- private ServletOutputStream servletOutputStream;
-
- private Locale locale = Locale.US;
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#addDateHeader(java.lang.String,
- * long)
- */
- public void addDateHeader(String name, long date) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String,
- * java.lang.String)
- */
- public void addHeader(String name, String value) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#addIntHeader(java.lang.String,
- * int)
- */
- public void addIntHeader(String name, int value) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String)
- */
- public boolean containsHeader(String name) {
- // TODO Auto-generated method stub
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#encodeRedirectURL(java.lang.String
- * )
- */
- public String encodeRedirectURL(String url) {
- return url;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#encodeRedirectUrl(java.lang.String
- * )
- */
- public String encodeRedirectUrl(String url) {
- // TODO Auto-generated method stub
- return encodeRedirectURL(url);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String)
- */
- public String encodeURL(String url) {
- return url;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#encodeUrl(java.lang.String)
- */
- public String encodeUrl(String url) {
- return encodeURL(url);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#sendError(int)
- */
- public void sendError(int sc) throws IOException {
- status = sc;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#sendError(int,
- * java.lang.String)
- */
- public void sendError(int sc, String msg) throws IOException {
- status = sc;
- errorMessage = msg;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String)
- */
- public void sendRedirect(String location) throws IOException {
- redirectLocation = location;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String,
- * long)
- */
- public void setDateHeader(String name, long date) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String,
- * java.lang.String)
- */
- public void setHeader(String name, String value) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * javax.servlet.http.HttpServletResponse#setIntHeader(java.lang.String,
- * int)
- */
- public void setIntHeader(String name, int value) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#setStatus(int)
- */
- public void setStatus(int sc) {
- status = sc;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.http.HttpServletResponse#setStatus(int,
- * java.lang.String)
- */
- public void setStatus(int sc, String sm) {
- status = sc;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#flushBuffer()
- */
- public void flushBuffer() throws IOException {
- // do nothing
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#getBufferSize()
- */
- public int getBufferSize() {
- return bufferSize;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#getCharacterEncoding()
- */
- public String getCharacterEncoding() {
- return StubHttpRequest.UTF8;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#getContentType()
- */
- public String getContentType() {
- return "text/html;charset=UTF-8";
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#getLocale()
- */
- public Locale getLocale() {
- return locale;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#getOutputStream()
- */
- public ServletOutputStream getOutputStream() throws IOException {
- if (null != this.outputWriter) {
- throw new IllegalStateException();
- }
- if (this.outputStream == null) {
- this.outputStream = new ByteArrayOutputStream(getBufferSize());
- servletOutputStream = new ServletOutputStream(){
-
- @Override
- public void write(int b) throws IOException {
- StubHttpResponse.this.outputStream.write(b);
- }
-
- };
- }
- return servletOutputStream;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#getWriter()
- */
- public PrintWriter getWriter() throws IOException {
- if (null != this.outputStream) {
- throw new IllegalStateException();
- }
- if (this.outputWriter == null) {
- this.outputWriter = new StringWriter(getBufferSize());
- printWriter = new PrintWriter(outputWriter);
- }
- return printWriter;
- }
-
-
- public String getWriterContent() {
- if(null != this.outputWriter){
- return this.outputWriter.toString();
- }
- return null;
- }
-
- public byte[] getStreamContent() {
- if(null!=outputStream){
- return outputStream.toByteArray();
- }
- return null;
- }
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#isCommitted()
- */
- public boolean isCommitted() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#reset()
- */
- public void reset() {
- if(isCommitted()){
- throw new IllegalStateException();
- }
- resetBuffer();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#resetBuffer()
- */
- public void resetBuffer() {
- if(isCommitted()){
- throw new IllegalStateException();
- }
- this.servletOutputStream = null;
- this.outputStream = null;
- this.printWriter = null;
- this.outputWriter = null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#setBufferSize(int)
- */
- public void setBufferSize(int size) {
- this.bufferSize = size;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String)
- */
- public void setCharacterEncoding(String charset) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#setContentLength(int)
- */
- public void setContentLength(int len) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#setContentType(java.lang.String)
- */
- public void setContentType(String type) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.ServletResponse#setLocale(java.util.Locale)
- */
- public void setLocale(Locale loc) {
- this.locale = loc;
-
- }
-
-}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpSession.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StubHttpSession.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubHttpSession.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,156 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.util.Enumeration;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionContext;
-
-/**
- * @author asmirnov
- *
- */
-public class StubHttpSession implements HttpSession {
-
- public static final String SESSION_ID="1234567890";
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
- */
- public Object getAttribute(String name) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getAttributeNames()
- */
- public Enumeration getAttributeNames() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getCreationTime()
- */
- public long getCreationTime() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getId()
- */
- public String getId() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getLastAccessedTime()
- */
- public long getLastAccessedTime() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
- */
- public int getMaxInactiveInterval() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getServletContext()
- */
- public ServletContext getServletContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getSessionContext()
- */
- public HttpSessionContext getSessionContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
- */
- public Object getValue(String name) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#getValueNames()
- */
- public String[] getValueNames() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#invalidate()
- */
- public void invalidate() {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#isNew()
- */
- public boolean isNew() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#putValue(java.lang.String, java.lang.Object)
- */
- public void putValue(String name, Object value) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
- */
- public void removeAttribute(String name) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
- */
- public void removeValue(String name) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String, java.lang.Object)
- */
- public void setAttribute(String name, Object value) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
- */
- public void setMaxInactiveInterval(int interval) {
- // TODO Auto-generated method stub
-
- }
-
-}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubServletConfig.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StubServletConfig.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubServletConfig.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,70 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-
-/**
- * @author asmirnov
- *
- */
-public class StubServletConfig implements ServletConfig {
-
- public static final String FACES_SERVLET = "Faces Servlet";
-
- private final ServletContext context;
-
- private Map<String, String> initParameters ;
-
-
-
- public StubServletConfig(ServletContext context) {
- this.context = context;
- this.initParameters = new HashMap<String, String>();
- }
-
- public StubServletConfig(ServletContext context,Map<String, String>
initParameters) {
- this.context = context;
- this.initParameters = initParameters;
- }
- /* (non-Javadoc)
- * @see javax.servlet.ServletConfig#getInitParameter(java.lang.String)
- */
- public String getInitParameter(String name) {
- return initParameters.get(name);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletConfig#getInitParameterNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
- }
-
- public void setInitParameter(String name, String value) {
- initParameters.put(name, value);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletConfig#getServletContext()
- */
- public ServletContext getServletContext() {
- return context;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletConfig#getServletName()
- */
- public String getServletName() {
- return FACES_SERVLET;
- }
-
-}
Deleted:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubServletContext.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/stub/StubServletContext.java 2008-10-30
00:26:08 UTC (rev 10973)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StubServletContext.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,267 +0,0 @@
-/**
- *
- */
-package org.richfaces.test.stub;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.Servlet;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
-/**
- * @author asmirnov
- *
- */
-public class StubServletContext implements ServletContext {
-
- public static final String CONTEXT_PATH = "";
- private final Map<String, Object> attributes = new HashMap<String,
Object>();
- private final ServerResource serverRoot;
-
- private Map<String,String> initParameters = new HashMap<String, String>();
-
- public StubServletContext(ServerResource serverRoot) {
- this.serverRoot = serverRoot;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
- */
- public Object getAttribute(String name) {
- return attributes.get(name);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getAttributeNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getAttributeNames() {
- return Collections.enumeration(attributes.keySet());
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getContext(java.lang.String)
- */
- public ServletContext getContext(String uripath) {
- // stub server has only one context.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getContextPath()
- */
- public String getContextPath() {
- // Test always run in the root context.
- return CONTEXT_PATH;
- }
-
- public void addInitParameters(Map<String,String>parameters) {
- initParameters.putAll(parameters);
- }
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
- */
- public String getInitParameter(String name) {
- return initParameters.get(name);
- }
-
-
- /**
- * Put new init parameter to the Map.
- * @param name
- * @param value
- */
- public void setInitParameter(String name, String value) {
- initParameters.put(name, value);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getInitParameterNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getInitParameterNames() {
- return Collections.enumeration(initParameters.keySet());
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getMajorVersion()
- */
- public int getMajorVersion() {
- return 2;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
- */
- public String getMimeType(String file) {
- // TODO create mime-types table.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getMinorVersion()
- */
- public int getMinorVersion() {
- return 5;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
- */
- public RequestDispatcher getNamedDispatcher(String name) {
- // TODO create stub dispatcher.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
- */
- public String getRealPath(String path) {
- // we always use 'virtual' configuration.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
- */
- public RequestDispatcher getRequestDispatcher(String path) {
- // TODO implement stub dispatcher.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getResource(java.lang.String)
- */
- public URL getResource(String path) throws MalformedURLException {
- URL url = null;
- ServerResource resource = getServerResource(path);
- if(null != resource){
- url = resource.getURL();
- }
- return url;
- }
-
- /**
- * @param path
- * @return
- */
- protected ServerResource getServerResource(String path) {
- return serverRoot.getResource(new ServerResourcePath(path));
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
- */
- public InputStream getResourceAsStream(String path) {
- ServerResource resource = getServerResource(path);
- if(null != resource){
- try {
- return resource.getAsStream();
- } catch (IOException e) {
- return null;
- }
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
- */
- @SuppressWarnings("unchecked")
- public Set getResourcePaths(String path) {
- ServerResource resource = getServerResource(path);
- if(null != resource){
- return resource.getPaths();
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getServerInfo()
- */
- public String getServerInfo() {
- return "Stub test server";
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getServlet(java.lang.String)
- */
- public Servlet getServlet(String name) throws ServletException {
- // always return null.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getServletContextName()
- */
- public String getServletContextName() {
- // Stub server has no declared name.
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getServletNames()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getServletNames() {
- return Collections.enumeration(Collections.EMPTY_LIST);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#getServlets()
- */
- @SuppressWarnings("unchecked")
- public Enumeration getServlets() {
- return Collections.enumeration(Collections.EMPTY_LIST);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#log(java.lang.String)
- */
- public void log(String msg) {
- // TODO implement logging.
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String)
- */
- public void log(Exception exception, String msg) {
- // TODO implement logging.
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#log(java.lang.String, java.lang.Throwable)
- */
- public void log(String message, Throwable throwable) {
- // TODO implement logging.
-
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
- */
- public void removeAttribute(String name) {
- attributes.remove(name);
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
- */
- public void setAttribute(String name, Object object) {
- attributes.put(name, object);
- }
-
-}
Copied:
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml
(from rev 11026,
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/faces-config.xml)
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/faces-config.xml 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,69 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!--
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License").
You
+ may not use this file except in compliance with the License. You can obtain
+ a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL.html
+ or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ Sun designates this particular file as subject to the "Classpath" exception
+ as provided by Sun in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the License
+ Header, with the fields enclosed by brackets [] replaced by your own
+ identifying information: "Portions Copyrighted [year]
+ [name of copyright owner]"
+
+ Contributor(s):
+
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+-->
+
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0">
+
+ <!-- our NumberBean we created before -->
+ <managed-bean>
+ <managed-bean-name>HelloBean</managed-bean-name>
+
<managed-bean-class>org.richfaces.test.HelloBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+
+ <!-- going from guess.xhtml to response.xhtml -->
+ <navigation-rule>
+ <from-view-id>/hello.xhtml</from-view-id>
+ <navigation-case>
+ <from-outcome>success</from-outcome>
+ <to-view-id>/response.xhtml</to-view-id>
+ </navigation-case>
+ </navigation-rule>
+
+ <!-- going from response.xhtml to guess.xhtml -->
+ <navigation-rule>
+ <from-view-id>/response.xhtml</from-view-id>
+ <navigation-case>
+ <from-outcome>success</from-outcome>
+ <to-view-id>/hello.xhtml</to-view-id>
+ </navigation-case>
+ </navigation-rule>
+
+</faces-config>
Copied: branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/web.xml
(from rev 10995,
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/web.xml)
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/web.xml
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/main/resources/org/richfaces/test/web.xml 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,59 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<web-app version="2.5"
+
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
+
+ <display-name>Stub test</display-name>
+ <description>
+ Stub testing server
+ </description>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>server</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+ <context-param>
+ <param-name>com.sun.faces.validateXml</param-name>
+ <param-value>true</param-value>
+ <description>
+ Set this flag to true if you want the JavaServer Faces
+ Reference Implementation to validate the XML in your
+ faces-config.xml resources against the DTD. Default
+ value is false.
+ </description>
+ </context-param>
+ <context-param>
+ <param-name>com.sun.faces.verifyObjects</param-name>
+ <param-value>true</param-value>
+ <description>
+ Set this flag to true if you want the JavaServer Faces
+ Reference Implementation to verify that all of the application
+ objects you have configured (components, converters,
+ renderers, and validators) can be successfully created.
+ Default value is false.
+ </description>
+ </context-param>
+
+ <!-- Faces Servlet -->
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ </servlet>
+
+
+ <!-- Faces Servlet Mapping -->
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+
+
+</web-app>
+
+
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -15,16 +15,21 @@
import javax.faces.application.StateManager;
import javax.faces.application.ViewHandler;
import javax.faces.webapp.FacesServlet;
+import javax.servlet.http.HttpSession;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.w3c.dom.Element;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.SubmittableElement;
import com.sun.faces.config.ConfigureListener;
import com.sun.faces.util.FacesLogger;
@@ -32,60 +37,22 @@
* @author asmirnov
*
*/
-public class FacesServerTest {
+public class FacesServerTest extends AbstractFacesTest {
- private static ClassLoader contextClassLoader;
- private static LocalServer facesServer;
-
/**
* @throws java.lang.Exception
*/
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- contextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(
- LocalServer.class.getClassLoader());
- InputStream stream = FacesServerTest.class
- .getResourceAsStream("logging.properties");
- if (null != stream) {
- try {
- LogManager.getLogManager().readConfiguration(stream);
- } finally {
- stream.close();
- }
- }
- facesServer = new LocalServer();
- facesServer.addServlet("*.jsf", new FacesServlet());
- facesServer.addResource("/WEB-INF/web.xml",
- "org/richfaces/test/web.xml");
- facesServer.addResource("/WEB-INF/faces-config.xml",
- "org/richfaces/test/faces-config.xml");
- facesServer.addResource("/hello.xhtml",
"org/richfaces/test/hello.xhtml");
- facesServer.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME,
StateManager.STATE_SAVING_METHOD_SERVER);
- facesServer.addInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
".xhtml");
- facesServer.addInitParameter("com.sun.faces.validateXml", "true");
- facesServer.addInitParameter("com.sun.faces.verifyObjects",
"true");
- facesServer.addWebListener(new ConfigureListener());
- facesServer.init();
- }
-
- /**
- * @throws java.lang.Exception
- */
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- facesServer.destroy();
- Thread.currentThread().setContextClassLoader(contextClassLoader);
- }
-
- /**
- * @throws java.lang.Exception
- */
@Before
public void setUp() throws Exception {
}
+ @Override
+ protected void setupWebContent(StagingServer facesServer) {
+ facesServer.addResource("/hello.xhtml",
"org/richfaces/test/hello.xhtml");
+ facesServer.addResource("/response.xhtml",
"org/richfaces/test/response.xhtml");
+ facesServer.addResource("/wave.med.gif",
"org/richfaces/test/wave.med.gif");
+ }
/**
* @throws java.lang.Exception
*/
@@ -95,15 +62,33 @@
/**
* Test method for
- * {@link org.richfaces.test.LocalServer#getConnection(java.net.URL)}.
+ * {@link org.richfaces.test.StagingServer#getConnection(java.net.URL)}.
*
* @throws Exception
*/
@Test
- public void testGetConnection() throws Exception {
+ public void testHelloFacelets() throws Exception {
WebClient webClient = new LocalWebClient(facesServer);
HtmlPage page = webClient.getPage("http://localhost/hello.jsf");
- System.out.println(page.asXml());
+ System.out.println(page.asXml());
+ Element submitElement = page.getElementById("helloForm:submit");
+ HtmlForm htmlForm = page.getFormByName("helloForm");
+ htmlForm.getInputByName("helloForm:username");
+ assertNotNull(htmlForm);
+ HtmlInput input = htmlForm.getInputByName("helloForm:username");
+ assertNotNull(input);
+ input.setValueAttribute("foo");
+ HtmlPage responsePage = (HtmlPage) htmlForm.submit((SubmittableElement)
submitElement);
+ assertNotNull(responsePage);
+ System.out.println(responsePage.asXml());
+ HttpSession session = facesServer.getSession(false);
+ assertNotNull(session);
+ HelloBean bean = (HelloBean) session.getAttribute("HelloBean");
+ assertNotNull(bean);
+ assertEquals("foo", bean.getName());
+ Element span = responsePage.getElementById("responseform:userLabel");
+ assertNotNull(span);
+ assertEquals("foo", span.getTextContent().trim());
}
}
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourcePathTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourcePathTest.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourcePathTest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -6,6 +6,7 @@
import static org.junit.Assert.*;
import org.junit.Test;
+import org.richfaces.test.staging.ServerResourcePath;
/**
* @author asmirnov
@@ -14,7 +15,7 @@
public class ServerResourcePathTest {
/**
- * Test method for {@link
org.richfaces.test.stub.ServerResourcePath#ServerResourcePath(java.lang.String)}.
+ * Test method for {@link
org.richfaces.test.staging.ServerResourcePath#ServerResourcePath(java.lang.String)}.
*/
@Test
public void testRootPath() {
@@ -26,7 +27,7 @@
}
/**
- * Test method for {@link
org.richfaces.test.stub.ServerResourcePath#ServerResourcePath(java.lang.String)}.
+ * Test method for {@link
org.richfaces.test.staging.ServerResourcePath#ServerResourcePath(java.lang.String)}.
*/
@Test
public void testWebInfPath() {
@@ -44,7 +45,7 @@
}
/**
- * Test method for {@link
org.richfaces.test.stub.ServerResourcePath#ServerResourcePath(java.lang.String)}.
+ * Test method for {@link
org.richfaces.test.staging.ServerResourcePath#ServerResourcePath(java.lang.String)}.
*/
@Test
public void testWebInfTrainingSlashPath() {
@@ -63,7 +64,7 @@
/**
- * Test method for {@link
org.richfaces.test.stub.ServerResourcePath#ServerResourcePath(java.lang.String)}.
+ * Test method for {@link
org.richfaces.test.staging.ServerResourcePath#ServerResourcePath(java.lang.String)}.
*/
@Test
public void testWebXmlPath() {
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourceTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourceTest.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServerResourceTest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -11,6 +11,10 @@
import java.util.Set;
import org.junit.Test;
+import org.richfaces.test.staging.ClasspathServerResource;
+import org.richfaces.test.staging.ServerResource;
+import org.richfaces.test.staging.ServerResourcePath;
+import org.richfaces.test.staging.ServerResourcesDirectory;
/**
* @author asmirnov
@@ -46,7 +50,7 @@
/**
* Test method for
- * {@link
org.richfaces.test.stub.ServerResourcesDirectory#addResource(org.richfaces.test.stub.ServerResourcePath,
org.richfaces.test.stub.ServerResource)}
+ * {@link
org.richfaces.test.staging.ServerResourcesDirectory#addResource(org.richfaces.test.staging.ServerResourcePath,
org.richfaces.test.staging.ServerResource)}
* .
*/
@Test
@@ -69,7 +73,7 @@
/**
* Test method for
- * {@link
org.richfaces.test.stub.ServerResourcesDirectory#getResource(org.richfaces.test.stub.ServerResourcePath)}
+ * {@link
org.richfaces.test.staging.ServerResourcesDirectory#getResource(org.richfaces.test.staging.ServerResourcePath)}
* .
*/
@Test
@@ -90,7 +94,7 @@
/**
* Test method for
- * {@link
org.richfaces.test.stub.ServerResourcesDirectory#getResource(org.richfaces.test.stub.ServerResourcePath)}
+ * {@link
org.richfaces.test.staging.ServerResourcesDirectory#getResource(org.richfaces.test.staging.ServerResourcePath)}
* .
*/
@Test
@@ -107,7 +111,7 @@
/**
* Test method for
- * {@link org.richfaces.test.stub.ServerResourcesDirectory#getAsStream()}.
+ * {@link org.richfaces.test.staging.ServerResourcesDirectory#getAsStream()}.
*
* @throws IOException
*/
@@ -129,7 +133,7 @@
/**
* Test method for
- * {@link org.richfaces.test.stub.ServerResourcesDirectory#getURL()}.
+ * {@link org.richfaces.test.staging.ServerResourcesDirectory#getURL()}.
*/
@Test
public void testGetURL() {
Modified:
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServletTest.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServletTest.java 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/stub/ServletTest.java 2008-11-12
00:43:49 UTC (rev 11095)
@@ -6,13 +6,18 @@
import javax.servlet.ServletException;
import org.junit.Test;
+import org.richfaces.test.staging.RequestChain;
+import org.richfaces.test.staging.ServerResource;
+import org.richfaces.test.staging.ServletContainer;
+import org.richfaces.test.staging.StaticServlet;
+import org.richfaces.test.staging.StagingServletContext;
public class ServletTest {
@Test
public void testIsApplicable() {
StaticServlet staticServlet = new StaticServlet();
- ServletContainer servlet = new ServletContainer("/foo/*",staticServlet);
+ RequestChain servlet = new ServletContainer("/foo/*",staticServlet);
assertTrue(servlet.isApplicable("/foo/bar.jsf"));
assertFalse(servlet.isApplicable("/foz/bar.jsf"));
assertFalse(servlet.isApplicable("bar"));
@@ -30,7 +35,7 @@
@Test
public void testGetServletPath() {
StaticServlet staticServlet = new StaticServlet();
- ServletContainer servlet = new ServletContainer("/foo/*",staticServlet);
+ RequestChain servlet = new ServletContainer("/foo/*",staticServlet);
assertEquals("/foo/", servlet.getServletPath("/foo/bar.jsf"));
assertNull(servlet.getServletPath("/foz/bar.jsf"));
servlet = new ServletContainer("*.jsf",staticServlet);
@@ -40,7 +45,7 @@
@Test
public void testGetPathInfo() {
StaticServlet staticServlet = new StaticServlet();
- ServletContainer servlet = new ServletContainer("/foo/*",staticServlet);
+ RequestChain servlet = new ServletContainer("/foo/*",staticServlet);
assertEquals("bar.jsf", servlet.getPathInfo("/foo/bar.jsf"));
assertNull(servlet.getPathInfo("/foz/bar.jsf"));
servlet = new ServletContainer("*.jsf",staticServlet);
@@ -51,8 +56,8 @@
@Test
public void testInit() throws ServletException {
StaticServlet staticServlet = new StaticServlet();
- ServletContainer servlet = new ServletContainer("/foo/*",staticServlet);
- StubServletContext context = new StubServletContext(){
+ RequestChain servlet = new ServletContainer("/foo/*",staticServlet);
+ StagingServletContext context = new StagingServletContext(){
@Override
protected ServerResource getServerResource(String path) {
Deleted:
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/faces-config.xml
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/faces-config.xml 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/faces-config.xml 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,69 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
-<!--
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-
- Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
-
- The contents of this file are subject to the terms of either the GNU
- General Public License Version 2 only ("GPL") or the Common Development
- and Distribution License("CDDL") (collectively, the "License").
You
- may not use this file except in compliance with the License. You can obtain
- a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL.html
- or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
- language governing permissions and limitations under the License.
-
- When distributing the software, include this License Header Notice in each
- file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
- Sun designates this particular file as subject to the "Classpath" exception
- as provided by Sun in the GPL Version 2 section of the License file that
- accompanied this code. If applicable, add the following below the License
- Header, with the fields enclosed by brackets [] replaced by your own
- identifying information: "Portions Copyrighted [year]
- [name of copyright owner]"
-
- Contributor(s):
-
- If you wish your version of this file to be governed by only the CDDL or
- only the GPL Version 2, indicate your decision by adding "[Contributor]
- elects to include this software in this distribution under the [CDDL or GPL
- Version 2] license." If you don't indicate a single choice of license, a
- recipient has the option to distribute your version of this file under
- either the CDDL, the GPL Version 2 or to extend the choice of license to
- its licensees as provided above. However, if you add GPL Version 2 code
- and therefore, elected the GPL Version 2 license, then the option applies
- only if the new code is made subject to such option by the copyright
- holder.
--->
-
-<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
- version="2.0">
-
- <!-- our NumberBean we created before -->
- <managed-bean>
- <managed-bean-name>HelloBean</managed-bean-name>
-
<managed-bean-class>org.richfaces.test.HelloBean</managed-bean-class>
- <managed-bean-scope>session</managed-bean-scope>
- </managed-bean>
-
- <!-- going from guess.xhtml to response.xhtml -->
- <navigation-rule>
- <from-view-id>/hello.xhtml</from-view-id>
- <navigation-case>
- <from-outcome>success</from-outcome>
- <to-view-id>/response.xhtml</to-view-id>
- </navigation-case>
- </navigation-rule>
-
- <!-- going from response.xhtml to guess.xhtml -->
- <navigation-rule>
- <from-view-id>/response.xhtml</from-view-id>
- <navigation-case>
- <from-outcome>success</from-outcome>
- <to-view-id>/hello.xhtml</to-view-id>
- </navigation-case>
- </navigation-rule>
-
-</faces-config>
Added:
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/response.xhtml
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/response.xhtml
(rev 0)
+++
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/response.xhtml 2008-11-12
00:43:49 UTC (rev 11095)
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html">
+<body>
+
+ <h:form id="responseform">
+ <h:graphicImage id="waveImg" url="/wave.med.gif" />
+ <h2>Hi, <h:outputText id="userLabel" value="
#{HelloBean.name}" /> </h2>
+ <h:commandButton id="back" value="Back"
action="success" />
+ </h:form>
+</body>
+</html>
\ No newline at end of file
Property changes on:
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/response.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/wave.med.gif
===================================================================
(Binary files differ)
Property changes on:
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/wave.med.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/web.xml
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/web.xml 2008-11-11
20:12:38 UTC (rev 11094)
+++
branches/jsf2.0/framework/jsf-test/src/test/resources/org/richfaces/test/web.xml 2008-11-12
00:43:49 UTC (rev 11095)
@@ -1,59 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
-<web-app version="2.5"
-
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >
-
- <display-name>Stub test</display-name>
- <description>
- Stub testing server
- </description>
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
- <param-value>server</param-value>
- </context-param>
- <context-param>
- <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
- <param-value>.xhtml</param-value>
- </context-param>
- <context-param>
- <param-name>com.sun.faces.validateXml</param-name>
- <param-value>true</param-value>
- <description>
- Set this flag to true if you want the JavaServer Faces
- Reference Implementation to validate the XML in your
- faces-config.xml resources against the DTD. Default
- value is false.
- </description>
- </context-param>
- <context-param>
- <param-name>com.sun.faces.verifyObjects</param-name>
- <param-value>true</param-value>
- <description>
- Set this flag to true if you want the JavaServer Faces
- Reference Implementation to verify that all of the application
- objects you have configured (components, converters,
- renderers, and validators) can be successfully created.
- Default value is false.
- </description>
- </context-param>
-
- <!-- Faces Servlet -->
- <servlet>
- <servlet-name>Faces Servlet</servlet-name>
- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
- </servlet>
-
-
- <!-- Faces Servlet Mapping -->
-
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>*.jsf</url-pattern>
- </servlet-mapping>
-
-
-</web-app>
-
-