[embjopr-commits] EMBJOPR SVN: r147 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Fri Feb 13 07:29:58 EST 2009


Author: ozizka at redhat.com
Date: 2009-02-13 07:29:58 -0500 (Fri, 13 Feb 2009)
New Revision: 147

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java
Log:


Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java	2009-02-13 12:29:16 UTC (rev 146)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java	2009-02-13 12:29:58 UTC (rev 147)
@@ -1,5 +1,8 @@
 package org.jboss.jopr.jsfunit.as5;
 
+import java.io.FileNotFoundException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
 import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
 import com.gargoylesoftware.htmlunit.html.*;
@@ -10,6 +13,7 @@
 import java.net.InetAddress;
 import java.net.URL;
 import java.net.UnknownHostException;
+import org.jboss.jopr.jsfunit.DebugUtils;
 import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
 import org.jboss.jopr.jsfunit.EmbjoprTestCase;
 
@@ -37,9 +41,11 @@
 			//HtmlElement box = tabMenu.getTabContentBox().getElement();
 
 			helpers.checkSummaryValue( "Name", helpers.getLocalHostName() );
-			helpers.checkSummaryValue( "OS Name", System.getProperty("os.name") );
+			// System.getProperty("os.name") // Gives the computer name.
+			//helpers.checkSummaryValue( "OS Name", System.getProperty("os.name") );
+			helpers.checkSummaryValue( "OS Name", executeProcessAndGetOutput("uname") );
 			helpers.checkSummaryValue( "OS Version", System.getProperty("os.version") );
-			helpers.checkSummaryValue( "OS Architecture", System.getProperty("os.arch") );
+			helpers.checkSummaryValue( "Architecture", System.getProperty("os.arch") );
 
 
 			// $ cat /proc/version
@@ -48,7 +54,10 @@
 
 			// $ cat /etc/redhat-release
 			// Red Hat Enterprise Linux Server release 5.2 (Tikanga)
