Author: nbelaevski
Date: 2008-04-19 16:47:32 -0400 (Sat, 19 Apr 2008)
New Revision: 7958
Added:
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java
Modified:
branches/3.1.x/framework/test/pom.xml
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
branches/3.1.x/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
branches/3.1.x/ui/pom.xml
branches/3.1.x/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SortIconRendererTest.java
Log:
3.1.x unit tests updated
Modified: branches/3.1.x/framework/test/pom.xml
===================================================================
--- branches/3.1.x/framework/test/pom.xml 2008-04-19 15:02:53 UTC (rev 7957)
+++ branches/3.1.x/framework/test/pom.xml 2008-04-19 20:47:32 UTC (rev 7958)
@@ -45,9 +45,9 @@
<version>3.1.5-SNAPSHOT</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>
@@ -73,5 +73,10 @@
<version>2.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.6R7</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified:
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
---
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-04-19
15:02:53 UTC (rev 7957)
+++
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-04-19
20:47:32 UTC (rev 7958)
@@ -187,7 +187,8 @@
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);
+ client.setJavaScriptEngine(new DummyScriptEngine(client));
return client;
}
Copied:
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java
(from rev 7190,
trunk/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java)
===================================================================
--- branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java
(rev 0)
+++
branches/3.1.x/framework/test/src/main/java/org/ajax4jsf/tests/DummyScriptEngine.java 2008-04-19
20:47:32 UTC (rev 7958)
@@ -0,0 +1,67 @@
+/**
+ *
+ */
+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
+ *
+ */
+public class DummyScriptEngine extends JavaScriptEngine {
+
+ public DummyScriptEngine(WebClient webClient) {
+ super(webClient);
+ }
+
+ public Object callFunction(HtmlPage htmlPage, Function function,
+ Context context, Scriptable scope, Scriptable thisObject,
+ Object[] args) {
+ return Boolean.FALSE;
+ }
+
+ public Script compile(HtmlPage htmlPage, String sourceCode,
+ String sourceName, int startLine) {
+ return new Script() {
+ public Object exec(Context arg0, Scriptable arg1) {
+ return Boolean.FALSE;
+ }
+ };
+ }
+
+
+ public Script getCachedScript(WebResponse webResponse) {
+ return null;
+ }
+
+ protected Log getLog() {
+ return null;
+ }
+
+ public void initialize(WebWindow webWindow) {
+ super.initialize(webWindow);
+ }
+
+ public boolean isScriptRunning() {
+ return false;
+ }
+
+ public String preProcess(HtmlPage htmlPage, String sourceCode,
+ String sourceName, HtmlElement htmlElement) {
+ return "";
+ }
+}
Modified:
branches/3.1.x/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
===================================================================
---
branches/3.1.x/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2008-04-19
15:02:53 UTC (rev 7957)
+++
branches/3.1.x/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2008-04-19
20:47:32 UTC (rev 7958)
@@ -83,7 +83,8 @@
// XXX test CurrentDate = null
calendar.setPopup(true);
Calendar calendarObject = Calendar.getInstance();
- calendarObject.set(2001, Calendar.SEPTEMBER, 11);
+ calendarObject.clear();
+ calendarObject.set(2001, Calendar.SEPTEMBER, 11, 10, 12, 1);
calendar.setId("calendar");
calendar.setSubmittedValue(calendarObject.getTime());
form.getChildren().add(calendar);
@@ -95,7 +96,7 @@
calendar2 = (UICalendar) application
.createComponent(UICalendar.COMPONENT_TYPE);
calendar2.setDatePattern("dd/M/yy HH:mm");
- calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36);
+ calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36, 1);
calendar2.setSubmittedValue(calendarObject.getTime());
calendar2.setId("timecalendar");
form.getChildren().add(calendar2);
@@ -119,9 +120,11 @@
.createComponent(UICalendar.COMPONENT_TYPE);
calendar.setLocale(Locale.FRENCH);
Calendar calendarObject = Calendar.getInstance();
+ calendarObject.clear();
calendarObject.set(2007, Calendar.JUNE, 10);
Calendar preloadRangeBegin = Calendar.getInstance();
+ preloadRangeBegin.clear();
preloadRangeBegin.setTime(calendar
.getDefaultPreloadBegin(calendarObject.getTime()));
assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
@@ -129,6 +132,7 @@
assertEquals(1, preloadRangeBegin.get(Calendar.DATE));
Calendar preloadRangeEnd = Calendar.getInstance();
+ preloadRangeEnd.clear();
preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject
.getTime()));
assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR));
@@ -163,6 +167,7 @@
.createComponent(UICalendar.COMPONENT_TYPE);
calendar.setLocale(Locale.FRENCH);
Calendar calendarObject = Calendar.getInstance();
+ calendarObject.clear();
calendarObject.set(2007, Calendar.JUNE, 10);
calendar.setCurrentDate(calendarObject.getTime());
@@ -229,7 +234,8 @@
public void testCalendarDecode() throws Exception {
Calendar calendarObject = Calendar.getInstance();
- calendarObject.set(2001, Calendar.SEPTEMBER, 11);
+ calendarObject.clear();
+ calendarObject.set(2001, Calendar.SEPTEMBER, 11, 10, 12, 1);
calendar.decode(facesContext);
assertEquals(calendarObject.getTime(), calendar.getSubmittedValue());
calendarObject.set(2002, Calendar.SEPTEMBER, 11, 1, 1, 1);
@@ -292,7 +298,8 @@
Date time = (Date) calendar2.getValue();
Calendar calendarObject = Calendar.getInstance();
- calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36);
+ calendarObject.clear();
+ calendarObject.set(2001, Calendar.SEPTEMBER, 11, 13, 36, 01);
assertEquals(calendarObject.getTime(), calendar2.getSubmittedValue());
}
Modified: branches/3.1.x/ui/pom.xml
===================================================================
--- branches/3.1.x/ui/pom.xml 2008-04-19 15:02:53 UTC (rev 7957)
+++ branches/3.1.x/ui/pom.xml 2008-04-19 20:47:32 UTC (rev 7958)
@@ -143,12 +143,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>htmlunit</groupId>
- <artifactId>htmlunit</artifactId>
- <version>1.10</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
Modified:
branches/3.1.x/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SortIconRendererTest.java
===================================================================
---
branches/3.1.x/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SortIconRendererTest.java 2008-04-19
15:02:53 UTC (rev 7957)
+++
branches/3.1.x/ui/scrollableDataTable/src/test/java/org/richfaces/renderkit/html/SortIconRendererTest.java 2008-04-19
20:47:32 UTC (rev 7958)
@@ -83,40 +83,34 @@
* Test method for
* {@link
org.richfaces.renderkit.html.SortIconRenderer#renderAscIcon(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)}.
*/
- public final void testRenderAscIcon() {
+ public final void testRenderAscIcon() throws Exception {
UIComponent component = new UIColumn();
- try {
- setupResponseWriter();
- renderer.renderAscIcon(facesContext, component);
- HtmlPage page = processResponseWriter();
-
- Iterator elementIterator = page.getAllHtmlChildElements();
-
- HtmlElement div = null;
-
- while(elementIterator.hasNext()) {
- HtmlElement node = (HtmlElement) elementIterator.next();
- if (node.getNodeName().equalsIgnoreCase("div")) {
- div = node;
- }
+ setupResponseWriter();
+ renderer.renderAscIcon(facesContext, component);
+ HtmlPage page = processResponseWriter();
+
+ Iterator elementIterator = page.getAllHtmlChildElements();
+
+ HtmlElement div = null;
+
+ while(elementIterator.hasNext()) {
+ HtmlElement node = (HtmlElement) elementIterator.next();
+ if (node.getNodeName().equalsIgnoreCase("div")) {
+ div = node;
}
-
- assertNotNull(div);
-
- String className = div.getAttributeValue("class");
-
- assertNotNull(className);
-
- assertEquals("dr-sdt-sort-asc", className);
-
- } catch (Exception e) {
- fail(e.getMessage());
}
-
+
+ assertNotNull(div);
+
+ String className = div.getAttributeValue("class");
+
+ assertNotNull(className);
+
+ assertEquals("dr-sdt-sort-asc", className);
}
- public void testRenderFacet() {
+ public void testRenderFacet() throws Exception {
UIComponent component = new UIColumn();
UIOutput output = new UIOutput() {
public String getRendererType() {
@@ -133,55 +127,43 @@
component.getFacets().put("ascIcon", output);
- try {
- setupResponseWriter();
- renderer.renderAscIcon(facesContext, component);
- HtmlPage htmlPage = processResponseWriter();
-
- HtmlElement element = htmlPage.getHtmlElementById("test_div_0");
- assertNotNull(element);
- assertEquals("div", element.getNodeName());
-
- } catch (Exception e) {
- fail(e.getMessage());
- }
-
-
+ setupResponseWriter();
+ renderer.renderAscIcon(facesContext, component);
+ HtmlPage htmlPage = processResponseWriter();
+
+ HtmlElement element = htmlPage.getHtmlElementById("test_div_0");
+ assertNotNull(element);
+ assertEquals("div", element.getNodeName());
}
/**
* Test method for
* {@link
org.richfaces.renderkit.html.SortIconRenderer#renderDescIcon(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)}.
*/
- public final void testRenderDescIcon() {
+ public final void testRenderDescIcon() throws Exception {
UIComponent component = new UIColumn();
- try {
- setupResponseWriter();
- renderer.renderDescIcon(facesContext, component);
- HtmlPage page = processResponseWriter();
-
- Iterator elementIterator = page.getAllHtmlChildElements();
-
- HtmlElement div = null;
-
- while(elementIterator.hasNext()) {
- HtmlElement node = (HtmlElement) elementIterator.next();
- if (node.getNodeName().equalsIgnoreCase("div")) {
- div = node;
- }
+ setupResponseWriter();
+ renderer.renderDescIcon(facesContext, component);
+ HtmlPage page = processResponseWriter();
+
+ Iterator elementIterator = page.getAllHtmlChildElements();
+
+ HtmlElement div = null;
+
+ while(elementIterator.hasNext()) {
+ HtmlElement node = (HtmlElement) elementIterator.next();
+ if (node.getNodeName().equalsIgnoreCase("div")) {
+ div = node;
}
-
- assertNotNull(div);
-
- String className = div.getAttributeValue("class");
-
- assertNotNull(className);
-
- assertEquals("dr-sdt-sort-desc", className);
-
- } catch (Exception e) {
- fail(e.getMessage());
}
+
+ assertNotNull(div);
+
+ String className = div.getAttributeValue("class");
+
+ assertNotNull(className);
+
+ assertEquals("dr-sdt-sort-desc", className);
}
}