Author: alexsmirnov
Date: 2008-11-21 19:52:43 -0500 (Fri, 21 Nov 2008)
New Revision: 11301
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/AbstractServerResource.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html
trunk/framework/jsf-test/src/main/javadoc/overview.html
Log:
javadoc packages documentation
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -5,8 +5,6 @@
import java.io.IOException;
-import javax.servlet.ServletException;
-
import org.apache.commons.httpclient.NameValuePair;
import org.richfaces.test.staging.HttpMethod;
import org.richfaces.test.staging.StagingConnection;
@@ -59,11 +57,7 @@
if(null != body &&
FormEncodingType.URL_ENCODED.getName().equals(contentType)){
connection.parseFormParameters(body);
}
- try {
- connection.execute();
- } catch (ServletException e) {
- throw new IOException(e.getMessage());
- }
+ connection.execute();
return new LocalWebResponse(settings,connection);
}
}
\ No newline at end of file
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/AbstractServerResource.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/AbstractServerResource.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/AbstractServerResource.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -4,7 +4,6 @@
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
-import java.util.Collections;
import java.util.Set;
import java.util.logging.Logger;
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/ServerResourcesDirectory.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -6,7 +6,6 @@
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -164,17 +164,23 @@
/**
* Execute this connection request on the associated servlet or filter chain.
- * @throws ServletException
- * @throws IOException
+ * @throws TestException if any errors were during execution.
*/
- public void execute() throws ServletException, IOException {
+ public void execute() {
if (isStarted() || isFinished()) {
throw new TestException(
"request have already been executed");
}
start();
- this.servlet.execute(request, response);
- finish();
+ try {
+ this.servlet.execute(request, response);
+ } catch (ServletException e) {
+ throw new TestException("Error execute request ",e);
+ } catch (IOException e) {
+ throw new TestException("IO Error during request execution",e);
+ } finally {
+ finish();
+ }
}
/**
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpRequest.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -15,7 +15,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpResponse.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -7,22 +7,15 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.text.DateFormat;
-import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
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.junit.internal.matchers.SubstringMatcher;
-
/**
* @author asmirnov
*
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingHttpSession.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -4,14 +4,11 @@
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 java.util.concurrent.ConcurrentHashMap;
-import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
@@ -21,6 +18,7 @@
* @author asmirnov
*
*/
+@SuppressWarnings("deprecation")
abstract class StagingHttpSession implements HttpSession {
private static final int DEFAULT_INACTIVE_TIME = 30;
@@ -119,7 +117,6 @@
*
* @see javax.servlet.http.HttpSession#getSessionContext()
*/
- @SuppressWarnings("deprecation")
public HttpSessionContext getSessionContext() {
throw new NotImplementedException("Session context is not implemented");
}
@@ -168,7 +165,6 @@
*/
public boolean isNew() {
checkValid();
- // TODO Auto-generated method stub
return false;
}
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -71,28 +71,30 @@
private static final Logger log = ServerLogger.SERVER.getLogger();
- private List<RequestChain> servlets = new ArrayList<RequestChain>();
+ private final List<RequestChain> servlets = new ArrayList<RequestChain>();
- private RequestChain defaultServlet;
+ private RequestChain defaultServlet= new ServletContainer(null, new StaticServlet());
- private List<EventListener> contextListeners = new
ArrayList<EventListener>();
+ private final List<EventListener> contextListeners = new
ArrayList<EventListener>();
- private Map<String, String> initParameters = new HashMap<String, String>();
+ private final Map<String, String> initParameters = new HashMap<String,
String>();
- private ServerResource serverRoot = new ServerResourcesDirectory();
+ private final ServerResource serverRoot = new ServerResourcesDirectory();
private final Map<String, String> mimeTypes = new HashMap<String,
String>();
private InvocationListener invocationListener;
- private StagingServletContext context;
+ private final StagingServletContext context = new LocalContext();
private ServletContext contextProxy;
- private ServerHttpSession session;
+ private ServerHttpSession session=null;
- private HttpSession sessionProxy;
+ private HttpSession sessionProxy=null;
+ private boolean initialised=false;
+
/**
* This inner class links ServletContext calls to the server instance.
* @author asmirnov
@@ -286,7 +288,7 @@
result = defaultServlet;
}
} catch (MalformedURLException e) {
- // do nothing, just return no servlet.
+ log.warning("Mailformed request URL "+e.getMessage());
}
}
return result;
@@ -400,7 +402,7 @@
}
} catch (IOException e) {
- throw new TestException(e);
+ throw new TestException("Error read Jar content",e);
} catch (URISyntaxException e) {
throw new TestException(e);
}
@@ -532,6 +534,9 @@
*
*/
public synchronized HttpSession getSession(boolean create) {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
if (null == this.session && create) {
this.session = new ServerHttpSession();
// Create proxy objects.
@@ -560,8 +565,7 @@
* It should be called from test setUp method to prepare testing environment.
*/
public void init() {
- // Create context.
- this.context = new LocalContext();
+ log.info("Init staging server");
// Create Jsp factory
JspFactory.setDefaultFactory(new StaggingJspFactory(this.context));
// Create init parameters
@@ -576,7 +580,6 @@
new Class[] { ServletContext.class },
getInvocationHandler(context));
// Create default servlet
- defaultServlet = new ServletContainer(null, new StaticServlet());
final ServletContextEvent event = new ServletContextEvent(context);
fireEvent(CONTEXT_LISTENER_CLASS,
new EventInvoker<ServletContextListener>() {
@@ -588,12 +591,13 @@
try {
for (RequestChain servlet : servlets) {
// init servlet
- servlet.init(this.context);
+ servlet.init(context);
}
- defaultServlet.init(getContext());
+ defaultServlet.init(context);
} catch (ServletException e) {
- throw new TestException(e);
+ throw new TestException("Servlet initialisation error ",e);
}
+ this.initialised = true;
}
/**
@@ -602,6 +606,10 @@
*
*/
public void destroy() {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
+ this.initialised = false;
// Destroy session
if (null != this.session) {
// inform session listeners.
@@ -630,7 +638,8 @@
defaultServlet.destroy();
// Create Jsp factory
JspFactory.setDefaultFactory(null);
-
+ this.contextProxy = null;
+ log.info("Staging server have been destroyed");
}
/**
@@ -641,6 +650,9 @@
* @throws {@link TestException} if no servlet found to process given URL.
*/
public StagingConnection getConnection(URL url) {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
return new StagingConnection(this, url);
}
@@ -649,6 +661,9 @@
* @return context instance.
*/
public ServletContext getContext() {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
return contextProxy;
}
Modified:
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2008-11-21
22:17:26 UTC (rev 11300)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServletContext.java 2008-11-22
00:52:43 UTC (rev 11301)
@@ -7,7 +7,6 @@
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;
@@ -21,7 +20,6 @@
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
-import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletException;
Modified: trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html
===================================================================
--- trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html 2008-11-21
22:17:26 UTC (rev 11300)
+++ trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html 2008-11-22
00:52:43 UTC (rev 11301)
@@ -5,6 +5,8 @@
<title>Insert title here</title>
</head>
<body>
-
+<p>This packcage contains <a
href="AbstractFacesTest.html">AbstractFacesTest</a> class, wich can be
used as a base point for all JSF-related test cases.</p>
+<p>The <a href="LocalWebClient.html">LocalWebClient</a>
class, whether is subclass of the HtmlUnit <a
href="http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/h...
class used
+as client to the local staging server <a
href="org/richfaces/test/staging/StagingServer.html">StagingServer</a>.</p>
</body>
</html>
\ No newline at end of file
Modified: trunk/framework/jsf-test/src/main/javadoc/overview.html
===================================================================
--- trunk/framework/jsf-test/src/main/javadoc/overview.html 2008-11-21 22:17:26 UTC (rev
11300)
+++ trunk/framework/jsf-test/src/main/javadoc/overview.html 2008-11-22 00:52:43 UTC (rev
11301)
@@ -5,6 +5,25 @@
<title>Insert title here</title>
</head>
<body>
-
+<h1>Java web application testing framework</h1>
+<p>This is a testing framework desibned ( but not limited to ) for test JSF
components and applications</p>
+<p>Though best strategy for alow-level black box testing is to use a Mock objects,
+ writing integration tests required a more real environment.
+ On the other hand, running tests on the real web, or, even more, full JEE server takes a
lot of the resoures and has a own limitations.
+</p>
+<p>This framework designed as an intermediate solution. It contains <a
href="org/richfaces/test/staging/StagingServer.html">staging Java Web
server</a>, where is real
+ JSF framework running. This is at most Servlet 2.5 / JSP 2.1 compatible container, wich
allows to run at most all JSF applications. But, in difference with real web container,
+ it is "in process" only server. That does not have network connector, session
management, does not process any configuration files etc. Its advantage for a unit
testing:
+ <ul>
+ <li>It has a minimal startup time, because no configuration files processed and no
resource pools or other heavy objects created.</li>
+ <li>It is extremally flexible. It uses a 'virtual' web application
content, that can be builded from any objects:
+ files, java resource, even dynamic classes those generate content 'on the fly'.
Every test is able to use individual application content.</li>
+ <li>Not only content, but any other configuration aspects, like servlets,
filters, configuration parameters can be changed from the test code.</li>
+ <li>Tests runs as a web server clients in the same JVM and thread as a
server-side code does. It allows to inspect any objects on the both sides from the same
code. No thread syncronisation is necessary in the test code.</li>
+ <li>It is possible to make test runs "inside" web request. For example,
only one JSF lifecycle phase can be tested.
+ </ul>
+ <p>Other important part of the framework is <a
href="org/richfaces/test/LocalWebClient.html">LocalWebClient</a>,
subclass of the HtmlUnit <a
href="http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/h...;.
+ In difference with the original client it always making local call to the staging server
instead of real network protocol use. This client allows to use all HtmlUnit HTML and
JavaScript testing features, even client side JavaScript test runs.</p>
+ <p>To make tests are easest, we provide <a
href="org/richfaces/test/AbstractFacesTest.html">the base abstract
class</a> for a Junit test with set of the template method for a fine virtual server
tuning.</p>
</body>
</html>
\ No newline at end of file