Author: alexsmirnov
Date: 2008-11-20 15:04:55 -0500 (Thu, 20 Nov 2008)
New Revision: 11281
Modified:
trunk/framework/jsf-test/pom.xml
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
Log:
make LocalWebResponse usable for an in-response tests
Modified: trunk/framework/jsf-test/pom.xml
===================================================================
--- trunk/framework/jsf-test/pom.xml 2008-11-20 16:06:01 UTC (rev 11280)
+++ trunk/framework/jsf-test/pom.xml 2008-11-20 20:04:55 UTC (rev 11281)
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
-<project>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>framework</artifactId>
<groupId>org.richfaces</groupId>
@@ -25,7 +26,7 @@
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_10</version>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>el-impl</groupId>
@@ -103,5 +104,16 @@
<artifactId>xalan</artifactId>
<version>2.7.0</version>
</dependency>
+ <dependency>
+ <groupId>de.berlios.jsunit</groupId>
+ <artifactId>jsunit</artifactId>
+ <version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
===================================================================
---
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-20
16:06:01 UTC (rev 11280)
+++
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-20
20:04:55 UTC (rev 11281)
@@ -18,35 +18,61 @@
import com.gargoylesoftware.htmlunit.WebResponse;
/**
- * This implementation realise WebResponse wrapper for a staging server connection.
- * This class for an internal use only.
+ * This implementation realise WebResponse wrapper for a staging server
+ * connection. This class is used by the {@link LocalWebClient}, but also can be used to
analise response rendering:
+ * <pre>
+ * ............
+ * @Test
+ * public void testRender() {
+ * setupFacesRequest();
+ * // Prepare view etc
+ * ..................
+ * lifecycle.render(facesContext);
+ * WebClient webClient = new LocalWebClient(facesServer);
+ * HtmlPage page = (HtmlPage) webClient.loadWebResponseInto(new
LocalWebResponse(connection), webClient.getCurrentWindow());
+ * // analyse response
+ * assertTrue(....)
+ * }
+ * </pre>
+ *
* @author asmirnov
- *
+ *
*/
-final class LocalWebResponse implements WebResponse {
- private final WebRequestSettings settings;
+public class LocalWebResponse implements WebResponse {
+ private WebRequestSettings settings;
private final StagingConnection serverConnection;
- public LocalWebResponse(WebRequestSettings settings,StagingConnection serverConnection)
{
- this.settings = settings;
+ public LocalWebResponse(StagingConnection serverConnection) {
this.serverConnection = serverConnection;
}
- /* (non-Javadoc)
+ public LocalWebResponse(WebRequestSettings settings,
+ StagingConnection connection) {
+ this(connection);
+ this.settings = settings;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getContentAsStream()
*/
public InputStream getContentAsStream() throws IOException {
return new ByteArrayInputStream(getResponseBody());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getContentAsString()
*/
public String getContentAsString() {
return serverConnection.getContentAsString();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getContentCharSet()
*/
public String getContentCharSet() {
@@ -57,73 +83,103 @@
return serverConnection.getResponseContentType();
}
- /* (non-Javadoc)
- * @see com.gargoylesoftware.htmlunit.WebResponse#getLoadTimeInMilliSeconds()
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.gargoylesoftware.htmlunit.WebResponse#getLoadTimeInMilliSeconds()
*/
public long getLoadTimeInMilliSeconds() {
return 0;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getRequestMethod()
*/
public com.gargoylesoftware.htmlunit.HttpMethod getRequestMethod() {
- return
com.gargoylesoftware.htmlunit.HttpMethod.valueOf(serverConnection.getRequestMethod().toString());
+ return com.gargoylesoftware.htmlunit.HttpMethod
+ .valueOf(serverConnection.getRequestMethod().toString());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getRequestSettings()
*/
public WebRequestSettings getRequestSettings() {
+ if (settings == null) {
+ settings = new WebRequestSettings(this.getUrl(), getRequestMethod());
+ }
return settings;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getResponseBody()
*/
public byte[] getResponseBody() {
return serverConnection.getResponseBody();
}
- /* (non-Javadoc)
- * @see
com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaderValue(java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaderValue(java
+ * .lang.String)
*/
public String getResponseHeaderValue(String headerName) {
- // TODO Auto-generated method stub
+ String[] values = serverConnection.getResponseHeaders().get(headerName);
+ if(null != values && values.length >0){
+ return values[0];
+ }
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getStatusCode()
*/
public int getStatusCode() {
return serverConnection.getResponseStatus();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getStatusMessage()
*/
public String getStatusMessage() {
return serverConnection.getErrorMessage();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getUrl()
*/
public URL getUrl() {
return serverConnection.getUrl();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaders()
*/
public List<NameValuePair> getResponseHeaders() {
ArrayList<NameValuePair> headers = new ArrayList<NameValuePair>(10);
- for (Entry<String, String[]> entry :
serverConnection.getResponseHeaders().entrySet()) {
+ for (Entry<String, String[]> entry : serverConnection
+ .getResponseHeaders().entrySet()) {
for (String value : entry.getValue()) {
- headers.add(new NameValuePair(entry.getKey(),value));
+ headers.add(new NameValuePair(entry.getKey(), value));
}
- };
+ }
+ ;
return headers;
}
}
\ No newline at end of file