[embjopr-commits] EMBJOPR SVN: r477 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5/connectors and 1 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Thu May 21 16:38:42 EDT 2009


Author: ozizka at redhat.com
Date: 2009-05-21 16:38:41 -0400 (Thu, 21 May 2009)
New Revision: 477

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connectors/
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connectors/ConnectorsTest.java
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
EJTT updated - added few methods to NavTreeLabel class.
Created ConnectorTests.

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connectors/ConnectorsTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connectors/ConnectorsTest.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/connectors/ConnectorsTest.java	2009-05-21 20:38:41 UTC (rev 477)
@@ -0,0 +1,77 @@
+package org.jboss.jopr.jsfunit.as5.connectors;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.jboss.jopr.jsfunit.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
+
+
+
+
+public class ConnectorsTest extends EmbjoprTestCase implements AppConstants {
+
+
+	/**
+	 * @return the suite of tests being tested
+	 */
+	public static Test suite() {
+		return new TestSuite(ConnectorsTest.class);
+	}
+
+
+	/**
+	 * This test asummes that HTTP and AJP connectors are present, like in the default AS config.
+	 */
+	public void testConnectorHttp() throws IOException, EmbJoprTestException
+	{
+		// Expand the Connectors node and click it.
+		ejtt.navTree.getNodeByLabel(NAV_JBOSS_WEB).getArrowLink().click();
+		ejtt.navTree.waitUntilNodeLoadedByAjax(NAV_CONNECTORS, 1000, 6);
+		ejtt.navTree.getNodeByLabel(NAV_CONNECTORS).getLabelLink().click();
+
+		ContentTable connList = ejtt.tabMenu.getTabContentBox().getFirstTable();
+
+		// HTTP
+		ContentTableRow rowHttp = connList.getFirstRowContainingText("http://");
+		if( null == rowHttp )
+			throw new EmbJoprTestException("HTTP connector not listed.", this);
+		String status = rowHttp.getCellTextByColumnName("Status");
+		if( ! "UP".equals(status) )
+			throw new EmbJoprTestException("HTTP connector is not UP, but: "+status);
+
+		// AJP
+		ContentTableRow rowAjp  = connList.getFirstRowContainingText("ajp://");
+		if( null == rowAjp )
+			throw new EmbJoprTestException("AJP connector not listed.", this);
+		status = rowAjp.getCellTextByColumnName("Status");
+		if( ! "UP".equals(status) )
+			throw new EmbJoprTestException("AJP connector is not UP, but: "+status);
+
+
+		// Get all children nodes
+		ejtt.navTree.getNodeByLabel(NAV_CONNECTORS).expand();
+		List<NavTreeNode> childNodes = ejtt.navTree.getNodeByLabel(NAV_CONNECTORS).getChildren();
+
+		// They all should have a name in the form of URL.
+		// So take the protocol part and put it in a set.
+		Set<String> presentNodeNames = new HashSet(childNodes.size());
+		for (NavTreeNode navTreeNode : childNodes) {
+			String nodeLabel = navTreeNode.getLabelLink().getTextContent().trim();
+			URL url = new URL(nodeLabel);
+			presentNodeNames.add(url.getProtocol());
+		}
+
+		assertTrue( "Connectors node should contain a subnode for AJP protocol.", presentNodeNames.contains("ajp") );
+		assertTrue( "Connectors node should contain a subnode for HTTP protocol.", presentNodeNames.contains("http") );
+
+	}
+
+
+}// class
+

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-05-21 15:51:42 UTC (rev 476)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-05-21 20:38:41 UTC (rev 477)
@@ -398,6 +398,18 @@
 
 		}
 
+		/**
+		 * If the node is collapsed, expand it.
+		 * @returns true if the node already was expanded.
+		 */
+		public boolean expand() throws EmbJoprTestException, IOException{
+			boolean isExpanded = isExpanded();
+			if( !isExpanded ){
+				this.getArrowLink().click();
+			}
+			return isExpanded;
+		}
+
 		/** Returns the text link of this node. */
 		public HtmlAnchor getLabelLink(){
 			// Until I come up with something smarter, let it be so:
@@ -405,21 +417,57 @@
 			return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
 		}
 
+
+		private final String XPATH_ARROW_LINK = ".//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
+
 		/** Returns the arrow's link. */
+		public HtmlAnchor findArrowLink(){
+			HtmlAnchor arrowLink = (HtmlAnchor) this.elem.getFirstByXPath( XPATH_ARROW_LINK );
+			return arrowLink;
+		}
 		public HtmlAnchor getArrowLink() throws HtmlElementNotFoundException{
-			String xPath = ".//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
-			HtmlAnchor arrowLink = (HtmlAnchor) this.elem.getFirstByXPath( xPath );
-			if( null == arrowLink )
-				throw new HtmlElementNotFoundException("Arrow link not found using XPath: "+xPath, currentTest);
+			HtmlAnchor arrowLink = this.findArrowLink();
+			if( null == arrowLink ){
+				throw new HtmlElementNotFoundException("Arrow link not found using XPath: "+XPATH_ARROW_LINK, currentTest);
+			}
 			return arrowLink;
 		}
 
+
 		/** Clicks the link of the this node. */
 		public void click() throws IOException {
 			this.getLabelLink().click();
 		}
 
+		
+		public boolean isExpandable() {
+			if( null == this.findArrowLink() )
+				return false;
+			else
+				return true;
+		}
 
+		// Note: The div is present even for empty nodes.
+		private final String XPATH_CHILDREN_DIV = "./following-sibling::div[contains(@id, ':childs')]";
+
+		public boolean hasChildren() throws EmbJoprTestException, IOException {
+			// Let's rely on the arrow, which's presence is a sign of having children.
+			return this.isExpandable();
+		}
+
+
+		private final String XPATH_CHILD_NODES = "./following-sibling::div[contains(@id, ':childs') and position()=1]/table";
+
+		public List<NavTreeNode> getChildren() throws EmbJoprTestException, IOException{
+			if( ! this.isExpandable() )
+				return Collections.EMPTY_LIST;
+			this.expand();
+
+			List<NavTreeNode> childNodes = (List<NavTreeNode>) this.elem.getByXPath(XPATH_CHILD_NODES);
+			return childNodes;
+		}
+
+
 	}// class NavTreeNode()
 
 




More information about the embjopr-commits mailing list