Author: maksimkaszynski
Date: 2008-03-25 12:18:15 -0400 (Tue, 25 Mar 2008)
New Revision: 7190
Added:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/HtmlTestUtils.java
Modified:
trunk/framework/test/pom.xml
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java
Log:
http://jira.jboss.com/jira/browse/RF-2726
Modified: trunk/framework/test/pom.xml
===================================================================
--- trunk/framework/test/pom.xml 2008-03-25 16:18:04 UTC (rev 7189)
+++ trunk/framework/test/pom.xml 2008-03-25 16:18:15 UTC (rev 7190)
@@ -52,9 +52,9 @@
<version>1.2_07</version>
</dependency>
<dependency>
- <groupId>htmlunit</groupId>
+ <groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
- <version>1.10</version>
+ <version>1.14</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-03-25
16:18:04 UTC (rev 7189)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-03-25
16:18:15 UTC (rev 7190)
@@ -29,9 +29,11 @@
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.List;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -47,15 +49,16 @@
import javax.faces.render.Renderer;
import javax.servlet.http.HttpServletResponse;
-import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.context.AjaxContextImpl;
import org.ajax4jsf.renderkit.AjaxViewRootRenderer;
import org.ajax4jsf.renderkit.ChameleonRenderKitImpl;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.resource.InternetResource;
import org.ajax4jsf.resource.InternetResourceBuilder;
import org.ajax4jsf.tests.org.apache.shale.test.config.ConfigParser;
import org.ajax4jsf.webapp.WebXml;
+import org.apache.commons.lang.StringUtils;
import org.apache.shale.test.base.AbstractJsfTestCase;
import org.apache.shale.test.mock.MockApplication;
import org.apache.shale.test.mock.MockPrintWriter;
@@ -73,6 +76,7 @@
import com.gargoylesoftware.htmlunit.WebResponseData;
import com.gargoylesoftware.htmlunit.WebResponseImpl;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
/**
* Base class for testing components and renderers in a4j framework
@@ -147,7 +151,7 @@
// Setup ViewHandler / ViewRoot.
application.setViewHandler(new MockViewHandler(application.getViewHandler()));
- UIViewRoot root = new AjaxViewRoot();
+ UIViewRoot root = new MockViewRoot();
root.setViewId("/viewId");
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
@@ -225,8 +229,9 @@
protected WebClient createWebClient() {
WebClient client = new WebClient();
//disable javascript for now as HtmlUnit doesn't treat prototype.js well
- client.setJavaScriptEnabled(false);
-
+ client.setJavaScriptEnabled(true);
+ //Set dummy script engine to prevent NPEs from default HtmlUnit engine
+ client.setJavaScriptEngine(new DummyScriptEngine(client));
return client;
}
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java
(rev 0)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java 2008-03-25
16:18:15 UTC (rev 7190)
@@ -0,0 +1,79 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+import org.apache.commons.logging.Log;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.Script;
+import org.mozilla.javascript.Scriptable;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.WebWindow;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+
+/**
+ * Dummy implementation of script engine. It really does nuthin.
+ * Always returns empty strings.
+ * @author Maksim Kaszynski
+ *
+ */
+@SuppressWarnings("serial")
+public class DummyScriptEngine extends JavaScriptEngine {
+
+ public DummyScriptEngine(WebClient webClient) {
+ super(webClient);
+ }
+
+ @Override
+ public Object callFunction(HtmlPage htmlPage, Function function,
+ Context context, Scriptable scope, Scriptable thisObject,
+ Object[] args) {
+ return false;
+ }
+
+ @Override
+ public Script compile(HtmlPage htmlPage, String sourceCode,
+ String sourceName, int startLine) {
+ return new Script() {
+ public Object exec(Context arg0, Scriptable arg1) {
+ return false;
+ }
+ };
+ }
+
+
+ @Override
+ public Script getCachedScript(WebResponse webResponse) {
+ return null;
+ }
+
+ @Override
+ protected Log getLog() {
+ return null;
+ }
+
+ @Override
+ public void initialize(WebWindow webWindow) {
+ super.initialize(webWindow);
+ }
+
+ @Override
+ public boolean isScriptRunning() {
+ return false;
+ }
+
+ @Override
+ public String preProcess(HtmlPage htmlPage, String sourceCode,
+ String sourceName, HtmlElement htmlElement) {
+ return "";
+ }
+
+
+
+
+}
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/HtmlTestUtils.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/HtmlTestUtils.java
(rev 0)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/HtmlTestUtils.java 2008-03-25
16:18:15 UTC (rev 7190)
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.apache.commons.lang.StringUtils;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public final class HtmlTestUtils {
+ private HtmlTestUtils() {
+ }
+
+ /**
+ * Extract list of all <script> elements' src attributes
+ * @param page
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public static List<String> extractScriptSources(HtmlPage page) {
+ List<HtmlScript> list =
+ page.getDocumentHtmlElement().getHtmlElementsByTagName(HTML.SCRIPT_ELEM);
+ List<String> sources = new ArrayList<String>();
+ for (HtmlScript htmlScript : list) {
+ String srcAttribute = htmlScript.getSrcAttribute();
+ if (StringUtils.isNotBlank(srcAttribute)) {
+ sources.add(srcAttribute);
+ }
+ }
+ return sources;
+ }
+
+
+}
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java 2008-03-25
16:18:04 UTC (rev 7189)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java 2008-03-25
16:18:15 UTC (rev 7190)
@@ -67,7 +67,7 @@
*/
@Override
public void setValue(ELContext context, Object value) {
- // TODO Auto-generated method stub
+ o = value;
}