[embjopr-commits] EMBJOPR SVN: r229 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: util and 1 other directory.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Tue Mar 17 12:24:33 EDT 2009


Author: ozizka at redhat.com
Date: 2009-03-17 12:24:33 -0400 (Tue, 17 Mar 2009)
New Revision: 229

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JavaScriptTest.java
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
NavTree.waitUntilReady()

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JavaScriptTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JavaScriptTest.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JavaScriptTest.java	2009-03-17 16:24:33 UTC (rev 229)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jopr.jsfunit;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import java.io.IOException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.lang.ObjectUtils;
+import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
+import org.jboss.jopr.jsfunit.util.DescribedCondition;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
+import org.mozilla.javascript.NativeFunction;
+
+/**
+ * Login test. Makes use of default login in EmbjoprTestCase::setUp()
+ *
+ * @author Stan Silvert
+ */
+public class JavaScriptTest extends EmbjoprTestCase
+{
+
+   /**
+    * @return the suite of tests being tested
+    */
+   public static Test suite() {
+      return new TestSuite( JavaScriptTest.class );
+   }
+
+
+
+   public void testTreeItemLoaded() throws IOException
+   {
+			JavaScriptEngine jse = client.getContentPage().getEnclosingWindow().getWebClient().getJavaScriptEngine();
+
+			log.info( "Script is "+ (jse.isScriptRunning()?"":"not") +" running." );
+
+			Object jsTreeItem = jse.execute((HtmlPage) client.getContentPage(), "Tree.Item", "testTreeItemLoaded", 0);
+			log.info( jsTreeItem.getClass().getName() );
+			log.info( ObjectUtils.toString(jsTreeItem) );
+
+			//org.mozilla.javascript.InterpretedFunction
+			// extends NativeFunction implements Script
+			// extends BaseFunction
+			NativeFunction func = (NativeFunction) jsTreeItem;
+			log.info( "Source: " + func.getEncodedSource() );
+
+
+
+			// JS null object?
+			jsTreeItem = jse.execute((HtmlPage) client.getContentPage(), "null", "testTreeItemLoaded", 0);
+			log.info( jsTreeItem.getClass().getName() );
+			log.info( ObjectUtils.toString(jsTreeItem) );
+
+
+
+
+
+
+			new ActiveConditionChecker( new DescribedCondition("Tree.Item JS object is initialized.") {
+				final EmbJoprTestToolkit selfEjtt = ejtt;
+				public boolean isTrue() throws Exception {
+					Object obj = selfEjtt.getJavaScriptObject("Test.Item");
+					if( null == obj ) return false;
+					//if (	org.mozilla.javascript.NOT_FOUND ) return false;
+					if( ! (obj instanceof NativeFunction ) ) return false;
+					return true;
+				}
+			});
+		
+
+	 }
+
+
+}
\ No newline at end of file

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java	2009-03-17 14:17:59 UTC (rev 228)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java	2009-03-17 16:24:33 UTC (rev 229)
@@ -123,7 +123,7 @@
 
 
 	/**
-	 * Logs in using several
+	 * Logs in using multiple accounts simultaneously.
 	 * @throws java.io.IOException
 	 *
 	 * PASSED.

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-03-17 14:17:59 UTC (rev 228)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-03-17 16:24:33 UTC (rev 229)
@@ -8,12 +8,14 @@
 
 import org.jboss.jopr.jsfunit.exceptions.*;
 import com.gargoylesoftware.htmlunit.html.*;
+import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
 import java.io.IOException;
 import java.net.URL;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.jboss.jopr.jsfunit.AppConstants;
 import org.jboss.jsfunit.jsfsession.*;
+import org.mozilla.javascript.NativeFunction;
 import org.w3c.dom.Element;
 
 
@@ -40,10 +42,12 @@
 		this.selfEjtt = this;
 	}
 
+	public EmbJoprTestToolkit getEjtt(){ return this; }
 
 
 
 
+
 	/**
 	 * Single nav tree instance.
 	 *
@@ -77,6 +81,20 @@
 	public String getDeployDir() {
 		return System.getProperty(AppConstants.SYSPROP_DEPLOY_DIR);
 	}
+
+	public JavaScriptEngine getJavaScriptEngine(){
+		return client.getContentPage().getEnclosingWindow().getWebClient().getJavaScriptEngine();
+	}
+
+	/**
+	 * @returns JavaScript object, as returned by JavaScriptEngine#execute().
+	 */
+	public Object getJavaScriptObject( String jsExpression ){
+		return this.getJavaScriptEngine().execute(
+						(HtmlPage) client.getContentPage(),
+						jsExpression,
+						"testTreeItemLoaded", 0);
+	}
 	
 
 	/**
@@ -224,10 +242,31 @@
         return (ClickableElement)client.getElement(id);
     }
 
+
+		public boolean isReady(){
+			Object obj = getJavaScriptObject("Test.Item");
+			if( null == obj ) return false;
+			//if (	org.mozilla.javascript.NOT_FOUND ) return false;
+			if( ! (obj instanceof NativeFunction ) ) return false;
+			return true;
+		}
+
+		public void waitUntilReady(){
+			final NavTree self = this;
+			new ActiveConditionChecker( new DescribedCondition("Tree.Item JS object is initialized.") {
+				public boolean isTrue() throws Exception {
+					return self.isReady();
+				}
+			});
+		}
+
+
 	}// class NavTree
 
 
 
+
+
 	/**
 	 * Represents nav tree node.
 	 * Contains convenience methods to work with the node.




More information about the embjopr-commits mailing list