Author: ozizka(a)redhat.com
Date: 2009-07-27 22:10:21 -0400 (Mon, 27 Jul 2009)
New Revision: 595
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java
Removed:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java
Log:
* RootNodeTest - Control tab test disabled (Control tab is currently disabled)
Copied: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java (from rev
592, trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java)
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java
(rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/RootNodeTest.java 2009-07-28
02:10:21 UTC (rev 595)
@@ -0,0 +1,380 @@
+package org.jboss.jopr.jsfunit.as5;
+
+import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
+import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
+import com.gargoylesoftware.htmlunit.html.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.UnknownHostException;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.EmbjoprTestCase;
+
+
+/**
+ * Tests the initial screen - the root node's Summary, Metrics and Control tab.
+ *
+ * @author ondra
+ */
+public class RootNodeTest extends EmbjoprTestCase {
+
+ /**
+ * Checks the summary tab contents.
+ */
+ public void testRootNodeSummary() throws EmbJoprTestException {
+
+ try{
+
+ new NavTree().clickRootNode();
+
+ //if( !tabMenu.isTabActive("Summary")) // we can click either
+ tabMenu.clickTab("Summary");
+
+
+ //HtmlElement box = tabMenu.getTabContentBox().getElement();
+
+ helpers.checkSummaryValue( "Name", helpers.getLocalHostName() );
+ // 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( "Architecture",
System.getProperty("os.arch") );
+
+
+ // $ cat /proc/version
+ // Linux version 2.6.18-92.1.18.el5xen (brewbuilder(a)hs20-bc2-4.build.redhat.com) (gcc
version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Wed Nov 5 09:15:48 EST 2009
+
+
+ // $ cat /etc/redhat-release
+ // Red Hat Enterprise Linux Server release 5.2 (Tikanga)
+
+ // 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();
+ assertEquals( rhRelease, distName + " " + distVersion );
+ }
+ catch( IOException ex ){
+ // cat not found or similar.
+ // When file not found, just returns emty string.
+ }*/
+
+
+ }
+ catch( IOException ex ){
+ throw new EmbJoprTestException(ex);
+ }
+
+ }// testSummary()
+
+
+
+ /**
+ * Checks the Metrics tab contents.
+ * Not much to do here - same values as in Summary.
+ */
+ /*public void testMetrics() throws AssertException {
+
+ }/**/
+
+
+
+ /**
+ * Checks the Manual Autorediscovery feature of the Control tab.
+ */
+ public void testRootNodeControlManualAutodiscovery() throws EmbJoprTestException {
+
+ try{
+
+ navTree.clickRootNode();
+
+ if( tabMenu.isTabDisabled("Control") )
+ fail("Root (server) node's Control tab is disabled.");
+
+ tabMenu.clickTab("Control");
+ TabContentBox box = tabMenu.getTabContentBox();
+
+ HtmlButtonInput button = box.getButtonByLabel("Manual Autodiscovery");
+ button.click();
+
+ // TODO: check the result.
+
+ }
+ catch( IOException ex ){
+ throw new EmbJoprTestException(ex);
+ }
+
+ }
+
+
+
+
+ /**
+ * Checks the Manual Autorediscovery feature of the Control tab.
+ */
+ public void XtestRootNodeControlViewProcessList() throws EmbJoprTestException {
+
+ try{
+
+ navTree.clickRootNode();
+
+ if( tabMenu.isTabDisabled("Control") )
+ fail("Root (server) node's Control tab is disabled.");
+
+ tabMenu.clickTab("Control");
+ TabContentBox box = tabMenu.getTabContentBox();
+
+ HtmlButtonInput button = box.getButtonByLabel("View Process List");
+ button.click();
+
+ // TODO: check the result.
+
+ }
+ catch( IOException ex ){
+ throw new EmbJoprTestException(ex);
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+ Helpers helpers = new Helpers();
+
+ /**
+ * Helper mathods for this test.
+ */
+ class Helpers {
+
+
+ /**
+ * Gets the string value from the summary table.
+ * @param name
+ * @return
+ * @throws org.jboss.jopr.jsfunit.AssertException
+ */
+ private String getSummaryValue(String name) throws EmbJoprTestException{
+
+ HtmlElement box = tabMenu.getTabContentBox().getElement();
+ 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.getLastChild().getTextContent().trim();
+ return actualValue;
+
+ }
+
+ private void checkSummaryValue(String name, String expectedValue ) throws
EmbJoprTestException {
+ String actualValue = getSummaryValue(name);
+ assertTrue( String.format("Summary property '%s' doesn't fit -
expected: '%s'; actual: '%s'",
+ name, expectedValue, actualValue),
+ actualValue.trim().endsWith(expectedValue) );
+ }
+
+
+ private String getLocalHostName() throws UnknownHostException {
+ InetAddress addr = InetAddress.getLocalHost();
+ return addr.getHostName();
+ }
+
+ }
+
+
+
+ /**
+ * Intended to read files like "cat /proc/version" etc.
+ * Returns the content of whole file.
+ *
+ * @returns the content of whole file.
+ */
+ private static String executeProcessAndGetOutput( String command ) throws IOException {
+
+ Process exec = Runtime.getRuntime().exec( command );
+ InputStream inputStream = exec.getInputStream();
+ BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(inputStream));
+ StringBuilder sb = new StringBuilder();
+
+ do{
+ String s = bufferedReader.readLine();
+ if( null == s )
+ break;
+ sb.append(s);
+ } while( false );
+
+ return sb.toString();
+
+ }
+
+
+
+
+
+
+
+
+ // TODO: Move to EmbJopr base class? Or make some order there?
+
+
+ private NavTree navTree = new NavTree();
+
+ /**
+ * Inner class to encapsulate navigation tree operations.
+ */
+ class NavTree {
+
+ private void clickRootNode() throws IOException, EmbJoprTestException {
+ DomElement element = (DomElement)client.getElement("navTreeForm");
+ 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();
+ }
+
+ }
+
+
+
+
+
+ private final TabMenu tabMenu = new TabMenu();
+
+ /**
+ * Inner class to encapsulate tab menu operations.
+ */
+ class TabMenu {
+
+ public TabContentBox getTabContentBox() throws EmbJoprTestException {
+
+ HtmlElement contentElement = (HtmlElement) client.getElement("content");
+ HtmlElement tabContentBox = (HtmlElement)
contentElement.getFirstByXPath("div[@class='tabmenubox']");
+ if( null == tabContentBox )
+ throw new EmbJoprTestException("Tab content box not found using
div[@class='tabmenubox'] XPath");
+
+ return new TabContentBox(tabContentBox);
+ }
+
+ public StyledElement getTab( String label ) throws EmbJoprTestException {
+
+ DomElement element = (DomElement)client.getElement("tabmenu");
+ 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("Tab '"+label+" not found using
XPath '"+xPath+"'");
+
+ return tabContent;
+
+ }
+
+ public boolean isTabActive( String label ) throws IOException, EmbJoprTestException {
+
+ StyledElement tabContent = getTab(label);
+ return "span".equals( tabContent.getTagName() )
+ && tabContent.getClassAttribute().contains("active");
+ }
+
+
+ public boolean isTabDisabled( String label ) throws EmbJoprTestException {
+ StyledElement tabContent = getTab(label);
+ return "span".equals( tabContent.getTagName() )
+ && tabContent.getClassAttribute().contains("disabled");
+ }
+
+ public void clickTab( String label ) throws IOException, EmbJoprTestException {
+
+ 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);
+
+ ((ClickableElement)tabContent).click();
+
+ }
+
+ }
+
+
+ /**
+ * Inner class for manipulation with tab content box.
+ */
+ class TabContentBox {
+
+ private HtmlElement box;
+ private URL validForURL;
+ private String validForDate;
+
+ public HtmlElement getElement() { return box; }
+
+
+
+ public TabContentBox(HtmlElement box) {
+ this.box = box;
+
+ // TODO: Check whether the page changed;
+ this.validForDate =
client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
+ this.validForURL = client.getContentPage().getWebResponse().getUrl();
+ }
+
+
+ public void checkIfStillValid() throws ActionOutOfSyncException {
+
+ String validForDate =
client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
+ URL validForURL = client.getContentPage().getWebResponse().getUrl();
+
+ if( !validForDate.equals(this.validForDate) ||
+ !validForURL.equals(this.validForURL) )
+ {
+ throw new ActionOutOfSyncException(
+ "This tab content box was created from another page and is not valid
now.");
+ }
+ }
+
+ public HtmlButtonInput getButtonByLabel( String label )
+ throws HtmlElementNotFoundException, ActionOutOfSyncException {
+
+ checkIfStillValid();
+
+ HtmlButtonInput button =
this.box.getFirstByXPath("//input[@value='"+label+"']");
+ if( null == button )
+ throw new HtmlElementNotFoundException("Button labelled
'"+label+"' not found.");
+
+ return button;
+
+ }
+
+ }
+
+
+
+}
Deleted:
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-07-28
01:02:37 UTC (rev 594)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java 2009-07-28
02:10:21 UTC (rev 595)
@@ -1,380 +0,0 @@
-package org.jboss.jopr.jsfunit.as5;
-
-import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
-import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
-import com.gargoylesoftware.htmlunit.html.*;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.URL;
-import java.net.UnknownHostException;
-import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
-import org.jboss.jopr.jsfunit.EmbjoprTestCase;
-
-
-/**
- * Tests the initial screen - the root node's Summary, Metrics and Control tab.
- *
- * @author ondra
- */
-public class ServerNodeSummaryTest extends EmbjoprTestCase {
-
- /**
- * Checks the summary tab contents.
- */
- public void testRootNodeSummary() throws EmbJoprTestException {
-
- try{
-
- new NavTree().clickRootNode();
-
- //if( !tabMenu.isTabActive("Summary")) // we can click either
- tabMenu.clickTab("Summary");
-
-
- //HtmlElement box = tabMenu.getTabContentBox().getElement();
-
- helpers.checkSummaryValue( "Name", helpers.getLocalHostName() );
- // 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( "Architecture",
System.getProperty("os.arch") );
-
-
- // $ cat /proc/version
- // Linux version 2.6.18-92.1.18.el5xen (brewbuilder(a)hs20-bc2-4.build.redhat.com) (gcc
version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Wed Nov 5 09:15:48 EST 2009
-
-
- // $ cat /etc/redhat-release
- // Red Hat Enterprise Linux Server release 5.2 (Tikanga)
-
- // 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();
- assertEquals( rhRelease, distName + " " + distVersion );
- }
- catch( IOException ex ){
- // cat not found or similar.
- // When file not found, just returns emty string.
- }*/
-
-
- }
- catch( IOException ex ){
- throw new EmbJoprTestException(ex);
- }
-
- }// testSummary()
-
-
-
- /**
- * Checks the Metrics tab contents.
- * Not much to do here - same values as in Summary.
- */
- /*public void testMetrics() throws AssertException {
-
- }/**/
-
-
-
- /**
- * Checks the Manual Autorediscovery feature of the Control tab.
- */
- public void testRootNodeControlManualAutodiscovery() throws EmbJoprTestException {
-
- try{
-
- navTree.clickRootNode();
-
- if( tabMenu.isTabDisabled("Control") )
- fail("Root (server) node's Control tab is disabled.");
-
- tabMenu.clickTab("Control");
- TabContentBox box = tabMenu.getTabContentBox();
-
- HtmlButtonInput button = box.getButtonByLabel("Manual Autodiscovery");
- button.click();
-
- // TODO: check the result.
-
- }
- catch( IOException ex ){
- throw new EmbJoprTestException(ex);
- }
-
- }
-
-
-
-
- /**
- * Checks the Manual Autorediscovery feature of the Control tab.
- */
- public void testRootNodeControlViewProcessList() throws EmbJoprTestException {
-
- try{
-
- navTree.clickRootNode();
-
- if( tabMenu.isTabDisabled("Control") )
- fail("Root (server) node's Control tab is disabled.");
-
- tabMenu.clickTab("Control");
- TabContentBox box = tabMenu.getTabContentBox();
-
- HtmlButtonInput button = box.getButtonByLabel("View Process List");
- button.click();
-
- // TODO: check the result.
-
- }
- catch( IOException ex ){
- throw new EmbJoprTestException(ex);
- }
-
- }
-
-
-
-
-
-
-
-
-
- Helpers helpers = new Helpers();
-
- /**
- * Helper mathods for this test.
- */
- class Helpers {
-
-
- /**
- * Gets the string value from the summary table.
- * @param name
- * @return
- * @throws org.jboss.jopr.jsfunit.AssertException
- */
- private String getSummaryValue(String name) throws EmbJoprTestException{
-
- HtmlElement box = tabMenu.getTabContentBox().getElement();
- 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.getLastChild().getTextContent().trim();
- return actualValue;
-
- }
-
- private void checkSummaryValue(String name, String expectedValue ) throws
EmbJoprTestException {
- String actualValue = getSummaryValue(name);
- assertTrue( String.format("Summary property '%s' doesn't fit -
expected: '%s'; actual: '%s'",
- name, expectedValue, actualValue),
- actualValue.trim().endsWith(expectedValue) );
- }
-
-
- private String getLocalHostName() throws UnknownHostException {
- InetAddress addr = InetAddress.getLocalHost();
- return addr.getHostName();
- }
-
- }
-
-
-
- /**
- * Intended to read files like "cat /proc/version" etc.
- * Returns the content of whole file.
- *
- * @returns the content of whole file.
- */
- private static String executeProcessAndGetOutput( String command ) throws IOException {
-
- Process exec = Runtime.getRuntime().exec( command );
- InputStream inputStream = exec.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(inputStream));
- StringBuilder sb = new StringBuilder();
-
- do{
- String s = bufferedReader.readLine();
- if( null == s )
- break;
- sb.append(s);
- } while( false );
-
- return sb.toString();
-
- }
-
-
-
-
-
-
-
-
- // TODO: Move to EmbJopr base class? Or make some order there?
-
-
- private NavTree navTree = new NavTree();
-
- /**
- * Inner class to encapsulate navigation tree operations.
- */
- class NavTree {
-
- private void clickRootNode() throws IOException, EmbJoprTestException {
- DomElement element = (DomElement)client.getElement("navTreeForm");
- 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();
- }
-
- }
-
-
-
-
-
- private final TabMenu tabMenu = new TabMenu();
-
- /**
- * Inner class to encapsulate tab menu operations.
- */
- class TabMenu {
-
- public TabContentBox getTabContentBox() throws EmbJoprTestException {
-
- HtmlElement contentElement = (HtmlElement) client.getElement("content");
- HtmlElement tabContentBox = (HtmlElement)
contentElement.getFirstByXPath("div[@class='tabmenubox']");
- if( null == tabContentBox )
- throw new EmbJoprTestException("Tab content box not found using
div[@class='tabmenubox'] XPath");
-
- return new TabContentBox(tabContentBox);
- }
-
- public StyledElement getTab( String label ) throws EmbJoprTestException {
-
- DomElement element = (DomElement)client.getElement("tabmenu");
- 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("Tab '"+label+" not found using
XPath '"+xPath+"'");
-
- return tabContent;
-
- }
-
- public boolean isTabActive( String label ) throws IOException, EmbJoprTestException {
-
- StyledElement tabContent = getTab(label);
- return "span".equals( tabContent.getTagName() )
- && tabContent.getClassAttribute().contains("active");
- }
-
-
- public boolean isTabDisabled( String label ) throws EmbJoprTestException {
- StyledElement tabContent = getTab(label);
- return "span".equals( tabContent.getTagName() )
- && tabContent.getClassAttribute().contains("disabled");
- }
-
- public void clickTab( String label ) throws IOException, EmbJoprTestException {
-
- 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);
-
- ((ClickableElement)tabContent).click();
-
- }
-
- }
-
-
- /**
- * Inner class for manipulation with tab content box.
- */
- class TabContentBox {
-
- private HtmlElement box;
- private URL validForURL;
- private String validForDate;
-
- public HtmlElement getElement() { return box; }
-
-
-
- public TabContentBox(HtmlElement box) {
- this.box = box;
-
- // TODO: Check whether the page changed;
- this.validForDate =
client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
- this.validForURL = client.getContentPage().getWebResponse().getUrl();
- }
-
-
- public void checkIfStillValid() throws ActionOutOfSyncException {
-
- String validForDate =
client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
- URL validForURL = client.getContentPage().getWebResponse().getUrl();
-
- if( !validForDate.equals(this.validForDate) ||
- !validForURL.equals(this.validForURL) )
- {
- throw new ActionOutOfSyncException(
- "This tab content box was created from another page and is not valid
now.");
- }
- }
-
- public HtmlButtonInput getButtonByLabel( String label )
- throws HtmlElementNotFoundException, ActionOutOfSyncException {
-
- checkIfStillValid();
-
- HtmlButtonInput button =
this.box.getFirstByXPath("//input[@value='"+label+"']");
- if( null == button )
- throw new HtmlElementNotFoundException("Button labelled
'"+label+"' not found.");
-
- return button;
-
- }
-
- }
-
-
-
-}