-			try{
+
+			// Commented out - this would only work on Red Hat.
+			// TODO: How to get these values universally?
+			/*try{
 				String rhRelease = executeProcessAndGetOutput("cat /etc/redhat-release");
 				String distName =    helpers.getSummaryValue("Distribution Name").trim();
 				String distVersion = helpers.getSummaryValue("Distribution Version").trim();
@@ -57,8 +66,9 @@
 			catch( IOException ex ){
 				// cat not found or similar.
 				// When file not found, just returns emty string.
-			}
+			}*/
 
+
 		}
 		catch( IOException ex ){
 			throw new EmbJoprTestException(ex);
@@ -89,7 +99,7 @@
 			tabMenu.clickTab("Control");
 			TabContentBox box = tabMenu.getTabContentBox();
 
-			HtmlButton button = box.getButtonByLabel("Manual Autodiscovery");
+			HtmlButtonInput button = box.getButtonByLabel("Manual Autodiscovery");
 			button.click();
 
 			// TODO: check the result.
@@ -115,7 +125,7 @@
 			tabMenu.clickTab("Control");
 			TabContentBox box = tabMenu.getTabContentBox();
 
-			HtmlButton button = box.getButtonByLabel("View Process List");
+			HtmlButtonInput button = box.getButtonByLabel("View Process List");
 			button.click();
 
 			// TODO: check the result.
@@ -150,20 +160,31 @@
 		 * @throws org.jboss.jopr.jsfunit.AssertException
 		 */
 		private String getSummaryValue(String name) throws EmbJoprTestException{
+
+			try {
+				DebugUtils.writeFile("Summary.html", client.getPageAsText());
+			} catch (FileNotFoundException ex) {
+				Logger.getLogger(ServerNodeSummaryTest.class.getName()).log(Level.SEVERE, null, ex);
+			} catch (IOException ex) {
+				Logger.getLogger(ServerNodeSummaryTest.class.getName()).log(Level.SEVERE, null, ex);
+			}
+
 			HtmlElement box = tabMenu.getTabContentBox().getElement();
-			String xPath = "//td/span/strong[contains(string(), '"+name+":')]/ancestor::td[1]";
+			String xPath = "//td//strong[contains(string(), '"+name+":')]/ancestor::td[1]";
 			HtmlElement tableCell = (HtmlElement) box.getFirstByXPath(xPath);
 			if( null == tableCell )
 				throw new EmbJoprTestException("Value for '"+name+"' not found using XPath: "+xPath);
 
-			String actualValue = tableCell.getTextContent();
+			String actualValue = tableCell.getLastChild().getTextContent().trim();
 			return actualValue;
 
 		}
 
 		private void checkSummaryValue(String name, String expectedValue ) throws EmbJoprTestException {
 			String actualValue = getSummaryValue(name);
-			assertTrue( actualValue.trim().endsWith(expectedValue) );
+			assertTrue( "Doesn't fit - expected: '"+expectedValue+"';" +
+							" actual: '"+actualValue+"'",
+							actualValue.trim().endsWith(expectedValue) );
 		}
 
 
@@ -217,9 +238,26 @@
 	 */
 	class NavTree {
 
-		private void clickRootNode() throws IOException {
+		private void clickRootNode() throws IOException, EmbJoprTestException {
 			DomElement element = (DomElement)client.getElement("navTreeForm");
-			HtmlAnchor rootNodeLink = element.getFirstByXPath("//a[@id='navTreeForm:navTree:2::homeLink']");
+			if( null == element )
+				throw new HtmlElementNotFoundException("Can't find #navTreeForm.");
+
+			// ID changes upon core build?
+			//HtmlAnchor rootNodeLink = element.getFirstByXPath("//a[@id='navTreeForm:navTree:2::homeLink']");
+
+			// javax.xml.transform.TransformerException: Can't find function: matches
+			//HtmlAnchor rootNodeLink = element.getFirstByXPath(
+			//				"//a[matches(@id,'^navTreeForm:navTree:.+::homeLink$')]");
+
+
+			String xPath = "//a[ starts-with( @id, 'navTreeForm:navTree:' ) " +
+							           " and contains( @id, '::homeLink' ) ]"; // XPath 2.0: ends-with( @id, '::homeLink' )
+			HtmlAnchor rootNodeLink = element.getFirstByXPath(xPath);
+
+			if( null == rootNodeLink )
+				throw new HtmlElementNotFoundException("Root node not found using XPath: "+xPath);
+
 			rootNodeLink.click();
 		}
 
@@ -239,7 +277,7 @@
 		public TabContentBox getTabContentBox() throws EmbJoprTestException {
 			
 			HtmlElement contentElement = (HtmlElement) client.getElement("content");
-			HtmlElement tabContentBox = (HtmlElement) contentElement.getByXPath("div[@class='tabmenubox']");
+			HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath("div[@class='tabmenubox']");
 			if( null == tabContentBox )
 				throw new EmbJoprTestException("Tab content box not found using div[@class='tabmenubox'] XPath");
 
@@ -249,11 +287,11 @@
 		public StyledElement getTab( String label ) throws EmbJoprTestException {
 
 			DomElement element = (DomElement)client.getElement("tabmenu");
-			StyledElement tabContent = element.getFirstByXPath(
-							"ul/li/span[string()='"+label+"'] | ul/li/a[string()='"+label+"']");
+			String xPath = "ul/li/span[normalize-space(string())='"+label+"'] | ul/li/a[normalize-space(string())='"+label+"']";
+			StyledElement tabContent = element.getFirstByXPath(xPath);
 
 			if( null == tabContent )
-				throw new EmbJoprTestException("No such tab: "+label);
+				throw new EmbJoprTestException("Tab '"+label+" not found using XPath '"+xPath+"'");
 
 			return tabContent;
 
@@ -326,12 +364,12 @@
 			}
 		}
 
-		public HtmlButton getButtonByLabel( String label )
+		public HtmlButtonInput getButtonByLabel( String label )
 						throws HtmlElementNotFoundException, ActionOutOfSyncException {
 
 			checkIfStillValid();
 
-			HtmlButton button = this.box.getFirstByXPath("//input[@value='"+label+"']");
+			HtmlButtonInput button = this.box.getFirstByXPath("//input[@value='"+label+"']");
 			if( null == button )
 				throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
 




More information about the embjopr-commits mailing list