[embjopr-commits] EMBJOPR SVN: r592 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5/app/ear and 3 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Mon Jul 27 20:53:07 EDT 2009


Author: ozizka at redhat.com
Date: 2009-07-27 20:53:07 -0400 (Mon, 27 Jul 2009)
New Revision: 592

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
 * Fixed NavTreeNode#expand() - was not refreshing underlying HTML element.
 * Ear and War tests prepared for HTMLUnit 2.4+


Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java	2009-07-27 21:33:27 UTC (rev 591)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java	2009-07-28 00:53:07 UTC (rev 592)
@@ -49,6 +49,10 @@
 	// Operations
 	public static final String OPERATION_OUTPUT_PROPERTY = "Output";
 
+
+	// Test files - EARs, JARs, WARs, etc...
+	public static final String JBCACHE_TEST_EAR = "JBossCacheTest-by-fdrabek.ear";
+
 }// interface
 
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java	2009-07-27 21:33:27 UTC (rev 591)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java	2009-07-28 00:53:07 UTC (rev 592)
@@ -876,7 +876,7 @@
 			page = (HtmlPage) page.refresh();
 
 			// Get the counter number.
-			Integer count1 = NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+			Integer count1 = NumberUtils.createInteger(( (HtmlElement)page.getBody().getHtmlElementById("count") ).getTextContent());
 
 
 
@@ -913,7 +913,7 @@
       assertTrue(page.asText().contains("HELLO WORLD"));
 
 			// Get the counter number.
-			Integer count2 = NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+			Integer count2 = NumberUtils.createInteger(( (HtmlElement)page.getBody().getHtmlElementById("count") ).getTextContent());
 
 			assertTrue( "Counter is reset upon app restart, thus should be lower after.", count1 > count2 );
 
@@ -971,7 +971,7 @@
 			page = (HtmlPage) page.refresh();
 
 			// Get the counter number.
-			Integer count1 = NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+			Integer count1 = NumberUtils.createInteger(( (HtmlElement) page.getBody().getHtmlElementById("count") ).getTextContent());
 
 
 
@@ -995,7 +995,7 @@
       assertTrue(page.asText().contains("HELLO WORLD"));
 
 			// Get the counter number.
-			Integer count2 = NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+			Integer count2 = NumberUtils.createInteger(( (HtmlElement) page.getBody().getHtmlElementById("count") ).getTextContent());
 
 			assertTrue( "Counter is reset upon app restart, thus should be lower after.", count1 > count2 );
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java	2009-07-27 21:33:27 UTC (rev 591)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java	2009-07-28 00:53:07 UTC (rev 592)
@@ -1007,7 +1007,7 @@
 			page = (HtmlPage) page.refresh();
 
 			// Get the counter number.
-			String count1text = page.getBody().getHtmlElementById("count").getTextContent();
+			String count1text = ( (HtmlElement) page.getBody().getHtmlElementById("count") ).getTextContent();
 			Integer count1 = NumberUtils.createInteger( count1text );
 
 
@@ -1045,7 +1045,7 @@
       assertTrue(page.asText().contains("HELLO WORLD"));
 
 			// Get the counter number.
-			String count2text = page.getBody().getHtmlElementById("count").getTextContent();
+			String count2text = ( (HtmlElement) page.getBody().getHtmlElementById("count") ).getTextContent();
 			Integer count2 = NumberUtils.createInteger( count2text );
 
 			assertTrue( "Counter is reset upon app restart, thus should be lower after. " +
@@ -1102,7 +1102,7 @@
 			page = (HtmlPage) page.refresh();
 
 			// Get the counter number.
-			String count1text = page.getBody().getHtmlElementById("count").getTextContent();
+			String count1text = ( (HtmlElement) page.getBody().getHtmlElementById("count") ).getTextContent();
 			Integer count1 = NumberUtils.createInteger( count1text );
 
 
@@ -1126,7 +1126,7 @@
       assertTrue(page.asText().contains("HELLO WORLD"));
 
 			// Get the counter number.
-			String count2text = page.getBody().getHtmlElementById("count").getTextContent();
+			String count2text = ( (HtmlElement) page.getBody().getHtmlElementById("count") ).getTextContent();
 			Integer count2 = NumberUtils.createInteger( count2text );
 
 			assertTrue( "Counter is reset upon app restart, thus should be lower after. " +

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java	2009-07-27 21:33:27 UTC (rev 591)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheCacheTest.java	2009-07-28 00:53:07 UTC (rev 592)
@@ -1,5 +1,6 @@
 package org.jboss.jopr.jsfunit.as5.jbcache;
 
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -8,16 +9,19 @@
 import java.util.Properties;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
 import org.jboss.qa.jbcache.testear.*;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
+import org.jboss.jopr.jsfunit.DebugUtils;
 import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
 import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
 import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTable;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTableRow;
 import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NavTreeNode;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NodeFinder;
 
 /**
  *
@@ -98,13 +102,21 @@
 		CollectionUtils.addAll(names, subnodesNames);
 
 		// Remove the names which we find.
-		List<NavTreeNode> children = haparNode.getChildren();
+		haparNode = ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION);
+		List<NavTreeNode> children = haparNode.getChildren( /*new NodeFinder() {
+			public HtmlTable getNodeElem(EmbJoprTestToolkit ejtt) throws HtmlElementNotFoundException {
+				return (HtmlTable) ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).getElement();
+			}
+		}*/);
+
+		haparNode = ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION);
 		for( NavTreeNode node : children ){
+			log.info("Found node: "+node.getName());
 			names.remove( node.getName() );
 		}
 		// The remaining names are missing.
 		if( names.size() > 0 ){
-			throw new EmbJoprTestException("These cache nodes are not present: "+StringUtils.join(names, ", "));
+			throw new EmbJoprTestException("These cache nodes are not present: "+StringUtils.join(names, ", "), this);
 		}
 
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java	2009-07-27 21:33:27 UTC (rev 591)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jbcache/JBossCacheInterceptorTest.java	2009-07-28 00:53:07 UTC (rev 592)
@@ -23,6 +23,11 @@
 	public void testJBossCacheInterceptorSummary() throws IOException, EmbJoprTestException {
 		if( isJBossConfigWithoutCache() ) return;
 
+
+
+		ejtt.deployment.deployViaEmbJopr( DeployableTypes.EAR, ejtt.getTestFilePath(this.APP_TYPE, JBCACHE_TEST_EAR));
+
+
 		ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
 		ejtt.navTree.getNodeByLabel(SUBNODE_INTERCEPTOR).click();
 
@@ -48,6 +53,10 @@
 		props.setProperty("Average Read Time", "0.0ms");
 		ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValues(props);
 
+
+		ejtt.deployment.undeployViaEmbJopr( DeployableTypes.EAR, JBCACHE_TEST_EAR );
+
+
 	}
 
 

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-07-27 21:33:27 UTC (rev 591)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-07-28 00:53:07 UTC (rev 592)
@@ -29,6 +29,10 @@
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.collections.Closure;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.collections.functors.ClosureTransformer;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.jboss.jopr.jsfunit.AppConstants;
@@ -85,6 +89,11 @@
 	private EmbjoprTestCase currentTest = null;
 
 
