Author: konstantin.mishin
Date: 2009-08-18 09:13:17 -0400 (Tue, 18 Aug 2009)
New Revision: 15199
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/javascript/
root/framework/trunk/impl/src/test/java/org/richfaces/javascript/QUnitTest.java
Modified:
root/framework/trunk/impl/src/test/resources/javascript/4_0_0.html
Log:
RFPL-59
Added: root/framework/trunk/impl/src/test/java/org/richfaces/javascript/QUnitTest.java
===================================================================
--- root/framework/trunk/impl/src/test/java/org/richfaces/javascript/QUnitTest.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/javascript/QUnitTest.java 2009-08-18
13:13:17 UTC (rev 15199)
@@ -0,0 +1,107 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - 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.richfaces.javascript;
+
+import static org.junit.Assert.fail;
+
+import java.net.URL;
+import java.util.Iterator;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.AlertHandler;
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlListItem;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ *
+ * @version $Revision$
+ * @author Konstantin Mishin
+ */
+public class QUnitTest {
+
+ private WebClient webClient_;
+
+ @Before
+ public void setUp() {
+ webClient_ = new WebClient();
+ webClient_.setAlertHandler(new AlertHandler() {
+ public void handleAlert(Page page, String message) {
+ System.out.println(" .handleAlert() " + message);
+ }
+ });
+ }
+
+ @After
+ public void tearDown() {
+ webClient_.closeAllWindows();
+ webClient_ = null;
+ }
+
+ protected void runTest(URL url) throws Exception {
+ HtmlPage page = loadPage(url);
+ HtmlElement doc = page.getDocumentElement();
+ HtmlElement tests = (HtmlElement) doc.getElementById("tests");
+ Iterator<HtmlElement> iter = tests.getChildElements().iterator();
+ if (!iter.hasNext()) {
+ fail("No result found");
+ }
+ StringBuilder sb = new StringBuilder();
+ int i = 1;
+ while (iter.hasNext()) {
+ final HtmlListItem testNode = (HtmlListItem) iter.next();
+ if (testNode.getAttribute("class").contains("fail")) {
+ sb.append(i).append(".
").append(testNode.<HtmlElement>getFirstByXPath("./strong").getFirstChild().getTextContent()).append("\n");
+ int j = 1;
+ for(HtmlElement li :
testNode.<HtmlElement>getFirstByXPath("./ol").getChildElements()) {
+ if (li.getAttribute("class").contains("fail")) {
+ sb.append(" ").append(j).append(".
").append(li.getTextContent()).append("\n");
+ }
+ j++;
+ }
+ }
+ i++;
+ }
+ if(sb.length() > 0) {
+ fail("Failures:\n" + sb + "User Agent: " +
doc.getElementById("userAgent").getTextContent());
+ }
+ }
+
+ protected HtmlPage loadPage(URL url) throws Exception {
+ HtmlPage page = webClient_.getPage(url);
+ webClient_.waitForBackgroundJavaScriptStartingBefore(4 * 60 * 1000);
+ return page;
+ }
+
+ /**
+ * @throws Exception if an error occurs
+ */
+ @Test
+ public void test() throws Exception {
+
runTest(getClass().getClassLoader().getResource("javascript/4_0_0.html"));
+ }
+}
Modified: root/framework/trunk/impl/src/test/resources/javascript/4_0_0.html
===================================================================
--- root/framework/trunk/impl/src/test/resources/javascript/4_0_0.html 2009-08-18 12:27:36
UTC (rev 15198)
+++ root/framework/trunk/impl/src/test/resources/javascript/4_0_0.html 2009-08-18 13:13:17
UTC (rev 15199)
@@ -11,7 +11,7 @@
<script type="text/javascript">
var jsf = {};
jQuery(document).ready(function(){
- test("RichFaces.submitForm", function() {
+ test("RichFaces.submitForm test", function() {
expect(7);
var submitTarget = "target";
var submitParameters = {
@@ -32,14 +32,25 @@
form.trigger = trigger;
ok(!form.attr("target"));
ok(!jQuery("input", form).size());
- return false;
});
test("RichFaces.log test", function() {
- ok(false, "Not yet implemented");
- // RichFaces.console.error("some error");
- // equals(RichFaces.getValue(["prop1", "prop2"], base),
"value2");
- // equals(RichFaces.getValue(["prop3", "prop2"], base),
undefined);
+ expect(8);
+ var log = jQuery("#richfaces\\.log");
+ equals(log.size(), 0);
+ RichFaces.log.error("some error");
+ RichFaces.log.info("some info");
+ log = jQuery("#richfaces\\.log");
+ equals(log.find("div").size(), 2);
+ equals(log.find("div:contains('some error')").size(), 1);
+ equals(log.find("div:contains('some info')").size(), 1);
+ RichFaces.log.setLevel("error");
+ equals(log.find("div").size(), 0);
+ RichFaces.log.error("some error");
+ RichFaces.log.info("some info");
+ equals(log.find("div").size(), 1);
+ equals(log.find("div:contains('some error')").size(), 1);
+ equals(log.find("div:contains('some info')").size(), 0);
});
test("RichFaces.getValue test", function() {
@@ -119,7 +130,7 @@
request : function(source, event, options) {
equals(source, ajaxSource);
equals(event, ajaxEvent);
- equals(options, ajaxOptions);
+ same(options, ajaxOptions);
}
}
RichFaces.ajax(ajaxSource, ajaxEvent, ajaxOptions);