Author: alexsmirnov
Date: 2008-11-20 19:26:49 -0500 (Thu, 20 Nov 2008)
New Revision: 11283
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/staging/StagingConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java
Log:
replace all staging server exceptions by the TestException, check init status in the
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-20
20:25:42 UTC (rev 11282)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-21
00:26:49 UTC (rev 11283)
@@ -59,11 +59,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:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-20
20:25:42 UTC (rev 11282)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-21
00:26:49 UTC (rev 11283)
@@ -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:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
===================================================================
---
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-20
20:25:42 UTC (rev 11282)
+++
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-21
00:26:49 UTC (rev 11283)
@@ -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:
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-20
20:25:42 UTC (rev 11282)
+++
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-21
00:26:49 UTC (rev 11283)
@@ -44,7 +44,7 @@
* @throws java.lang.Exception
*/
@Before
- public void setUp() throws Exception {
+ public void setUpTest() throws Exception {
}
@Override
@@ -58,7 +58,7 @@
* @throws java.lang.Exception
*/
@After
- public void tearDown() throws Exception {
+ public void tearDownTest() throws Exception {
}
/**
Modified:
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java
===================================================================
---
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java 2008-11-20
20:25:42 UTC (rev 11282)
+++
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java 2008-11-21
00:26:49 UTC (rev 11283)
@@ -27,7 +27,7 @@
* @throws java.lang.Exception
*/
@Before
- public void setUp() throws Exception {
+ public void setUpTest() throws Exception {
}
@Override
@@ -41,13 +41,13 @@
* @throws java.lang.Exception
*/
@After
- public void tearDown() throws Exception {
+ public void tearDownTest() throws Exception {
}
@Test
public void testRequest() throws Exception {
WebClient webClient = new LocalWebClient(facesServer,BrowserVersion.FIREFOX_3);
- webClient.setThrowExceptionOnScriptError(false);
+ webClient.setThrowExceptionOnScriptError(true);
HtmlPage page = webClient.getPage("http://localhost/home.jsf");
System.out.println(page.asXml());