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

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Thu Feb 19 21:07:08 EST 2009


Author: ozizka at redhat.com
Date: 2009-02-19 21:07:08 -0500 (Thu, 19 Feb 2009)
New Revision: 160

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
Log:
 * "EmbJopr TestKit" tested, fixed, some javadoc added.
 * EarTest.java fixed, also demonstrates how to use test kit.

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-02-20 02:07:08 UTC (rev 160)
@@ -153,16 +153,25 @@
 	}
 
 
+	public void announceCurrentTest(){
+		log.info( " --------  Test: "+DebugUtils.getCurrentMethodFullName()+"  -------- ");
+	}
 
 
 
 
+
+
 	
 
 
 	/* ---- Copied from ServerNodeSummaryTest.java, before moving to EmbjoprTestCase.java --- */
 
 
+
+
+
+
 	/**
 	 * Single nav tree instance.
 	 * 
@@ -181,20 +190,22 @@
 	 */
 	protected class NavTree {
 
+		public static final String ID_NAV_TREE_FORM = "navTreeForm";
+
 		private void clickRootNode() throws IOException, EmbJoprTestException {
-			DomElement element = (DomElement)client.getElement("navTreeForm");
+			DomElement element = (DomElement)client.getElement(ID_NAV_TREE_FORM);
 			if( null == element )
-				throw new HtmlElementNotFoundException("Can't find #navTreeForm.");
+				throw new HtmlElementNotFoundException("Can't find #"+ID_NAV_TREE_FORM+".");
 
 			// ID changes upon core build?
-			//HtmlAnchor rootNodeLink = element.getFirstByXPath("//a[@id='navTreeForm:navTree:2::homeLink']");
+			//HtmlAnchor rootNodeLink = element.getFirstByXPath(".//a[@id='navTreeForm:navTree:2::homeLink']");
 
+			// No XSLT 2.0 support :(
 			// javax.xml.transform.TransformerException: Can't find function: matches
 			//HtmlAnchor rootNodeLink = element.getFirstByXPath(
-			//				"//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
+			//				".//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
 
-
-			String xPath = "//a[ starts-with( @id, 'navTreeForm:navTree:' ) " +
+			String xPath = ".//a[ starts-with( @id, '"+ID_NAV_TREE_FORM+":navTree:' ) " +
 							           " and contains( @id, '::homeLink' ) ]"; // XPath 2.0: ends-with( @id, '::homeLink' )
 			HtmlAnchor rootNodeLink = element.getFirstByXPath(xPath);
 
@@ -205,13 +216,27 @@
 		}
 
 
-		public NavTreeNode getNodeByLabel( String label ){
+		/**
+		 * Finds the nav tree node by it's link label.
+		 *
+		 * @param label
+		 * @return
+		 * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+		 *         when there's no node with given label.
+		 */
+		public NavTreeNode getNodeByLabel( String label ) throws HtmlElementNotFoundException{
 			
-			DomElement element = (DomElement)client.getElement("navTreeForm");
+			DomElement navTreeForm = (DomElement)client.getElement(ID_NAV_TREE_FORM);
 
 			// A table which has an anchor containing given text.
-			String xPath = "//table[//a[contains(@id,'typeSummaryLink') and string() = '"+label+"']]";
-			HtmlTable nodeTable = element.getFirstByXPath( xPath );
+			// Note: Different node types have different id endings - typeSummaryLink, categorySummaryLink, ...
+			String xPath = ".//table[.//td[contains(@id,':text')]//a[contains(@id,'SummaryLink') and normalize-space() = '"+label+"']]";
+
+			HtmlTable nodeTable = navTreeForm.getFirstByXPath( xPath );
+
+			if( null == nodeTable )
+				throw new HtmlElementNotFoundException("Node '"+label+"' not found using XPath: "+xPath);
+
 			return new NavTreeNode(nodeTable);
 
 		}
@@ -219,10 +244,11 @@
 		
     /**
      * Need a standard JSFUnit API to replace this code.
+		 * @see getNodeByLabel().getLabelLink()
      */
     public HtmlAnchor getNodeLink(String linkLabel)
     {
-        return getLinkInsideForm("navTreeForm", linkLabel);
+        return getLinkInsideForm(ID_NAV_TREE_FORM, linkLabel);
     }
 
 
@@ -231,6 +257,7 @@
      * given by resourceName. This method is used to expand tree nodes
      * (eg. "Web Applications (WAR)", "Datasources", etc.) in the
      * navigation tree.
+		 * @see getNodeByLabel().getArrowLink()
      */
     public ClickableElement getNodeArrow(String resourceName)
 		{
@@ -244,26 +271,10 @@
         return (ClickableElement)client.getElement(id);
     }
 
+	}// class NavTree
 
-		// TODO: DRY - see NavTreeNode::isExpanded()
-		public boolean isNodeExpanded( String linkLabel ) throws EmbJoprTestException
-		{
-			ClickableElement nodeArrow = getNodeArrow(linkLabel);
 
-			HtmlElement img = (HtmlElement)nodeArrow.getFirstByXPath("img[@style='display: none;']");
 
-			if( img.getId().endsWith("expanded") )
-				return false;
-			else if( img.getId().endsWith("collapsed") )
-				return true;
-			else
-				throw new EmbJoprTestException("Can't determine whether nav tree node is expanded.");
-
-		}
-
-	}// class NavTree
-
-
 	/**
 	 * Represents nav tree node.
 	 * Contains convenience methods to work with the node.
@@ -278,7 +289,7 @@
 			this.elem = nodeTable;
 		}
 
-
+		/** Returns true if this node is expanded. */
 		public boolean isExpanded() throws EmbJoprTestException
 		{
 			HtmlAnchor arrowLink = this.getArrowLink();
@@ -293,17 +304,20 @@
 			
 		}
 