+
+
+
+
+	
 	/**
 	 * ProfileService references.
 	 */
@@ -121,6 +130,10 @@
 		return System.getProperty(AppConstants.SYSPROP_TESTDATA_DIR);
 	}
 
+	public String getTestFilePath( DeployableTypes location, String fileName ){
+		return this.getTestDataDir()+"/"+location.getDataDir()+"/"+fileName;
+	}
+
 	public String getTempDir() {
 		return System.getProperty(AppConstants.SYSPROP_TEMP_DIR);
 	}
@@ -180,9 +193,15 @@
 	}
 
 
+	/** Dumps the page to target directory as a HTML file. */
+	public void dumpPage( String fileName ) throws IOException {
+		DebugUtils.writeFile("target/"+fileName, this.client.getPageAsText());
+	}
 
 
 
+
+
 	/**
 	 * Inner class to encapsulate navigation tree operations.
 	 *
@@ -444,12 +463,36 @@
 
 		/**
 		 * If the node is collapsed, expand it.
+		 * Calls #expand( NodeFinder ) using a finder which looks for a node with the same name as this one.
+		 *
 		 * @returns true if the node already was expanded.
 		 */
-		public boolean expand() throws EmbJoprTestException, IOException{
+		public boolean expand() throws EmbJoprTestException, IOException {
+			final String nodeName = this.getName();
+			return expand( new NodeFinder() {
+				public HtmlTable getNodeElem(EmbJoprTestToolkit ejtt) throws HtmlElementNotFoundException {
+					return (HtmlTable) ejtt.navTree.getNodeByLabel( nodeName ).getElement();
+				}
+			});
+		}
+
+		/**
+		 * If the node is collapsed, expand it.
+		 * Expanding a node causes AJAX call which renders old HTML element stale.
+		 * Thus, upon expanding, element must be re-bound. That's what the NodeFinder is for.
+		 * 
+		 * @returns true if the node already was expanded.
+		 */
+		public boolean expand( NodeFinder finder ) throws EmbJoprTestException, IOException{
+
+			// null finder -> use default finder.
+			if( null == finder)
+				return expand();
+
 			boolean isExpanded = isExpanded();
 			if( !isExpanded ){
 				this.getArrowLink().click();
+				this.elem = finder.getNodeElem(selfEjtt);
 			}
 			return isExpanded;
 		}
@@ -503,11 +546,27 @@
 		private final String XPATH_CHILD_NODES = "./following-sibling::div[contains(@id, ':childs') and position()=1]/table";
 
 		public List<NavTreeNode> getChildren() throws EmbJoprTestException, IOException{
+			return getChildren(null);
+		}
+
+		public List<NavTreeNode> getChildren( NodeFinder finder ) throws EmbJoprTestException, IOException{
 			if( ! this.isExpandable() )
 				return Collections.EMPTY_LIST;
-			this.expand();
+			this.expand( finder );
 
-			List<NavTreeNode> childNodes = (List<NavTreeNode>) this.elem.getByXPath(XPATH_CHILD_NODES);
+			List<HtmlTable> tables = (List<HtmlTable>) this.elem.getByXPath(XPATH_CHILD_NODES);
+			
+			/*List<NavTreeNode> childNodes = (List<NavTreeNode>) CollectionUtils.collect(tables, new Transformer() {
+				public Object transform(Object input) {
+					return new NavTreeNode( (HtmlTable)input );
+				}
+			});/**/
+
+			List<NavTreeNode> childNodes = new ArrayList<NavTreeNode>();
+			for (HtmlTable htmlTable : tables) {
+				childNodes.add( new NavTreeNode(htmlTable) );
+			}
+
 			return childNodes;
 		}
 
@@ -515,12 +574,15 @@
 	}// class NavTreeNode()
 
 
+	/** Interface to reload a nav tree node after reloading operation (including AJAX calls). */
+	public interface NodeFinder {
+		public HtmlTable getNodeElem( EmbJoprTestToolkit ejtt ) throws HtmlElementNotFoundException;
+	}
 
 
 
 
 
-
 	/**
 	 * Inner class to encapsulate tab menu operations.
 	 */



More information about the embjopr-commits mailing list