Author: nbelaevski
Date: 2007-04-04 07:57:16 -0400 (Wed, 04 Apr 2007)
New Revision: 51
Added:
trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
Modified:
trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
Log:
MockViewHandler created to handle resource requests in mock env. properly. writeState()
stubbed also
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-03
16:47:13 UTC (rev 50)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-04
11:57:16 UTC (rev 51)
@@ -26,15 +26,10 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Random;
-import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -49,11 +44,9 @@
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.framework.ajax.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
import org.ajax4jsf.framework.ajax.AjaxViewRoot;
import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
import org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl;
-import org.ajax4jsf.framework.resource.FacesResourceContext;
import org.ajax4jsf.framework.resource.InternetResource;
import org.ajax4jsf.framework.resource.InternetResourceBuilder;
import org.ajax4jsf.framework.skin.SkinBean;
@@ -61,14 +54,11 @@
import org.ajax4jsf.framework.skin.VersionBean;
import org.ajax4jsf.framework.util.config.WebXml;
import org.ajax4jsf.tests.org.apache.shale.test.config.ConfigParser;
-import org.apache.commons.httpclient.Header;
import org.apache.shale.test.base.AbstractJsfTestCase;
-import org.apache.shale.test.mock.MockHttpServletResponse;
import org.apache.shale.test.mock.MockPrintWriter;
import org.apache.shale.test.mock.MockResponseWriter;
import org.apache.shale.test.mock.MockServletOutputStream;
-import com.gargoylesoftware.htmlunit.KeyValuePair;
import com.gargoylesoftware.htmlunit.MockWebConnection;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -91,7 +81,7 @@
public class AbstractAjax4JsfTestCase extends AbstractJsfTestCase {
protected final static String SLASHED_RESOURCE_URI_PREFIX = "/" +
WebXml.RESOURCE_URI_PREFIX;
-
+
private File tmpRoot = null;
/**
@@ -122,7 +112,7 @@
ajaxContext = new AjaxContext();
request.setAttribute(AjaxContext.AJAX_CONTEXT_KEY, ajaxContext);
// Setup ViewHandler / ViewRoot.
- application.setViewHandler(new AjaxViewHandler(application.getViewHandler()));
+ application.setViewHandler(new MockViewHandler(application.getViewHandler()));
facesContext.setViewRoot(application.getViewHandler().createView(facesContext,
facesContext.getViewRoot().getViewId()));
// Setup Skin avd version variables.
servletContext.setAttribute("a4j", new VersionBean());
@@ -179,7 +169,7 @@
InternetResourceBuilder.setInstance(null);
}
// setupWebClient();
-
+
ConfigParser parser = new ConfigParser();
parser.parse(parser.getPlatformURLs());
@@ -198,29 +188,29 @@
webClient = new WebClient();
webConnection = new MockWebConnection(webClient) {
public WebResponse getResponse(WebRequestSettings settings)
- throws IOException {
+ throws IOException {
if
(settings.getURL().getFile().startsWith(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX))
{
InternetResource resource = InternetResourceBuilder.getInstance().getResource(
settings.getURL().getFile().substring(AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX.length()));
-
+
final MockFacesResourceContext resourceContext = new
MockFacesResourceContext(facesContext);
resource.sendHeaders(resourceContext);
-
+
return new WebResponseImpl(
new WebResponseData(
resource.getResourceAsStream(resourceContext),
HttpServletResponse.SC_OK,
"OK",
resourceContext.getHeaders()),
- settings.getURL(),
- settings.getSubmitMethod(),
- 0) {
-
+ settings.getURL(),
+ settings.getSubmitMethod(),
+ 0) {
+
public String getContentType() {
return resourceContext.getContentType();
}
};
-
+
} else {
return super.getResponse(settings);
}
Added: trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
(rev 0)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java 2007-04-04 11:57:16
UTC (rev 51)
@@ -0,0 +1,48 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.tests;
+
+import java.io.IOException;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.framework.ajax.AjaxViewHandler;
+
+public class MockViewHandler extends AjaxViewHandler {
+
+ public MockViewHandler(ViewHandler parent) {
+ super(parent);
+ }
+
+ public void writeState(FacesContext context) throws IOException {
+ //System.out.println(".writeState()");
+ }
+
+ public String getResourceURL(FacesContext context, String url) {
+ return url;
+ }
+
+ public String getActionURL(FacesContext context, String url) {
+ return url;
+ }
+}
\ No newline at end of file