+		/** Returns the text link of this node. */
 		public HtmlAnchor getLabelLink(){
 			// Until I come up with something smarter, let it be so:
-			String xPath = "//td[contains(@id,':text')]/a";
+			String xPath = ".//td[contains(@id,':text')]/a";
 			return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
 		}
 
+		/** Returns the arrow's link. */
 		public HtmlAnchor getArrowLink(){
-			String xPath = "//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
+			String xPath = ".//td[contains(@id,':handles')]//a[contains(@id,':handle')]";
 			return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
 		}
 
+		/** Clicks the link of the this node. */
 		public void click() throws IOException {
 			this.getLabelLink().click();
 		}
@@ -331,7 +345,7 @@
 			return new TabContentBox(tabContentBox);
 		}
 
-		public ClickableElement getTab( String label ) throws EmbJoprTestException {
+		public ClickableElement getTab( String label ) throws HtmlElementNotFoundException {
 
 			DomElement element = (DomElement)client.getElement("tabmenu");
 			String xPath = "ul/li/span[normalize-space(string())='"+label+"'] | ul/li/a[normalize-space(string())='"+label+"']";
@@ -339,36 +353,33 @@
 
 
 			if( null == tabContent )
-				throw new EmbJoprTestException("Tab '"+label+" not found using XPath '"+xPath+"'");
+				throw new HtmlElementNotFoundException("Tab '"+label+" not found using XPath '"+xPath+"'");
 
 			return tabContent;
 
 		}
 
-		public boolean isTabActive( String label ) throws IOException, EmbJoprTestException {
+		/** Returns true if the tab with given label is active (it's content is shown). */
+		public boolean isTabActive( String label ) throws IOException, HtmlElementNotFoundException {
 
 			StyledElement tabContent = getTab(label);
 			return "span".equals( tabContent.getTagName() )
 							&& tabContent.getClassAttribute().contains("active");
 		}
 
-
-		public boolean isTabDisabled( String label ) throws EmbJoprTestException {
+		/** Returns true if the tab with given label is disabled (grayed and can't be activated). */
+		public boolean isTabDisabled( String label ) throws HtmlElementNotFoundException {
 			StyledElement tabContent = getTab(label);
 			return "span".equals( tabContent.getTagName() )
 							&& tabContent.getClassAttribute().contains("disabled");
 		}
 
-		public void clickTab( String label ) throws IOException, EmbJoprTestException {
+		/** Shotcut -  getTab(label).click(); Not necesarilly clicks an anchor. */
+		public void clickTab( String label ) throws IOException, ActionNotAvailableException, HtmlElementNotFoundException {
 
 			StyledElement tabContent = getTab(label);
-
-			//if( !"a".equals( tabContent.getTagName() ) )
-			//if( !( tabContent instanceof HtmlAnchor ) )
-			//	throw new AssertException("Tab is not an anchor: "+label);
-
 			if( !( tabContent instanceof ClickableElement ) )
-				throw new EmbJoprTestException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
+				throw new ActionNotAvailableException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
 
 			((ClickableElement)tabContent).click();
 
@@ -440,7 +451,7 @@
 		{
 			checkIfStillValid();
 
-			String xPath = "*[contains(string(), '"+headerText+"']/following::table";
+			String xPath = "*[contains(normalize-space(), '"+headerText+"')]/following::table";
 			// [@id='resourceSummaryForm:dataTable'] - is this reliable?
 			HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
 			return new ContentTable(tableElement);
@@ -459,7 +470,7 @@
 
 			checkIfStillValid();
 
-			HtmlButtonInput button = this.element.getFirstByXPath("//input[@value = '"+label+"']");
+			HtmlButtonInput button = this.element.getFirstByXPath(".//input[normalize-space(@value)='"+label+"']");
 			if( null == button )
 				throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
 
@@ -506,7 +517,7 @@
 
 			// TODO: Escape the single quotes. By doubling?
 			// http://books.google.com/books?id=jzqFMlM0gb0C&pg=PA308&lpg=PA308&dq=xquery+escape+quote&source=bl&ots=DIKQ92AhHh&sig=A7adGlif6jfYKtJXGc4eZbXYeCQ&hl=cs&ei=LYCcSYKLO5ir-gazwfjtBA&sa=X&oi=book_result&resnum=8&ct=result
-			String xPath = "//tr[contains(string(), '"+text+"')]";
+			String xPath = ".//tr[contains(string(), '"+text+"')]";
 			HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
 			if( null == elm )
 				throw new HtmlElementNotFoundException(xPath);
@@ -519,7 +530,7 @@
 			if( 0 == element.getRowCount() )
 				throw new HtmlElementNotFoundException("Table has no rows.");
 
-			String xPath = "//tr[//a[string() = '"+linkLabel+"']]";
+			String xPath = ".//tr[//a[normalize-space()='"+linkLabel+"']]";
 			HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
 			if( null == elm )
 				throw new HtmlElementNotFoundException(xPath);
@@ -538,7 +549,7 @@
 			/**/ // Give it another chance, JavaScript could change it.
 
 			// Get all TH from the first THEAD row that contains TH.
-			String xPath = "/thead/tr[th and pos()=0]/th";
+			String xPath = "./thead/tr[th and position()=1]/th";
 			List<HtmlTableHeaderCell> colHeaders = (List<HtmlTableHeaderCell>) this.element.getByXPath(xPath);
 
 			if( 0 == colHeaders.size() ){
@@ -605,14 +616,14 @@
 
 		/**
 		 * Finds a <button> or <input type="button"> with the given label.
-		 * @param label The label of the button. Compared to a [trimmed] label text of the button.
+		 * @param label The label of the button. Compared to a trimmed label text of the button.
 		 * @returns the button element - either HtmlButtonInput or HtmlButton.
 		 * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
 		 */
 		public ClickableElement getButtonByLabel( String label ) throws HtmlElementNotFoundException
 		{
-			String xPath = "//input[@type='button' and @value = '"+label+"']" +
-							" || //button[ string() = '"+label+"']";
+			String xPath = ".//input[@type='button' and normalize-space(@value) = '"+label+"']" +
+							" || .//button[normalize-space() = '"+label+"']";
 			HtmlElement elm = this.element.getFirstByXPath(xPath);
 			if( null == elm )
 				throw new HtmlElementNotFoundException("Can't find the button using xPath: "+xPath);
@@ -636,7 +647,7 @@
 		{
 			HtmlTableCell cell = this.getCellByColumnName(colName);
 
-			String xPath = "//a";
+			String xPath = ".//a";
 			HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
 
 			if( null == link )
@@ -651,7 +662,7 @@
 		 * @param string
 		 */
 		public HtmlAnchor getLinkByLabel(String linkLabel) throws HtmlElementNotFoundException {
-			String xPath = "//a[string()='"+linkLabel+"']";
+			String xPath = ".//a[normalize-space()='"+linkLabel+"']";
 			HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
 			if( null == link )
 				throw new HtmlElementNotFoundException(xPath);
@@ -672,17 +683,19 @@
 			return cell;
 		}
 
+		/**
+		 * Returns  this row's cell element from the column with specified name.
+		 * @param colName  Name of the column.
+		 * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+		 *         if no such column exists in the table.
+		 */
 		public HtmlTableCell getCellByColumnName( String colName ) throws HtmlElementNotFoundException
 		{
-			if( null == this.containingTable.colIndexes ){
-				//throw new HtmlElementNotFoundException("Table does not have columns analyzed yet.");
-				this.containingTable.analyzeColumns();
-			}
-			
-			int index = this.containingTable.colIndexes.get(colName);
+			int index = this.containingTable.getColumnIndexByName(colName);
 			return getCell(index);
 		}
 
+		/**  Shortcut - returns text content of this row's cell from given column. */
 		public String getCellTextByColumnName( String colName ) throws HtmlElementNotFoundException {
 			return this.getCellByColumnName(colName).getTextContent();
 		}

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-02-20 02:07:08 UTC (rev 160)
@@ -72,9 +72,9 @@
     {
 
 				// Announce this test in the JBoss log.
-			  log.info("================================================");
+			  log.info("==================================================================");
 			  log.info("  Setting up test "+this.getClass().getName());
-			  log.info("================================================");
+			  log.info("==================================================================");
 
 
 				// JVM version
@@ -104,6 +104,14 @@
         this.server = jsfSession.getJSFServerSession(); 
 
     }
+
+		@Override
+		protected void tearDown() throws Exception {
+			// Denounce this test in the JBoss log.
+			log.info("------  END OF TEST "+this.getClass().getName()+" -------");
+		}
+
+
 		
     /**
      * Need a standard JSFUnit API to replace this code

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java	2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/HelloJoprTest.java	2009-02-20 02:07:08 UTC (rev 160)
@@ -111,6 +111,7 @@
       client.click("createContentForm:addButton");
       
       // assert that the success message appeared on the client side
+			DebugUtils.writeFile("hello.html", client.getPageAsText());
       assertTrue(client.getPageAsText().contains("hellothere.war created successfully"));
       
       // assert text and sevrity level for FacesMessage on server side

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java	2009-02-19 23:40:21 UTC (rev 159)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java	2009-02-20 02:07:08 UTC (rev 160)
@@ -27,6 +27,7 @@
 import java.io.IOException;
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import org.jboss.jopr.jsfunit.exceptions.ActionNotAvailableException;
 import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
 import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
 import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
@@ -114,6 +115,7 @@
 		
 	}
 
+
 	/**
 	 * assertion:
 	  
@@ -128,8 +130,9 @@
 	 * @param earFilePath
 	 * @throws java.io.IOException
 	 */
-	public void testNavigationToEar() throws IOException, HtmlElementNotFoundException, ActionOutOfSyncException
+	public void testNavigationToEar() throws IOException, HtmlElementNotFoundException, ActionOutOfSyncException, ActionNotAvailableException
 	{
+		announceCurrentTest();
 
 		NavTreeNode nodeServers = navTree.getNodeByLabel("JBossAS Servers");
 		nodeServers.click();
@@ -180,6 +183,8 @@
 		{
 			// Whooo-hooo! So much to click through!
 
+			tabMenu.clickTab("Summary");
+
 			// TODO: Pagination options: EMBJOPR-78
 			// resourceDataScroller.xhtml, TableManager.java, "pageSizes".
 
@@ -197,6 +202,7 @@
 
 
 		{
+			// Go back to applications Sumary screen.
 			navTree.getNodeByLabel("Applications").click();
 		}
 		// --- click ---
@@ -214,7 +220,6 @@
 	}// testNavigationToEar()
 
 
-
 	private void deployEar( String earFilePath ) throws IOException
 	{
 

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/ActionNotAvailableException.java	2009-02-20 02:07:08 UTC (rev 160)
@@ -0,0 +1,30 @@
+package org.jboss.jopr.jsfunit.exceptions;
+
+/**
+ * Signalizes that there was an action performed
+ * that was out of context - e.g. clicking on a button
+ * that was a part of a HTML page that's already gone.
+ *
+ *
+ * @author ondra
+ */
+public class ActionNotAvailableException extends EmbJoprTestException {
+
+	public ActionNotAvailableException() {
+	}
+
+	public ActionNotAvailableException(String message) {
+		super(message);
+	}
+
+	public ActionNotAvailableException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+	public ActionNotAvailableException(Throwable cause) {
+		super(cause);
+	}
+
+	
+
+}




More information about the embjopr-commits mailing list