EMBJOPR SVN: r216 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5.
by embjopr-commits@lists.jboss.org
Author: charles.crouch(a)jboss.com
Date: 2009-03-12 16:34:17 -0400 (Thu, 12 Mar 2009)
New Revision: 216
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
use LinkedHashMap for metrics we are comparing so we have a specified order in which the metrics are checked
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-03-12 20:32:49 UTC (rev 215)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-03-12 20:34:17 UTC (rev 216)
@@ -509,7 +509,7 @@
performDatasourceOperation(propertiesMap.get("jndi-name"), DatasourceType.XA_DATASOURCE, "Flush");
// Make sure the metrics are updated appropriately
- Map<String, String> expectedMetrics = new HashMap<String, String>();
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
expectedMetrics.put("Available Connection Count", "15.0");
expectedMetrics.put("Connection Count", "0.0");
expectedMetrics.put("Connection Created Count", "0.0");
@@ -569,7 +569,7 @@
performDatasourceOperation(propertiesMap.get("jndi-name"), DatasourceType.LOCAL_TX_DATASOURCE, "Flush");
// Make sure the metrics are updated appropriately
- Map<String, String> expectedMetrics = new HashMap<String, String>();
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
expectedMetrics.put("Available Connection Count", "20.0");
expectedMetrics.put("Connection Count", "0.0");
expectedMetrics.put("Connection Created Count", "0.0");
@@ -799,7 +799,7 @@
Map<String, String> propertiesMap = createLocalTXDatasource("MetricsCreateDS");
// Set up the expected values
- Map<String, String> expectedMetrics = new HashMap<String, String>();
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
expectedMetrics.put("Available Connection Count", "20.0");
expectedMetrics.put("Connection Count", "0.0");
expectedMetrics.put("Connection Created Count", "0.0");
@@ -856,7 +856,7 @@
assertNotNull(con);
// Set up the expected values
- Map<String, String> expectedMetrics = new HashMap<String, String>();
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
expectedMetrics.put("Available Connection Count", "19.0");
expectedMetrics.put("Connection Count", "5.0");
expectedMetrics.put("Connection Created Count", "5.0");
@@ -913,7 +913,7 @@
propertiesMap.get("password"));
// Set up the expected values
- Map<String, String> expectedMetrics = new HashMap<String, String>();
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
expectedMetrics.put("Available Connection Count", "14.0");
expectedMetrics.put("Connection Count", "6.0");
expectedMetrics.put("Connection Created Count", "6.0");
@@ -974,7 +974,7 @@
disconnectDB(connections.get(1));
// Set up the expected values
- Map<String, String> expectedMetrics = new HashMap<String, String>();
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
expectedMetrics.put("Available Connection Count", "17.0");
expectedMetrics.put("Connection Count", "3.0");
expectedMetrics.put("Connection Created Count", "5.0");
15 years, 10 months
EMBJOPR SVN: r215 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
by embjopr-commits@lists.jboss.org
Author: charles.crouch(a)jboss.com
Date: 2009-03-12 16:32:49 -0400 (Thu, 12 Mar 2009)
New Revision: 215
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
Log:
actually use the connection
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-03-11 21:38:40 UTC (rev 214)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-03-12 20:32:49 UTC (rev 215)
@@ -291,7 +291,10 @@
String password) throws Exception{
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:" + jndiName);
- return ds.getConnection(username, password);
+ Connection con = ds.getConnection(username, password);
+ // actually exercise the connection
+ con.getMetaData();
+ return con;
}
/**
15 years, 10 months
EMBJOPR SVN: r214 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-11 17:38:40 -0400 (Wed, 11 Mar 2009)
New Revision: 214
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
Rewritten EAR test to comply current AS state.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-11 21:12:25 UTC (rev 213)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-11 21:38:40 UTC (rev 214)
@@ -104,11 +104,13 @@
MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
Set mBeans = jmxServer.queryNames(objName, null);
if (mBeans.size() != 1) {
+ log.info(mBeanName+" not found.");
return false;
}
ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
// Returns org.jboss.deployers.spi.DeploymentState.
Object state = jmxServer.getAttribute(deploymentMBean, "State");
+ log.info("State is '"+state.toString()+"'.");
return "DEPLOYED".equals(state.toString()) || "3".equals(state.toString());
}
@@ -117,7 +119,8 @@
public boolean isEJBDeployed(String ejbJarName) throws RuntimeException
{
try {
- String mBeanName = "jboss.j2ee:module=\""+ejbJarName+"\",service=EjbModule";
+ //String mBeanName = "jboss.j2ee:module=\""+ejbJarName+"\",service=EjbModule";
+ String mBeanName = "jboss.j2ee:module=\""+ejbJarName+"\",*";
return isMBeanStateDeployedByQuery(mBeanName);
}
catch (Exception e) {
@@ -145,8 +148,11 @@
public boolean isEarDeployed(String earName) throws RuntimeException
{
try {
- String query = "jboss.deployment:id=\"vfszip:" +
- System.getProperty("jsfunit.deploy.dir") + "/" + earName + "\",*";
+ //String query = "jboss.deployment:id=\"vfszip:" +
+ // System.getProperty("jsfunit.deploy.dir") + "/" + earName + "/\",*";
+ String query = String.format("jboss.deployment:id=\"vfszip:%s/%s/\",*",
+ System.getProperty("jsfunit.deploy.dir"), earName );
+
return isMBeanStateDeployedByQuery(query);
}
catch (Exception e) {
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-11 21:12:25 UTC (rev 213)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-11 21:38:40 UTC (rev 214)
@@ -28,6 +28,8 @@
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
+import org.jboss.jopr.jsfunit.util.DescribedCondition;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
@@ -134,6 +136,7 @@
+
/**
* Tests Applications listing.
* Creates a list of all apps listed,
@@ -186,9 +189,9 @@
}// testNavigationToApplications()
-
+
/**
* Determines the type of the deployable based on the value
* in the Type column in EmbJopr.
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-03-11 21:12:25 UTC (rev 213)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-03-11 21:38:40 UTC (rev 214)
@@ -100,6 +100,8 @@
checkClientAndServerMessages(expectedMessage, expectedMessage, false);
// Use JMX to assert that the EAR components really did deploy successfully.
+ //id="vfszip:/home/brq/ozizka/JoprEmbedded/jboss-as-5.x/build/output/jboss-5.1.0.Beta1/server/default/deploy/eardeployment.ear/",type=Deployment
+ //id="vfszip:/home/ondra/work/JOPRembedded/embjopr-svn-trunk/jsfunit/target/jboss5x/deploy/eardeployment.ear",* not found.
assertTrue("JMX doesn't report EAR as deployed: eardeployment.ear", isEarDeployed(BASIC_EAR));
assertTrue("JMX doesn't report EJB sessiona.jar as deployed.", isEJBDeployed("sessiona.jar"));
assertTrue("JMX doesn't report EJB sessionb.jar as deployed.", isEJBDeployed("sessionb.jar"));
@@ -301,8 +303,8 @@
return null != earRow;
}
}).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(2000, 5);
+
-
ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
// Wait until the Status is "UP".
@@ -396,6 +398,7 @@
* @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
*
* PASSED.
+ * Now fails, because EAR does not appear.
*/
public void testDeployUnpackedEar() throws IOException, EmbJoprTestException {
@@ -404,9 +407,11 @@
// Deploy the unpacked EAR.
// We have to use hotdeploy - can't upload a directory.
+ log.info("Unzipping ear/"+EAR_UNPACKED_ZIP);
unzipToDeployDir("ear/"+EAR_UNPACKED_ZIP, "");
// Loop, wait for the app to appear.
- waitActivelyForDeployment( DeployableTypes.EAR, EAR_UNPACKED, 5000, 18 );
+ log.info("Waiting for EAR to appear.");
+ waitActivelyForDeployment( DeployableTypes.EAR, EAR_UNPACKED, 5000, 12 );
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
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-03-11 21:12:25 UTC (rev 213)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ServerNodeSummaryTest.java 2009-03-11 21:38:40 UTC (rev 214)
@@ -161,14 +161,6 @@
*/
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//strong[contains(string(), '"+name+":')]/ancestor::td[1]";
HtmlElement tableCell = (HtmlElement) box.getFirstByXPath(xPath);
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java 2009-03-11 21:12:25 UTC (rev 213)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java 2009-03-11 21:38:40 UTC (rev 214)
@@ -43,7 +43,7 @@
if( this.dumpPageOnTimout ){
try {
// Since this is still inner class, we could use 'this'.
- //DebugUtils.writeFile(test.getName() + ".html", test.getClient().getPageAsText());///
+ DebugUtils.writeFile("target/"+test.getName()+".html", test.getClient().getPageAsText());///
} catch (Exception ex) { log.error("Can't dump page.", ex); }
}
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-03-11 21:12:25 UTC (rev 213)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-11 21:38:40 UTC (rev 214)
@@ -236,7 +236,7 @@
public boolean isExpanded() throws EmbJoprTestException
{
HtmlAnchor arrowLink = this.getArrowLink();
- HtmlElement img = (HtmlElement)arrowLink.getFirstByXPath("img[@style='display: none;']");
+ HtmlElement img = (HtmlElement)arrowLink.getFirstByXPath("img[contains(@style,'display: none')]");
if( img.getId().endsWith("expanded") )
return false;
15 years, 10 months
EMBJOPR SVN: r212 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-11 14:41:25 -0400 (Wed, 11 Mar 2009)
New Revision: 212
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
Log:
Added testMultipleSuccessiveLogins(), trying to trigger EMBJOPR-92
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java 2009-03-11 17:26:01 UTC (rev 211)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/MultipleUserLoginTest.java 2009-03-11 18:41:25 UTC (rev 212)
@@ -25,20 +25,11 @@
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.*;
-import java.io.BufferedReader;
-import java.io.FileReader;
import java.io.IOException;
-import java.io.StringReader;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.xerces.xni.parser.XMLDocumentFilter;
-import org.apache.xerces.xni.parser.XMLInputSource;
-import org.cyberneko.html.HTMLConfiguration;
-import org.cyberneko.html.filters.DefaultFilter;
-import org.cyberneko.html.filters.Writer;
import org.jboss.jsfunit.framework.WebClientSpec;
import org.jboss.jsfunit.framework.WebConversationFactory;
import org.jboss.jsfunit.jsfsession.JSFClientSession;
@@ -69,7 +60,9 @@
private static final String LABEL_LOGOUT = "Logout";
- public void XsetUp() throws IOException
+
+ /** Disabled, second login solved using HTMLUnit. */
+ public void DISABLEDsetUp() throws IOException
{
// Announce this test in the JBoss log.
@@ -92,6 +85,7 @@
// Contrary to super class, this test skips the session creation in setUp().
}
+ /**/
/**
* Instance of JSF session. Keeps server and client session parts, and user's name and pass.
@@ -175,8 +169,8 @@
// Refresh and log USER_A out.
- ((HtmlPage) client.getContentPage()).refresh();
- byte[] responseBBody = client.getContentPage().getWebResponse().getResponseBody();
+ //((HtmlPage) client.getContentPage()).refresh();
+ //byte[] responseBBody = client.getContentPage().getWebResponse().getResponseBody();
HtmlAnchor logoutLink = (HtmlAnchor) client.getElement("logoutLink");
logoutLink.click();
@@ -193,8 +187,46 @@
+ /**
+ * Perhaps reveals EMBJOPR-92 - Nav tree is not filled right after login
+ */
+ public void testMultipleSuccessiveLogins() throws IOException
+ {
+ final WebClient wc = new WebClient(BrowserVersion.FIREFOX_3);
+ wc.setThrowExceptionOnFailingStatusCode(false);
+ wc.setConfirmHandler(new SimpleConfirmHandler(true));
+ final WebClientTools clientTools = new WebClientTools(wc);
+ final String userNameComponent = "login_form:name";
+ final String passwordComponent = "login_form:password";
+ final String submitComponent = "login_form:submit";
+ final String url = WebConversationFactory.getWARURL() + "/";
+
+ int retries = 10;
+
+ while( retries-- > 0 ) {
+
+ log.info("Logging in, "+retries+" logins remaining after this one.");
+
+ // Login
+ HtmlPage loginPage = wc.getPage(url);
+ setValue(loginPage, userNameComponent, USER_B);
+ setValue(loginPage, passwordComponent, PASS_B);
+ clickSubmitComponent(loginPage, submitComponent);
+
+
+ String pageBText = clientTools.getPageAsText();
+ assertTrue("Page doesn't contain user's name.", pageBText.contains(USER_B) );
+ assertTrue("Page doesn't contain '"+LABEL_LOGOUT+"'.", pageBText.contains(LABEL_LOGOUT) );
+
+ // Logout
+ HtmlAnchor logoutLink = (HtmlAnchor) clientTools.getElement("logoutLink");
+ logoutLink.click();
+ }
+ }
+
+
// These were taken from FomrAuthenticationStrategy.java; unfortunately not reusable from there.
15 years, 10 months
EMBJOPR SVN: r211 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-11 13:26:01 -0400 (Wed, 11 Mar 2009)
New Revision: 211
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
Added NavTree.waitUntilLoaded()
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-03-11 16:43:42 UTC (rev 210)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-11 17:26:01 UTC (rev 211)
@@ -28,6 +28,7 @@
protected JSFClientSession client;
protected JSFServerSession server;
+ private EmbJoprTestToolkit selfEjtt; // For closures.
public JSFClientSession getClient() { return client; }
public JSFServerSession getServer() { return server; }
@@ -36,6 +37,7 @@
public EmbJoprTestToolkit(JSFClientSession client, JSFServerSession server) {
this.client = client;
this.server = server;
+ this.selfEjtt = this;
}
@@ -67,10 +69,17 @@
+ /**
+ * Reloads the current page.
+ */
+ private void refreshPage() throws IOException {
+ ((HtmlPage)client.getContentPage()).refresh();
+ }
+
/**
* Inner class to encapsulate navigation tree operations.
*
@@ -107,10 +116,29 @@
}
- public void waitForNavTreeLoaded(){
- sleep(1500);///
- // TODO: Use ActiveConditionChecker
+
+ /**
+ * Waits
+ * @param msInterval Milliseconds to wait between tries.
+ * @param retries Number of retries. Total time = (retries - 1) * msInterval.
+ * @throws java.lang.Exception Whatever exception is thrown from the isTrue() method.
+ * @throws org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException
+ * when max number of retries was reached.
+ */
+ public void waitUntilLoaded( int msInterval, int retries ) throws Exception {
+ final NavTree self = this;
+ //final EmbJoprTestToolkit ejtt = client;
+ new ActiveConditionChecker( new DescribedCondition("Nav tree contains Applications node.") {
+ int callsMade = 0;
+ public boolean isTrue() throws HtmlElementNotFoundException, IOException {
+ // Refresh the page if this is not the first call.
+ if( callsMade++ > 0 )
+ selfEjtt.refreshPage();
+ // If found, return true.
+ return null != self.findNodeByLabel("Applications");
+ }
+ }).throwOnTimeout().waitWithTimeout(1000, 3);
}
15 years, 10 months
EMBJOPR SVN: r210 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-11 12:43:42 -0400 (Wed, 11 Mar 2009)
New Revision: 210
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
Added NavTreeNode.findNodeByLabel()
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-03-11 14:43:29 UTC (rev 209)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-11 16:43:42 UTC (rev 210)
@@ -12,6 +12,7 @@
import java.net.URL;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
+import org.jboss.jopr.jsfunit.AppConstants;
import org.jboss.jsfunit.jsfsession.*;
import org.w3c.dom.Element;
@@ -113,6 +114,10 @@
}
+
+
+
+
/**
* Finds the nav tree node by it's link label.
*
@@ -122,6 +127,12 @@
* when there's no node with given label.
*/
public NavTreeNode getNodeByLabel( String label ) throws HtmlElementNotFoundException{
+ return getNodeByLabel(label, true);
+ }
+ public NavTreeNode findNodeByLabel( String label ) throws HtmlElementNotFoundException{
+ return getNodeByLabel(label, false);
+ }
+ public NavTreeNode getNodeByLabel( String label, boolean throwIfNotFound ) throws HtmlElementNotFoundException{
DomElement navTreeForm = (DomElement)client.getElement(ID_NAV_TREE_FORM);
@@ -134,8 +145,12 @@
HtmlTable nodeTable = navTreeForm.getFirstByXPath( xPath );
- if( null == nodeTable )
- throw new HtmlElementNotFoundException("Node '"+label+"' not found using XPath: "+xPath);
+ if( null == nodeTable ){
+ if( throwIfNotFound )
+ throw new HtmlElementNotFoundException("Node '"+label+"' not found using XPath: "+xPath);
+ else
+ return null;
+ }
return new NavTreeNode(nodeTable);
@@ -971,7 +986,6 @@
}
-
// TODO
protected class JMXDeploymentInfo {
15 years, 10 months
EMBJOPR SVN: r209 - in trunk/jsfunit: src/test/java/org/jboss/jopr/jsfunit/as5 and 1 other directories.
by embjopr-commits@lists.jboss.org
Author: fjuma
Date: 2009-03-11 10:43:29 -0400 (Wed, 11 Mar 2009)
New Revision: 209
Added:
trunk/jsfunit/testdata/datasources/testFiles/FlushAfterMultipleConnectionsExistingFile-ds.xml
trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterClosingConnectionsExistingFile-ds.xml
trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterMultipleConnectionsExistingFile-ds.xml
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Added datasource operations tests that use an existing -ds.xml file.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-03-11 02:04:08 UTC (rev 208)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-03-11 14:43:29 UTC (rev 209)
@@ -52,6 +52,8 @@
*
*/
public abstract class DatasourceTestBase extends EmbjoprTestCase {
+
+ public static final String DS_NAV_LABEL = "Datasources";
// Datasource types, as they appear in the left nav
protected enum DatasourceType {
@@ -542,7 +544,7 @@
DatasourceType datasourceType,
Map<String, String> metricsMap) throws IOException, EmbJoprTestException {
- refreshTreeNode("Datasources");
+ refreshTreeNode(DS_NAV_LABEL);
ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType.getLabel());
datasourceTypeArrow.click();
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-03-11 02:04:08 UTC (rev 208)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-03-11 14:43:29 UTC (rev 209)
@@ -68,7 +68,7 @@
Map<String, String> propertiesMap) throws IOException {
// Expand the "Datasources" tree node
- ClickableElement datasourcesArrow = getNavTreeArrow("Datasources");
+ ClickableElement datasourcesArrow = getNavTreeArrow(DS_NAV_LABEL);
datasourcesArrow.click();
HtmlAnchor datasourceLink = getNavTreeLink(datasourceType.getLabel());
@@ -138,7 +138,7 @@
DatasourceType datasourceType,
String tabName) throws IOException, EmbJoprTestException {
- refreshTreeNode("Datasources");
+ refreshTreeNode(DS_NAV_LABEL);
ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType.getLabel());
datasourceTypeArrow.click();
@@ -154,7 +154,7 @@
*/
@Override
protected void deleteDatasource(String datasourceName) throws IOException {
- HtmlAnchor datasourceLink = getNavTreeLink("Datasources");
+ HtmlAnchor datasourceLink = getNavTreeLink(DS_NAV_LABEL);
datasourceLink.click();
HtmlSelect menu = (HtmlSelect)client.getElement("currentPageSize");
@@ -534,6 +534,30 @@
// Min pool size will be 5, max pool size will be 20
Map<String, String> propertiesMap = createLocalTXDatasource("FlushAfterMultipleConnectionsDS");
+ flushOperationAfterMultipleConnections(propertiesMap);
+ }
+
+ /**
+ * Test the "Flush" operation after multiple connections to a database
+ * have been created. Use an existing datasource.
+ */
+ public void testFlushOperationAfterMultipleConnectionsUsingExistingDSFile() throws Exception {
+
+ // Use an existing datasource
+ Map<String, String> propertiesMap = getPropertyValuesMap("FlushAfterMultipleConnectionsExistingFile",
+ DatasourceType.LOCAL_TX_DATASOURCE);
+
+ expandNavTreeArrow(DS_NAV_LABEL);
+
+ // Min pool size will be 5, max pool size will be 20
+ flushOperationAfterMultipleConnections(propertiesMap);
+ }
+
+ /**
+ * Common code for the testFlushOperationAfterMultipleConnections* tests.
+ */
+ private void flushOperationAfterMultipleConnections(Map<String, String> propertiesMap) throws Exception {
+
// Create some connections and then close them. This will
// result in non-zero values for "Connection Created Count" and
// "Max Connections In Use Count".
@@ -616,6 +640,31 @@
// Min pool size will be 5, max pool size will be 20
Map<String, String> propertiesMap = createLocalTXDatasource("ListFormattedSubPoolStatisticsAfterMultipleConnectionsDS");
+ listFormattedSubPoolStatisticsAfterMultipleConnections(propertiesMap);
+ }
+
+ /**
+ * Test the "List Formatted Sub Pool Statistics" operation after multiple
+ * connections to a database have been established. Use an existing datasource.
+ */
+ public void testListFormattedSubPoolStatisticsAfterMultipleConnectionsUsingExistingDSFile() throws Exception {
+
+ // Use an existing datasource
+ Map<String, String> propertiesMap = getPropertyValuesMap("ListFormattedAfterMultipleConnectionsExistingFile",
+ DatasourceType.LOCAL_TX_DATASOURCE);
+
+ expandNavTreeArrow(DS_NAV_LABEL);
+
+ // Min pool size will be 5, max pool size will be 20
+ listFormattedSubPoolStatisticsAfterMultipleConnections(propertiesMap);
+ }
+
+ /**
+ * Common code for the
+ * testListFormattedSubPoolStatisticsAfterMultipleConnections* tests.
+ */
+ private void listFormattedSubPoolStatisticsAfterMultipleConnections(Map<String, String> propertiesMap) throws Exception {
+
// Create some connections
ArrayList<Connection> connections = createConnections(4, propertiesMap.get("jndi-name"),
propertiesMap.get("user-name"),
@@ -655,9 +704,9 @@
// Clean up
closeConnections(connections);
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"));
}
-
+
/**
* Test the "List Formatted Sub Pool Statistics" operation after
* closing some connections.
@@ -667,6 +716,30 @@
// Min pool size will be 5, max pool size will be 20
Map<String, String> propertiesMap = createLocalTXDatasource("ListFormattedSubPoolStatisticsAfterClosingConnectionsDS");
+ listFormattedSubPoolStatisticsAfterClosingConnections(propertiesMap);
+ }
+
+ /**
+ * Test the "List Formatted Sub Pool Statistics" operation after
+ * closing some connections. Use an existing datasource.
+ */
+ public void testListFormattedSubPoolStatisticsAfterClosingConnectionsUsingExistingDSFile() throws Exception {
+ // Use an existing datasource
+ Map<String, String> propertiesMap = getPropertyValuesMap("ListFormattedAfterClosingConnectionsExistingFile",
+ DatasourceType.LOCAL_TX_DATASOURCE);
+
+ expandNavTreeArrow(DS_NAV_LABEL);
+
+ // Min pool size will be 5, max pool size will be 20
+ listFormattedSubPoolStatisticsAfterClosingConnections(propertiesMap);
+ }
+
+ /**
+ * Common code for the
+ * testListFormattedSubPoolStatisticsAfterClosingConnections* tests.
+ */
+ private void listFormattedSubPoolStatisticsAfterClosingConnections(Map<String, String> propertiesMap) throws Exception {
+
// Create some connections
ArrayList<Connection> connections = createConnections(10, propertiesMap.get("jndi-name"),
propertiesMap.get("user-name"),
@@ -712,6 +785,7 @@
deleteDatasource(propertiesMap.get("jndi-name"));
}
+
/*
* METRICS TESTS
*/
@@ -764,7 +838,7 @@
Map<String, String> propertiesMap = getPropertyValuesMap("MetricsInitialConnectionExistingFile",
DatasourceType.LOCAL_TX_DATASOURCE);
- expandNavTreeArrow("Datasources");
+ expandNavTreeArrow(DS_NAV_LABEL);
// Min pool size will be 5, max pool size will be 20
checkMetricsAfterInitialDBConnection(propertiesMap);
@@ -773,7 +847,7 @@
/**
* Common code for the testMetricsAfterInitialDBConnection* tests.
*/
- public void checkMetricsAfterInitialDBConnection(Map<String, String> propertiesMap) throws Exception {
+ private void checkMetricsAfterInitialDBConnection(Map<String, String> propertiesMap) throws Exception {
// Create the first connection
Connection con = connectDB(propertiesMap.get("jndi-name"),
@@ -822,7 +896,7 @@
Map<String, String> propertiesMap = getPropertyValuesMap("MetricsMultipleConnectionsExistingFile",
DatasourceType.NO_TX_DATASOURCE);
- expandNavTreeArrow("Datasources");
+ expandNavTreeArrow(DS_NAV_LABEL);
// Min pool size will be 5, max pool size will be 20
checkMetricsAfterMultipleDBConnections(propertiesMap);
@@ -831,7 +905,7 @@
/**
* Common code for the testMetricsAfterMultipleDBConnections* tests.
*/
- public void checkMetricsAfterMultipleDBConnections(Map<String, String> propertiesMap) throws Exception {
+ private void checkMetricsAfterMultipleDBConnections(Map<String, String> propertiesMap) throws Exception {
// Establish multiple connections
ArrayList<Connection> connections = createConnections(6, propertiesMap.get("jndi-name"),
@@ -879,7 +953,7 @@
Map<String, String> propertiesMap = getPropertyValuesMap("MetricsCloseConnectionsExistingFile",
DatasourceType.NO_TX_DATASOURCE);
- expandNavTreeArrow("Datasources");
+ expandNavTreeArrow(DS_NAV_LABEL);
// Min pool size will be 5, max pool size will be 20
checkMetricsAfterClosingConnections(propertiesMap);
@@ -888,7 +962,7 @@
/**
* Common code for the testMetricsAfterClosingConnections* tests.
*/
- public void checkMetricsAfterClosingConnections(Map<String, String> propertiesMap) throws Exception {
+ private void checkMetricsAfterClosingConnections(Map<String, String> propertiesMap) throws Exception {
// Establish some connections
ArrayList<Connection> connections = createConnections(5, propertiesMap.get("jndi-name"),
Added: trunk/jsfunit/testdata/datasources/testFiles/FlushAfterMultipleConnectionsExistingFile-ds.xml
===================================================================
--- trunk/jsfunit/testdata/datasources/testFiles/FlushAfterMultipleConnectionsExistingFile-ds.xml (rev 0)
+++ trunk/jsfunit/testdata/datasources/testFiles/FlushAfterMultipleConnectionsExistingFile-ds.xml 2009-03-11 14:43:29 UTC (rev 209)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<datasources>
+ <local-tx-datasource>
+ <jndi-name>FlushAfterMultipleConnectionsExistingFile</jndi-name>
+ <rar-name>jboss-local-jdbc.rar</rar-name>
+ <use-java-context>true</use-java-context>
+ <connection-definition>javax.sql.DataSource</connection-definition>
+ <jmx-invoker-name>jboss:service=invoker,type=jrmp</jmx-invoker-name>
+ <min-pool-size>5</min-pool-size>
+ <max-pool-size>20</max-pool-size>
+ <blocking-timeout-millis>35000</blocking-timeout-millis>
+ <idle-timeout-minutes>20</idle-timeout-minutes>
+ <prefill>false</prefill>
+ <background-validation>false</background-validation>
+ <background-validation-millis>0</background-validation-millis>
+ <validate-on-match>true</validate-on-match>
+ <statistics-formatter>org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter</statistics-formatter>
+ <isSameRM-override-value>false</isSameRM-override-value>
+ <allocation-retry>0</allocation-retry>
+ <allocation-retry-wait-millis>5000</allocation-retry-wait-millis>
+ <metadata>
+ <type-mapping>FirstSQL/J</type-mapping>
+ </metadata>
+ <local-transaction/>
+ <user-name>sa</user-name>
+ <password></password>
+ <prepared-statement-cache-size>0</prepared-statement-cache-size>
+ <share-prepared-statements>false</share-prepared-statements>
+ <set-tx-query-timeout>false</set-tx-query-timeout>
+ <query-timeout>0</query-timeout>
+ <use-try-lock>60000</use-try-lock>
+ <driver-class>org.hsqldb.jdbcDriver</driver-class>
+ <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB</connection-url>
+ </local-tx-datasource>
+</datasources>
Added: trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterClosingConnectionsExistingFile-ds.xml
===================================================================
--- trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterClosingConnectionsExistingFile-ds.xml (rev 0)
+++ trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterClosingConnectionsExistingFile-ds.xml 2009-03-11 14:43:29 UTC (rev 209)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<datasources>
+ <local-tx-datasource>
+ <jndi-name>ListFormattedAfterClosingConnectionsExistingFile</jndi-name>
+ <rar-name>jboss-local-jdbc.rar</rar-name>
+ <use-java-context>true</use-java-context>
+ <connection-definition>javax.sql.DataSource</connection-definition>
+ <jmx-invoker-name>jboss:service=invoker,type=jrmp</jmx-invoker-name>
+ <min-pool-size>5</min-pool-size>
+ <max-pool-size>20</max-pool-size>
+ <blocking-timeout-millis>35000</blocking-timeout-millis>
+ <idle-timeout-minutes>20</idle-timeout-minutes>
+ <prefill>false</prefill>
+ <background-validation>false</background-validation>
+ <background-validation-millis>0</background-validation-millis>
+ <validate-on-match>true</validate-on-match>
+ <statistics-formatter>org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter</statistics-formatter>
+ <isSameRM-override-value>false</isSameRM-override-value>
+ <allocation-retry>0</allocation-retry>
+ <allocation-retry-wait-millis>5000</allocation-retry-wait-millis>
+ <metadata>
+ <type-mapping>FirstSQL/J</type-mapping>
+ </metadata>
+ <local-transaction/>
+ <user-name>sa</user-name>
+ <password></password>
+ <prepared-statement-cache-size>0</prepared-statement-cache-size>
+ <share-prepared-statements>false</share-prepared-statements>
+ <set-tx-query-timeout>false</set-tx-query-timeout>
+ <query-timeout>0</query-timeout>
+ <use-try-lock>60000</use-try-lock>
+ <driver-class>org.hsqldb.jdbcDriver</driver-class>
+ <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB</connection-url>
+ </local-tx-datasource>
+</datasources>
Added: trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterMultipleConnectionsExistingFile-ds.xml
===================================================================
--- trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterMultipleConnectionsExistingFile-ds.xml (rev 0)
+++ trunk/jsfunit/testdata/datasources/testFiles/ListFormattedAfterMultipleConnectionsExistingFile-ds.xml 2009-03-11 14:43:29 UTC (rev 209)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<datasources>
+ <local-tx-datasource>
+ <jndi-name>ListFormattedAfterMultipleConnectionsExistingFile</jndi-name>
+ <rar-name>jboss-local-jdbc.rar</rar-name>
+ <use-java-context>true</use-java-context>
+ <connection-definition>javax.sql.DataSource</connection-definition>
+ <jmx-invoker-name>jboss:service=invoker,type=jrmp</jmx-invoker-name>
+ <min-pool-size>5</min-pool-size>
+ <max-pool-size>20</max-pool-size>
+ <blocking-timeout-millis>35000</blocking-timeout-millis>
+ <idle-timeout-minutes>20</idle-timeout-minutes>
+ <prefill>false</prefill>
+ <background-validation>false</background-validation>
+ <background-validation-millis>0</background-validation-millis>
+ <validate-on-match>true</validate-on-match>
+ <statistics-formatter>org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter</statistics-formatter>
+ <isSameRM-override-value>false</isSameRM-override-value>
+ <allocation-retry>0</allocation-retry>
+ <allocation-retry-wait-millis>5000</allocation-retry-wait-millis>
+ <metadata>
+ <type-mapping>FirstSQL/J</type-mapping>
+ </metadata>
+ <local-transaction/>
+ <user-name>sa</user-name>
+ <password></password>
+ <prepared-statement-cache-size>0</prepared-statement-cache-size>
+ <share-prepared-statements>false</share-prepared-statements>
+ <set-tx-query-timeout>false</set-tx-query-timeout>
+ <query-timeout>0</query-timeout>
+ <use-try-lock>60000</use-try-lock>
+ <driver-class>org.hsqldb.jdbcDriver</driver-class>
+ <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB</connection-url>
+ </local-tx-datasource>
+</datasources>
15 years, 10 months
EMBJOPR SVN: r208 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-10 22:04:08 -0400 (Tue, 10 Mar 2009)
New Revision: 208
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
* Removed EmbJoprTestToolkit from the ApplicationTestBaseAS5
* Changed EarTest and ApplicationsPageTest to use EmbJoprTestToolkit from the new standalone class.
* Fixed few XPath expressions.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-11 00:46:33 UTC (rev 207)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-11 02:04:08 UTC (rev 208)
@@ -171,833 +171,7 @@
- /**
- * Single nav tree instance.
- *
- * Using instance instead of static methods is necessary
- * if we want to subclass this tools for AS 4 tests in the future.
- */
- protected NavTree navTree = new NavTree();
- /**
- * Inner class to encapsulate navigation tree operations.
- *
- * Note that this class does not hold any element reference,
- * because the reference becomes invalid with every navigation action.
- *
- * Instead, all these methods call client methods.
- */
- protected class NavTree {
-
- public static final String ID_NAV_TREE_FORM = "navTreeForm";
-
- private void clickRootNode() throws IOException, EmbJoprTestException {
- DomElement element = (DomElement)client.getElement(ID_NAV_TREE_FORM);
- if( null == element )
- 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']");
-
- // No XSLT 2.0 support :(
- // 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, '"+ID_NAV_TREE_FORM+":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();
- }
-
-
- public void waitForNavTreeLoaded(){
- sleep(1500);///
- // TODO: Use ActiveConditionChecker
-
- }
-
-
- /**
- * 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 navTreeForm = (DomElement)client.getElement(ID_NAV_TREE_FORM);
-
- // A table which has an anchor containing given text.
- // 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+"']]";
- // Node has @id = navTreeForm:navTree:136:137:138:139:143:195::instanceNodeOrLeafLink
- // Let's rely on the ":text" id part only and suppose there will be just one link in that TD.
- String xPath = ".//table[.//td[contains(@id,':text')]//a[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);
-
- }
-
-
- /**
- * Need a standard JSFUnit API to replace this code.
- * @see getNodeByLabel().getLabelLink()
- */
- public HtmlAnchor getNodeLink(String linkLabel)
- {
- return getLinkInsideForm(ID_NAV_TREE_FORM, linkLabel);
- }
-
-
- /**
- * Finds the arrow icon in the nav tree that corresponds to the resource
- * 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)
- {
- HtmlAnchor link = getNodeLink(resourceName);
- String id = link.getIdAttribute();
-
- // An example id is: "navTreeForm:navTree:81:82:83:84::typeSummaryLink"
- // The icon's id would be: "81:82:83:84::typeSummary:handle:img:collapsed"
- int index = id.lastIndexOf("Link");
- id = id.substring(0, index) + ":handle";
- return (ClickableElement)client.getElement(id);
- }
-
- }// class NavTree
-
-
-
- /**
- * Represents nav tree node.
- * Contains convenience methods to work with the node.
- */
- protected class NavTreeNode {
-
- /** Keeps the table element of this node. */
- private HtmlElement elem;
- public HtmlElement getElement() { return this.elem; }
-
- private NavTreeNode( HtmlTable nodeTable ){
- this.elem = nodeTable;
- }
-
- /** Returns true if this node is expanded. */
- public boolean isExpanded() throws EmbJoprTestException
- {
- HtmlAnchor arrowLink = this.getArrowLink();
- HtmlElement img = (HtmlElement)arrowLink.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.");
-
- }
-
- /** 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";
- return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
- }
-
- /** Returns the arrow's link. */
- public HtmlAnchor getArrowLink(){
- 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();
- }
-
-
- }// class NavTreeNode()
-
-
-
-
- protected final TabMenu tabMenu = new TabMenu();
-
- /**
- * Inner class to encapsulate tab menu operations.
- */
- protected class TabMenu {
-
- public TabContentBox getTabContentBox() throws HtmlElementNotFoundException {
-
- HtmlElement contentElement = (HtmlElement) client.getElement("content");
- HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath("div[@class='tabmenubox']");
- if( null == tabContentBox )
- throw new HtmlElementNotFoundException("Tab content box not found using div[@class='tabmenubox'] XPath");
-
- return new TabContentBox(tabContentBox);
- }
-
- 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+"']";
- ClickableElement tabContent = element.getFirstByXPath(xPath);
-
-
- if( null == tabContent )
- throw new HtmlElementNotFoundException("Tab '"+label+"' not found using XPath '"+xPath+"'");
-
- return tabContent;
-
- }
-
- /** 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");
- }
-
- /** 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");
- }
-
- /** Shotcut - getTab(label).click(); Not necesarilly clicks an anchor. */
- public void clickTab( String label ) throws IOException, ActionNotAvailableException, HtmlElementNotFoundException {
-
- StyledElement tabContent = getTab(label);
- if( !( tabContent instanceof ClickableElement ) )
- throw new ActionNotAvailableException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
-
- ((ClickableElement)tabContent).click();
-
- }
-
- }
-
-
- /**
- * Base class for parts that will check their validity before performing actions.
- * Not necessary if we pay attention to validity, but why not check it -
- * performance is not a question for us.
- *
- * TODO: Instead, use the Page returned from click() etc.
- */
- protected class PageContextAwareElement {
- private URL validForURL;
- private String validForDate;
-
- /** Store the context identifiing attributes upon creation. */
- public PageContextAwareElement() {
- // TODO: Shouldn't we store the elements's page instead of current?
- this.validForDate = client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
- this.validForURL = client.getContentPage().getWebResponse().getUrl();
- }
-
- /**
- * Checks whether this element is still valid in the current web page context,
- * i.e. whether we are still on the page in which this element existed.
- * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
- */
- 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 element wrapper was created from another page and is not valid now.");
- }
- }
-
- }
-
- /** Better try... */
- protected class PageAware {
- private Page validForPage;
- public PageAware(){
- this.validForPage = client.getContentPage();
- }
- public void checkIfStillValid() throws PageHasChangedException {
- if( !client.getContentPage().equals( this.validForPage ) )
- throw new PageHasChangedException(
- "This element wrapper was created from another page and is not valid now.",
- client.getContentPage(), this.validForPage );
- }
- }
-
-
- /**
- * Inner class for manipulation with tab content box.
- */
- protected class TabContentBox extends PageAware {
-
- private HtmlElement element;
- public HtmlElement getElement() { return element; }
-
- public TabContentBox(HtmlElement element) {
- super();
- this.element = element;
- }
-
- /**
- * Returns first table under given header.
- *
- * Unfortunately, headers are not H2 or similar, but DIV class="instructionalText".
- * To be revised later.
- *
- * @return
- */
- public ContentTable getTableUnderHeader( String headerText ) throws ActionOutOfSyncException
- {
- checkIfStillValid();
-
- String xPath = "*[contains(normalize-space(), '"+headerText+"')]/following::table";
- // [@id='resourceSummaryForm:dataTable'] - is this reliable?
- HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
- return new ContentTable(tableElement);
- }
-
- /**
- * Returns first table in the content box.
- * @param headerText
- * @return
- * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
- */
- public ContentTable getFirstTable() throws ActionOutOfSyncException
- {
- checkIfStillValid();
-
- String xPath = ".//form//table[contains( normalize-space(@id), ':dataTable')]";
- // [@id='resourceSummaryForm:dataTable'] - is this reliable?
- HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
- return new ContentTable(tableElement);
- }
-
-
- /**
- * Finds first button with given label inside this box.
- * @param label
- * @return
- * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
- * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
- */
- public HtmlButtonInput getButtonByLabel( String label )
- throws HtmlElementNotFoundException, ActionOutOfSyncException {
-
- checkIfStillValid();
-
- HtmlButtonInput button = this.element.getFirstByXPath(".//input[normalize-space(@value)='"+label+"']");
- if( null == button )
- throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
-
- return button;
-
- }
-
- }// inner class TabContentBox
-
-
-
- /**
- * Contains convenience methods for accessing content tables in EmbJopr.
- */
- protected class ContentTable {
-
- public static final String ID_CATEGORY_DATA_TABLE = "categorySummaryForm:dataTable";
- public static final String ID_RESOURCE_DATA_TABLE = "resourceSummaryForm:dataTable";
-
- private HtmlTable element;
- public HtmlTable getElement() { return element; }
-
- /**
- * Creates a data table wrapper for the given table element.
- */
- public ContentTable( HtmlTable element ) {
- this.element = element;
- }
-
- /**
- * Creates a data table wrapper for first found element with one of these IDs:
- * ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE
- *
- * This method assumes there's only one "data table" per page.
- * If not, it simply returns the first in the order of IDs searched.
- * You can always specify the element using ContentTable( HtmlTable element ).
- */
- public ContentTable() throws HtmlElementNotFoundException {
-
- // Find the data table - try some known IDs.
- String[] elemIDs = { ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE };
- Element elem = null;
- for( String elemID : elemIDs ){
- elem = client.getElement(elemID);
- if( null != elem )
- break;
- }
- if( null == elem )
- throw new HtmlElementNotFoundException(
- "Can't find the content table element, searched IDs: "
- + elemIDs.toString() );
-
- this.element = (HtmlTable)elem;
- }
-
-
- // Columns maps
- private List<String> colLabels = null;
- private Map<String, Integer> colIndexes = null;
- //private boolean analyzedButNotFound = false;
-
-
-
- /**
- * Returns the first row that contains given text, or throws HtmlElementNotFoundException.
- * @param text
- * @return
- * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
- * when no row contains specified text.
- */
- public ContentTableRow getFirstRowContainingText( String text )
- throws HtmlElementNotFoundException
- {
- if( 0 == element.getRowCount() )
- throw new HtmlElementNotFoundException("Table has no rows.");
-
- // TODO: Escape the single quotes. By doubling?
- // http://books.google.com/books?id=jzqFMlM0gb0C&pg=PA308&lpg=PA308&dq=xquer...
- String xPath = ".//tr[contains(string(), '"+text+"')]";
- HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
- if( null == elm )
- throw new HtmlElementNotFoundException(xPath);
- return new ContentTableRow(elm, this);
- }
-
-
-
- /**
- * Returns wrapper of the table row which contains a link with given label,
- * or null when the no such row is found.
- */
- public ContentTableRow findFirstRowContainingLink( String linkLabel )
- {
- if( 0 == element.getRowCount() )
- return null;
-
- String xPath = ".//tr[.//a[normalize-space()='"+linkLabel+"']]";
- HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
- if( null == elm )
- return null;
- return new ContentTableRow(elm, this);
- }
-
- public List<ContentTableRow> getRows(){
- if( 0 == element.getRowCount() )
- return Collections.EMPTY_LIST;
-
- String xPath = "./tbody/tr";
- List<HtmlTableRow> trList = (List) element.getByXPath(xPath);
- List<ContentTableRow> rows = new ArrayList(trList.size());
- for (HtmlTableRow tr : trList) {
- rows.add( new ContentTableRow(tr, this));
- }
- return rows;
- }
-
- /**
- * Returns wrapper of the table row which contains a link with given label.
- * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
- * when no row with such label found.
- */
- public ContentTableRow getFirstRowContainingLink( String linkLabel )
- throws HtmlElementNotFoundException
- {
- if( 0 == element.getRowCount() )
- throw new HtmlElementNotFoundException("Table has no rows.");
-
- String xPath = ".//tr[.//a[normalize-space()='"+linkLabel+"']]";
- HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
- if( null == elm )
- throw new HtmlElementNotFoundException(
- "Can't find row containing link '"+linkLabel+"' using XPath: "+xPath);
- return new ContentTableRow(elm, this);
- }
-
- /**
- * Creates a list of columns headers
- * and a label => col index map.
- */
- public void analyzeColumns() throws HtmlElementNotFoundException
- {
-
- /*if( this.analyzedButNotFound )
- throw new HtmlElementNotFoundException("Table has no column headers.");
- /**/ // 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 position()=1]/th";
- List<HtmlTableHeaderCell> colHeaders = (List<HtmlTableHeaderCell>) this.element.getByXPath(xPath);
-
- if( 0 == colHeaders.size() ){
- //this.analyzedButNotFound = true;
- throw new HtmlElementNotFoundException("Table has no column headers.");
- }
-
- List<String> colLabels_ = new ArrayList(colHeaders.size());
- Map<String, Integer> colIndexes_ = new HashMap(colHeaders.size());
-
- //for( HtmlTableHeaderCell th : colHeaders ){
- for( int i = 0; i < colHeaders.size(); i++ ) {
- HtmlTableHeaderCell th = colHeaders.get(i);
- String sHeader = th.getTextContent();
- colLabels_.add( sHeader );
- colIndexes_.put( sHeader, i );
- }
-
- this.colLabels = colLabels_;
- this.colIndexes = colIndexes_;
-
- }
-
- /**
- * Returns an index of the column with given name in the TH header,
- * or throws HtmlElementNotFound in two cases:
- * 1) Table does not have column headers
- * 2) No header with such name was found.
- *
- * @param colName
- * @return
- * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
- */
- public int getColumnIndexByName( String colName ) throws HtmlElementNotFoundException {
- if( null == this.colIndexes )
- this.analyzeColumns();
-
- Integer index = this.colIndexes.get(colName);
- if( null == index )
- throw new HtmlElementNotFoundException("No column named '"+colName+"'.");
-
- return index;
- }
-
- }// inner class ContentTable
-
-
-
-
-
- /**
- * Provides extra method that parses text-like info table (with one column).
- */
- protected class ContentInfoTable extends ContentTable {
-
- public ContentInfoTable(HtmlTable element) {
- super(element);
- }
-
- /**
- * Parses the content of the table for properties.
- * @return
- */
- public Properties getProperties()
- {
- Properties props = new Properties();
-
- // The template has label in span/strong and the value as text in td.
- String xPath = ".//tr/td[span/strong]";
- List<HtmlTableCell> cells = (List<HtmlTableCell>) this.getElement().getByXPath(xPath);
- for( HtmlTableCell cell : cells ){
- String[] parts = cell.getTextContent().split(":");
- props.put(parts[0], parts[1]);
- }
- return props;
- }
-
- }// inner class ContentInfoTable
-
-
-
- /**
- * Row of a content table.
- * Contains convenience methods for accessing content table rows in EmbJopr.
- */
- protected class ContentTableRow {
-
- private HtmlTableRow element;
- public HtmlTableRow getElement() { return element; }
-
- private ContentTable containingTable;
-
- private ContentTableRow(HtmlTableRow elm, ContentTable containingTable) {
- this.element = elm;
- this.containingTable = containingTable;
- }
-
- /**
- * 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.
- * @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 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);
- if( !(elm instanceof HtmlButton ) && !(elm instanceof HtmlButtonInput) )
- throw new HtmlElementNotFoundException("Element is not a button, but: "+elm.getClass().getName());
-
- return (ClickableElement)elm;
- }
-
-
- /**
- * Gives the (first) link from the cell of this row, from the column with given header.
- * @param colName
- * @return
- * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
- * in two cases:
- * 1) Table has no column of given name
- * 2) There's no link in that cell.
- */
- public HtmlAnchor getFirstLinkFromColumn(String colName) throws HtmlElementNotFoundException
- {
- HtmlTableCell cell = this.getCellByColumnName(colName);
-
- String xPath = ".//a";
- HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
-
- if( null == link )
- throw new HtmlElementNotFoundException("No link found in column '"+colName+"'");
-
- return link;
- }
-
-
- /**
- * Returns the link with given label.
- * @param string
- */
- public HtmlAnchor getLinkByLabel(String linkLabel) throws HtmlElementNotFoundException {
- String xPath = ".//a[normalize-space()='"+linkLabel+"']";
- HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
- if( null == link ){
- StringBuilder sb = new StringBuilder();
- List<HtmlElement> linksFound = this.element.getHtmlElementsByTagName("a");
- for( HtmlElement linkFound : linksFound ){
- sb.append("'").append( ((HtmlAnchor)linkFound).getTextContent() ).append("', ");
- }
- String availLinks = StringUtils.removeEnd( sb.toString(), ", " );
-
- throw new HtmlElementNotFoundException("Can't find link using '"+xPath+"', available: "+availLinks);
- }
- return link;
- }
-
- /**
- * Returns the cell of this table from given index,
- * or throws IndexOutOfBoundsException.
- *
- * TODO: May throw IndexOutOfBoundsException - leave unchecked?
- *
- * @param index
- * @return
- */
- public HtmlTableCell getCell( int index ){
- HtmlTableCell cell = this.element.getCell(index);
- 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
- {
- 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();
- }
-
-
- }// inner class ContentTableRow
-
-
-
-
- /**
- * Pagination control
- * Not tested yet.
- */
- public class ContentBoxPagination {
-
- //private HtmlElement element;
- //public HtmlElement getElement() { return element; }
-
- private static final String ID_PAGE_CONTROLS = "categorySummaryForm:dataTableScroller";
- private static final String ID_PAGE_SIZE_SELECT = "categorySummaryForm:currentPageSize";
- private static final String ID_PAGINATION_TOTAL_ITEMS = "paginationTotalItems";
-
- protected HtmlDivision getPageContols(){
- return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
- }
-
- protected HtmlSelect getPageSizeSelect(){
- return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
- }
-
- public int getTotalItemsCount() throws ActionNotAvailableException
- {
- Element e = client.getElement(ID_PAGINATION_TOTAL_ITEMS);
- String textContent = e.getTextContent();
- String[] parts = textContent.split(":");
- if( parts.length < 2 )
- throw new ActionNotAvailableException("Total pagination items count expected after 'Total:' or similar.");
-
- String countStr = parts[1].trim();
- try{
- return NumberUtils.createInteger( countStr );
- }catch(NumberFormatException ex ){
- throw new ActionNotAvailableException("Can't parse pagination items count from '"+countStr+"'", ex);
- }
- }
-
- protected HtmlSpan getGoSpan( String spanLabel ) throws HtmlElementNotFoundException {
- String xPath = ".//span[normalize-space() = '"+spanLabel+"']";
- HtmlSpan span = getPageContols().getFirstByXPath(xPath);
- if( null == span )
- throw new HtmlElementNotFoundException(
- "Span with '"+spanLabel+"' not found using XPath '"+xPath+"'");
- return span;
- }
-
- protected HtmlTableCell getGoPage( int pageNumber ) throws HtmlElementNotFoundException{
- String xPath = ".//td[normalize-space() = '"+pageNumber+"']";
- HtmlElement td = getPageContols().getFirstByXPath(xPath);
- if( null == td )
- throw new HtmlElementNotFoundException(
- "Page number "+pageNumber+" not found. Try 1 - "+this.getPageCount());
- return (HtmlTableCell) td;
- }
-
-
- public boolean goFirst() throws IOException, HtmlElementNotFoundException{
- // TODO: Compare old and new page object reference?
- HtmlSpan goSpan = getGoSpan("First");
- goSpan.click();
- return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
- }
-
- public boolean goPrev() throws IOException, HtmlElementNotFoundException{
- HtmlSpan goSpan = getGoSpan("Prev");
- goSpan.click();
- return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
- }
-
- public boolean goNext() throws IOException, HtmlElementNotFoundException{
- HtmlSpan goSpan = getGoSpan("Next");
- goSpan.click();
- return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
- }
-
- public boolean goLast() throws IOException, HtmlElementNotFoundException{
- HtmlSpan goSpan = getGoSpan("Last");
- goSpan.click();
- return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
- }
-
- public void goPage( int pageNumber ) throws IOException, HtmlElementNotFoundException{
- getGoPage(pageNumber).click();
- }
-
-
- public boolean isPageActive( int pageNumber ) throws IOException, HtmlElementNotFoundException{
- return !getGoPage(pageNumber).getStyleAttribute().contains("-inact");
- }
-
- public int getPageCount(){
- String xPath = ".//td[ count(./*) = 0 and normalize-space() > 0 ]";
- List<?> elements = getPageContols().getByXPath(xPath);
- return elements.size();
- }
-
- public int getItemsPerPage() throws HtmlElementNotFoundException, ActionNotAvailableException {
- String selectText = getPageSizeSelect().asText();
- try {
- return NumberUtils.createInteger( selectText );
- }
- catch( NumberFormatException ex ){
- throw new ActionNotAvailableException("Can't parse 'items per page' from '"+selectText+"'.", ex);
- }
- }
- public void setItemsPerPage( int num ) throws HtmlElementNotFoundException {
- String optionValue = ""+num;
- HtmlSelect pageSizeSelect = getPageSizeSelect();
-
- try{
- pageSizeSelect.getOptionByValue(optionValue);
- }
- catch( ElementNotFoundException ex ){
- // Print out available options.
- StringBuilder sb = new StringBuilder(pageSizeSelect.getOptionSize());
- for( HtmlOption opt : pageSizeSelect.getOptions() ){
- sb.append(" ").append(opt.getValueAttribute());
- }
- String possibleOptions = sb.toString().trim().replace(" ", ", ");
-
- throw new HtmlElementNotFoundException("Specified option is invalid. Try one of: "+possibleOptions, ex);
- }
-
- pageSizeSelect.setSelectedAttribute(optionValue, true);
- }
-
- }// ContentBoxPagination
-
-
-
-
- /** Calls Thread.sleep(ms), ignores the InterruptedException. */
- @SuppressWarnings("empty-statement")
- public static void sleep( int ms ) {
- try {
- Thread.sleep(3000);
- } catch (InterruptedException ex) {
- ; // We don't care, that's the purpose of this method.
- }
- }
-
-
}// ApplicationTestBaseAS5
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-11 00:46:33 UTC (rev 207)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-11 02:04:08 UTC (rev 208)
@@ -28,6 +28,7 @@
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
@@ -51,14 +52,14 @@
public void testNavigationToApplications() throws EmbJoprTestException, IOException {
// Wait until the tree is loaded via AJAX.
- // TODO: navTree.waitForNavTreeLoaded();
- sleep(2000);
+ // TODO: ejtt.navTree.waitForNavTreeLoaded();
+ ejtt.sleep(2000);
// Navigate to apps summary tab
- NavTreeNode appsNode = navTree.getNodeByLabel(NAV_APPLICATIONS);
+ NavTreeNode appsNode = ejtt.navTree.getNodeByLabel(NAV_APPLICATIONS);
assertNotNull(appsNode);
appsNode.click();
- tabMenu.clickTab("Summary");
+ ejtt.tabMenu.clickTab("Summary");
// Check text bits appearance.
String text = client.getElement("content").getTextContent();
@@ -78,31 +79,31 @@
public void testAppsPagination() throws EmbJoprTestException, IOException {
// Navigate to apps summary tab
- NavTreeNode appsNode = navTree.getNodeByLabel(NAV_APPLICATIONS);
+ NavTreeNode appsNode = ejtt.navTree.getNodeByLabel(NAV_APPLICATIONS);
assertNotNull(appsNode);
appsNode.click();
- tabMenu.clickTab("Summary");
+ ejtt.tabMenu.clickTab("Summary");
- sleep(1000);
+ ejtt.sleep(1000);
// Get and check total items count.
- int itemsCount = new ContentBoxPagination().getTotalItemsCount();
+ int itemsCount = ejtt.tabMenu.getTabContentBox().getPagination().getTotalItemsCount();
// Returns null, skipping.
//Number serverCount = (Number) server.getManagedBeanValue("#{paginationDataModel.size}");
//assertEquals("Items count reported in page differs from server's.", serverCount, itemsCount);
// Check whether trinomial equation fits
- int itemsPerPage = new ContentBoxPagination().getItemsPerPage();
+ int itemsPerPage = ejtt.tabMenu.getTabContentBox().getPagination().getItemsPerPage();
int expectedPages = itemsCount / itemsPerPage;
if( itemsCount % itemsPerPage > 0 )
expectedPages++;
- int pageCount = new ContentBoxPagination().getPageCount();
+ int pageCount = ejtt.tabMenu.getTabContentBox().getPagination().getPageCount();
assertEquals("Expected number of pages: "+itemsCount+" / "+itemsPerPage, expectedPages, pageCount);
// ------- FAILS HERE because of EMBJOPR-61. --------- //
int page = 0;
- while( new ContentBoxPagination().goNext() ){
+ while( ejtt.tabMenu.getTabContentBox().getPagination().goNext() ){
page++;
if( page > expectedPages )
@@ -110,7 +111,7 @@
" - to "+page+"th page, expected only "+expectedPages+".");
// Get rows.
- ContentTable table = tabMenu.getTabContentBox().getFirstTable();
+ ContentTable table = ejtt.tabMenu.getTabContentBox().getFirstTable();
List<ContentTableRow> rows = table.getRows();
// Check the number of rows listed against what set in combo.
@@ -144,10 +145,10 @@
public void testAppsListing() throws EmbJoprTestException, IOException {
// Navigate to apps summary tab
- NavTreeNode appsNode = navTree.getNodeByLabel(NAV_APPLICATIONS);
+ NavTreeNode appsNode = ejtt.navTree.getNodeByLabel(NAV_APPLICATIONS);
assertNotNull(appsNode);
appsNode.click();
- tabMenu.clickTab("Summary");
+ ejtt.tabMenu.clickTab("Summary");
@@ -161,10 +162,10 @@
// ------- FAILS HERE because of EMBJOPR-61. --------- //
int max = 100;
- while( max-- > 0 && new ContentBoxPagination().goNext() ){
+ while( max-- > 0 && ejtt.tabMenu.getTabContentBox().getPagination().goNext() ){
// Get rows.
- ContentTable table = tabMenu.getTabContentBox().getFirstTable();
+ ContentTable table = ejtt.tabMenu.getTabContentBox().getFirstTable();
List<ContentTableRow> rows = table.getRows();
// For all rows...
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-03-11 00:46:33 UTC (rev 207)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-03-11 02:04:08 UTC (rev 208)
@@ -36,6 +36,7 @@
import org.apache.commons.lang.StringUtils;
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.exceptions.*;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
import org.w3c.dom.Node;
@@ -132,7 +133,7 @@
verify the archive has been deployed successfully.
*/
- public void DISABLEDtestBadEarRedeploy() throws IOException {
+ public void DISABLEDtestBadEarRedeploy() throws IOException, HtmlElementNotFoundException {
String earFilePath = System.getProperty(SYSPROP_TESTDATA_DIR) + "/ear/"+EAR_MALFORMED_APP_FILENAME;
deployEar(earFilePath);
@@ -161,7 +162,7 @@
{
// JBossAS Servers node
- NavTreeNode nodeServers = navTree.getNodeByLabel("JBossAS Servers");
+ NavTreeNode nodeServers = ejtt.getNavTree().getNodeByLabel("JBossAS Servers");
nodeServers.click();
{
@@ -175,7 +176,7 @@
client.getPageAsText().contains("UP"));
// Check whether the server is listed. If not, Exception is thrown.
ContentTableRow row =
- tabMenu.getTabContentBox().getTableUnderHeader("JBoss Application Server")
+ ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("JBoss Application Server")
.getFirstRowContainingLink("JBoss App Server:default");
// Click the server link
//HtmlAnchor link row.getLinkByLabel("JBoss App Server:default");
@@ -200,7 +201,7 @@
// TODO: This page reports "Version:5.0 CR1" - EMBJOPR-77
- navTree.getNodeByLabel("Applications").click();
+ ejtt.getNavTree().getNodeByLabel("Applications").click();
}
@@ -209,15 +210,16 @@
{
// Whooo-hooo! So much to click through!
- tabMenu.clickTab("Summary");
+ ejtt.getTabMenu().clickTab("Summary");
// TODO: Pagination options: EMBJOPR-78
// resourceDataScroller.xhtml, TableManager.java, "pageSizes".
// There's at least one Application with State == UP.
- //ContentTable table = tabMenu.getTabContentBox().getTableUnderHeader("Different types of Applications");
- ContentTable table = new ContentTable((HtmlTable)client.getElement("categorySummaryForm:dataTable"));
+ //ContentTable table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Different types of Applications");
+ HtmlTable tableElement = (HtmlTable)client.getElement("categorySummaryForm:dataTable");
+ ContentTable table = ejtt.getTabMenu().getTabContentBox().getTable(tableElement);
ContentTableRow row = table.getFirstRowContainingText("UP");
// Go further - try to click on any Application that is up.
@@ -228,7 +230,7 @@
{
// Go back to applications Sumary screen.
- navTree.getNodeByLabel("Applications").click();
+ ejtt.getNavTree().getNodeByLabel("Applications").click();
}
@@ -238,27 +240,27 @@
String earFilePath = System.getProperty(SYSPROP_TESTDATA_DIR) + "/ear/"+BASIC_EAR;
deployEar( earFilePath );
- navTree.getNodeByLabel(NAV_EAR).click();
+ ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- ContentTableRow earRow = new ContentTable().getFirstRowContainingLink(BASIC_EAR);
+ ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
assertTrue("Page doesn't list "+BASIC_EAR+" in Summary tab.", earRow != null );
// Go to the summary through listed item.
earRow.getLinkByLabel(BASIC_EAR).click();
// Check that we have the summary tab for the selected EAR.
assertTrue( "EAR name ("+BASIC_EAR+" not found in the content box.",
- tabMenu.getTabContentBox().getElement().getTextContent().contains(BASIC_EAR) );
+ ejtt.getTabMenu().getTabContentBox().getElement().getTextContent().contains(BASIC_EAR) );
// Go to the summary through nav tree node.
- NavTreeNode earNode = navTree.getNodeByLabel(NAV_EAR);
+ NavTreeNode earNode = ejtt.getNavTree().getNodeByLabel(NAV_EAR);
if( !earNode.isExpanded() ){
log.info("Expanding.");
earNode.getArrowLink().click();
Thread.sleep(2000);
}
- navTree.getNodeByLabel(BASIC_EAR).click();
+ ejtt.getNavTree().getNodeByLabel(BASIC_EAR).click();
// Check that we have the summary tab for the selected EAR.
- tabMenu.getTabContentBox().getElement().getTextContent().contains(BASIC_EAR);
+ ejtt.getTabMenu().getTabContentBox().getElement().getTextContent().contains(BASIC_EAR);
undeployEar(BASIC_EAR);
@@ -294,14 +296,14 @@
new ActiveConditionChecker(new DescribedCondition("EAR appears in Summary tab list") {
public boolean isTrue() throws Exception {
// Refresh, then check.
- navTree.getNodeByLabel(NAV_EAR).click();
- ContentTableRow earRow = new ContentTable().findFirstRowContainingLink(BASIC_EAR);
+ ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
+ ContentTableRow earRow = ejtt.getDefaultContentTable().findFirstRowContainingLink(BASIC_EAR);
return null != earRow;
}
}).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(2000, 5);
- ContentTableRow earRow = new ContentTable().getFirstRowContainingLink(BASIC_EAR);
+ ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
// Wait until the Status is "UP".
// TODO: Replace with ActiveConditionChecker.
@@ -313,8 +315,8 @@
break;
// Refresh page after 1 second.
- navTree.getNodeByLabel(NAV_EAR).click();
- earRow = new ContentTable().getFirstRowContainingLink(BASIC_EAR);
+ ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
+ earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
// We don't want an infinite loop by mistake.
if( maxLoops-- <= 0 ){
@@ -329,8 +331,8 @@
// Check the values in info table(s)
// General Properties
- ContentInfoTable infoTable = new ContentInfoTable(
- tabMenu.getTabContentBox().getTableUnderHeader("General Properties").getElement() );
+ HtmlTable genpropTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("General Properties").getElement();
+ ContentInfoTable infoTable = ejtt.getContentInfoTable( genpropTable );
Properties props = infoTable.getProperties();
assertEquals(BASIC_EAR, props.getProperty("Name").trim());
@@ -340,8 +342,8 @@
// Resource Traits
- infoTable = new ContentInfoTable(
- tabMenu.getTabContentBox().getTableUnderHeader("Resource Traits").getElement() );
+ infoTable = ejtt.getContentInfoTable(
+ ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Resource Traits").getElement() );
props = infoTable.getProperties();
@@ -350,9 +352,9 @@
assertEquals("no", props.getProperty("Exploded?").trim());
- // Metrics Summary
- infoTable = new ContentInfoTable(
- tabMenu.getTabContentBox().getTableUnderHeader("Metrics Summary").getElement() );
+ // Metrics Summary
+ HtmlTable summaryTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Metrics Summary").getElement();
+ infoTable = ejtt.getContentInfoTable(summaryTable);
// (nothing here yet)
@@ -376,10 +378,10 @@
String earFilePath = System.getProperty(SYSPROP_TESTDATA_DIR) + "/ear/"+BASIC_EAR;
deployEar( earFilePath );
- navTree.getNodeByLabel(NAV_EAR).click();
+ ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
- ContentTableRow earRow = new ContentTable().getFirstRowContainingLink(BASIC_EAR);
+ ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
// TODO: Finish
@@ -407,9 +409,9 @@
waitActivelyForDeployment( DeployableTypes.EAR, EAR_UNPACKED, 5000, 18 );
- navTree.getNodeByLabel(NAV_EAR).click();
+ ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- ContentTableRow earRow = new ContentTable().getFirstRowContainingLink(EAR_UNPACKED);
+ ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(EAR_UNPACKED);
// TODO: Finish
@@ -470,8 +472,8 @@
throws HtmlElementNotFoundException, IOException
{
// Refresh / go to the appropriate page.
- navTree.getNodeByLabel( type.getNavTreeLabel() ).click();
- ContentTableRow earRow = new ContentTable().findFirstRowContainingLink(deployableName);
+ ejtt.getNavTree().getNodeByLabel( type.getNavTreeLabel() ).click();
+ ContentTableRow earRow = ejtt.getDefaultContentTable().findFirstRowContainingLink(deployableName);
if( null == earRow ){
log.debug("Row with "+deployableName+" not present.");
return false;
@@ -632,7 +634,7 @@
undeletableFiles.add( path.getAbsolutePath() );
}
- private void deployEar( String earFilePath ) throws IOException
+ private void deployEar( String earFilePath ) throws IOException, HtmlElementNotFoundException
{
if( !(new File(earFilePath)).exists())
throw new FileNotFoundException(earFilePath);
@@ -640,7 +642,7 @@
log.info("Deploying: "+earFilePath);
// Navigate to Enterprise Archives
- navTree.getNodeLink(NAV_EAR).click();
+ ejtt.getNavTree().getNodeLink(NAV_EAR).click();
// click on the "Add new resource" button
client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
@@ -650,7 +652,7 @@
fileInput.setContentType("application/ear");
fileInput.setValueAttribute(earFilePath);
client.click("createContentForm:addButton");
- sleep( 2000 );
+ ejtt.sleep( 2000 );
// Log the message
logServerMessage("Something went wrong with deploy: ");
@@ -660,9 +662,9 @@
{
// Navigate to Enterprise Archives
- navTree.getNodeLink(NAV_EAR).click();
+ ejtt.getNavTree().getNodeLink(NAV_EAR).click();
- tabMenu.clickTab("Summary");
+ ejtt.getTabMenu().clickTab("Summary");
HtmlButtonInput deleteButton = getAppDeleteButton( earFileName );
deleteButton.click();
@@ -671,7 +673,7 @@
logServerMessage("Something went wrong with undeploy: ");
// Sleep for 3 sec.
- sleep( 3000 );
+ ejtt.sleep( 3000 );
}
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-03-11 00:46:33 UTC (rev 207)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-11 02:04:08 UTC (rev 208)
@@ -47,7 +47,7 @@
* Using instance instead of static methods is necessary
* if we want to subclass this tools for AS 4 tests in the future.
*/
- protected final NavTree navTree = new NavTree();
+ public final NavTree navTree = new NavTree();
/**
* Single tab menu instance.
@@ -55,13 +55,21 @@
* Using instance instead of static methods is necessary
* if we want to subclass this tools for AS 4 tests in the future.
*/
- protected final TabMenu tabMenu = new TabMenu();
+ public final TabMenu tabMenu = new TabMenu();
+
+ public NavTree getNavTree() { return navTree; }
+ public TabMenu getTabMenu() { return tabMenu; }
+
+
+
+
+
/**
* Inner class to encapsulate navigation tree operations.
*
@@ -70,7 +78,7 @@
*
* Instead, all these methods call client methods.
*/
- protected class NavTree {
+ public class NavTree {
public static final String ID_NAV_TREE_FORM = "navTreeForm";
@@ -171,7 +179,7 @@
* Represents nav tree node.
* Contains convenience methods to work with the node.
*/
- protected class NavTreeNode {
+ public class NavTreeNode {
/** Keeps the table element of this node. */
private HtmlElement elem;
@@ -227,7 +235,7 @@
/**
* Inner class to encapsulate tab menu operations.
*/
- protected class TabMenu {
+ public class TabMenu {
public TabContentBox getTabContentBox() throws HtmlElementNotFoundException {
@@ -289,7 +297,7 @@
*
* TODO: Instead, use the Page returned from click() etc.
*/
- protected class PageContextAwareElement {
+ public class PageContextAwareElement {
private URL validForURL;
private String validForDate;
@@ -319,12 +327,13 @@
}
}
+
/**
* Base class for parts that will check their validity before performing actions.
* Not necessary if we pay attention to validity, but why not check it.
*/
- protected class PageAware {
+ public class PageAware {
private Page validForPage;
@@ -347,10 +356,13 @@
}
+
+
+
/**
* Inner class for manipulation with tab content box.
*/
- protected class TabContentBox extends PageAware {
+ public class TabContentBox extends PageAware {
private HtmlElement element;
public HtmlElement getElement() { return element; }
@@ -360,13 +372,20 @@
this.element = element;
}
+
/**
+ * Returns pagination wrapper.
+ */
+ public ContentBoxPagination getPagination(){
+ return new ContentBoxPagination();
+ }
+
+
+ /**
* Returns first table under given header.
*
* Unfortunately, headers are not H2 or similar, but DIV class="instructionalText".
* To be revised later.
- *
- * @return
*/
public ContentTable getTableUnderHeader( String headerText ) throws ActionOutOfSyncException
{
@@ -380,9 +399,6 @@
/**
* Returns first table in the content box.
- * @param headerText
- * @return
- * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
*/
public ContentTable getFirstTable() throws ActionOutOfSyncException
{
@@ -396,6 +412,27 @@
/**
+ * Returns table backed by the given table element.
+ */
+ public ContentTable getTable(HtmlTable table)
+ {
+ return new ContentTable(table);
+ }
+
+
+ /**
+ * Creates a data table wrapper for first found element with one of these IDs:
+ * ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE
+ *
+ * @see ContentTable#ContentTable()
+ */
+ public ContentTable getDefaultTable() throws HtmlElementNotFoundException{
+ return new ContentTable();
+ }
+
+
+
+ /**
* Finds first button with given label inside this box.
* @param label
* @return
@@ -422,7 +459,7 @@
/**
* Contains convenience methods for accessing content tables in EmbJopr.
*/
- protected class ContentTable {
+ public class ContentTable {
public static final String ID_CATEGORY_DATA_TABLE = "categorySummaryForm:dataTable";
public static final String ID_RESOURCE_DATA_TABLE = "resourceSummaryForm:dataTable";
@@ -603,13 +640,28 @@
}// inner class ContentTable
+ /**
+ * Creates a data table wrapper for first found element with one of these IDs:
+ * ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE
+ *
+ * This is a shortcut for ejtt.getTabMenu().getTabContentBox().getDefaultTable(),
+ * which we can do because it searches the element using ID.
+ *
+ * @see ContentTable#ContentTable()
+ */
+ public ContentTable getDefaultContentTable() throws HtmlElementNotFoundException{
+ return new ContentTable();
+ }
+
+
+
/**
* Provides extra method that parses text-like info table (with one column).
*/
- protected class ContentInfoTable extends ContentTable {
+ public class ContentInfoTable extends ContentTable {
public ContentInfoTable(HtmlTable element) {
super(element);
@@ -635,13 +687,20 @@
}// inner class ContentInfoTable
+ /**
+ * This is a shortcut for ejtt.getTabMenu().getTabContentBox().getContentInfoTable(tableElement).
+ */
+ public ContentInfoTable getContentInfoTable(HtmlTable tableElement) {
+ return new ContentInfoTable(tableElement);
+ }
+
/**
* Row of a content table.
* Contains convenience methods for accessing content table rows in EmbJopr.
*/
- protected class ContentTableRow {
+ public class ContentTableRow {
private HtmlTableRow element;
public HtmlTableRow getElement() { return element; }
@@ -755,7 +814,7 @@
/**
* Pagination control
- * Not tested yet.
+ * Not much tested yet.
*/
public class ContentBoxPagination {
@@ -766,11 +825,11 @@
private static final String ID_PAGE_SIZE_SELECT = "categorySummaryForm:currentPageSize";
private static final String ID_PAGINATION_TOTAL_ITEMS = "paginationTotalItems";
- protected HtmlDivision getPageContols(){
+ public HtmlDivision getPageContols(){
return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
}
- protected HtmlSelect getPageSizeSelect(){
+ public HtmlSelect getPageSizeSelect(){
return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
}
@@ -891,7 +950,7 @@
public HtmlAnchor getLinkInsideForm(String formId, String linkLabel) throws HtmlElementNotFoundException
{
HtmlForm form = (HtmlForm)client.getElement(formId);
- String xPath = ".//a[contains(normalize-space(), '"+linkLabel+"']";
+ String xPath = ".//a[contains(normalize-space(), '"+linkLabel+"')]";
HtmlAnchor link = form.getFirstByXPath(xPath);
if( null == link )
throw new HtmlElementNotFoundException("Can't find row containing link '"+linkLabel+"' using XPath: "+xPath);
15 years, 10 months
EMBJOPR SVN: r207 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-10 20:46:33 -0400 (Tue, 10 Mar 2009)
New Revision: 207
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.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/as5/ApplicationsPageTest.java
Log:
Moved EmbJoprTestToolkit to standalone class and added an instance of it to EmbJoprTestCase.java
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-11 00:35:30 UTC (rev 206)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-11 00:46:33 UTC (rev 207)
@@ -21,22 +21,14 @@
*/
package org.jboss.jopr.jsfunit;
-import com.gargoylesoftware.htmlunit.ElementNotFoundException;
-import com.gargoylesoftware.htmlunit.Page;
-import java.util.List;
-import java.util.Set;
+import java.io.IOException;
+import java.net.URL;
+import java.util.*;
import javax.management.*;
+import com.gargoylesoftware.htmlunit.*;
+import com.gargoylesoftware.htmlunit.html.*;
import org.jboss.mx.util.MBeanServerLocator;
-
import org.jboss.jopr.jsfunit.exceptions.*;
-import com.gargoylesoftware.htmlunit.html.*;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.w3c.dom.Element;
@@ -1006,40 +998,6 @@
}
-
- // TODO
- protected class JMXDeploymentInfo {
-
- // Etc...
- public boolean isDeployed(){
- return false;
- }
-
- }
-
- // TODO
- protected class FileDeploymentInfo {
-
- // Etc...
- public boolean isDeployed(){
- return false;
- }
-
- }
-
- // TODO
- protected class EmbJoprDeploymentInfo {
-
- // Etc...
- public boolean isDeployed(){
- return false;
- }
-
- }
-
-
-
-
}// ApplicationTestBaseAS5
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-11 00:35:30 UTC (rev 206)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-11 00:46:33 UTC (rev 207)
@@ -22,7 +22,6 @@
package org.jboss.jopr.jsfunit;
-import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.IOException;
@@ -38,19 +37,15 @@
import java.util.regex.Pattern;
import javax.xml.xpath.XPathException;
import org.jboss.profileservice.spi.ProfileService;
-import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
import javax.naming.InitialContext;
-import org.jboss.deployers.spi.management.ManagementView;
import javax.naming.NamingException;
-import org.jboss.managed.api.ComponentType;
-import org.jboss.managed.api.ManagedProperty;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.*;
import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.managed.api.ManagedComponent;
-import org.jboss.managed.api.ManagedDeployment;
-import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
-import java.io.File;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
/**
@@ -67,6 +62,8 @@
protected final Logger log = Logger.getLogger(this.getClass().getName());
+ protected EmbJoprTestToolkit ejtt;
+
protected boolean isJBoss4;
protected JSFClientSession client;
@@ -109,6 +106,7 @@
.getImplementationVersion();
log.info("Detected AS version: " + version);
isJBoss4 = version.startsWith("4");
+
// Initial JSF request
WebClientSpec wcSpec = new WebClientSpec("/", BrowserVersion.FIREFOX_3);
@@ -125,6 +123,7 @@
this.client = jsfSession.getJSFClientSession();
this.server = jsfSession.getJSFServerSession();
+ this.ejtt = new EmbJoprTestToolkit(client, server);
}
@Override
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-11 00:35:30 UTC (rev 206)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ApplicationsPageTest.java 2009-03-11 00:46:33 UTC (rev 207)
@@ -23,21 +23,15 @@
package org.jboss.jopr.jsfunit.as5;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import org.apache.commons.lang.StringUtils;
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
-import org.jboss.jopr.jsfunit.DebugUtils;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
-
-
/**
* This class contains tests for testing the EmbJopr Application
* Management Functions for Enterprise Application archives with JBoss AS 5.
@@ -56,8 +50,8 @@
public void testNavigationToApplications() throws EmbJoprTestException, IOException {
- //DebugUtils.writeFile("target/appNav.html", client.getPageAsText());
-
+ // Wait until the tree is loaded via AJAX.
+ // TODO: navTree.waitForNavTreeLoaded();
sleep(2000);
// Navigate to apps summary tab
@@ -78,7 +72,7 @@
/**
* Test pagination in Applications page.
*
- * FAILS HERE because of EMBJOPR-61.
+ * FAILS because of EMBJOPR-61.
* Bad number of listed rows at page 2. expected:<5> but was:<0>
*/
public void testAppsPagination() throws EmbJoprTestException, IOException {
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-11 00:46:33 UTC (rev 207)
@@ -0,0 +1,949 @@
+
+package org.jboss.jopr.jsfunit.util;
+
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.Page;
+import java.util.*;
+
+import org.jboss.jopr.jsfunit.exceptions.*;
+import com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
+import java.net.URL;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+import org.jboss.jsfunit.jsfsession.*;
+import org.w3c.dom.Element;
+
+
+
+/**
+ * Embedded Jopr Test Toolkit - helps with testing EmbJopr's web UI
+ * by creating object model of the UI.
+ *
+ * @author Ondrej Zizka
+ */
+public class EmbJoprTestToolkit {
+
+ protected JSFClientSession client;
+ protected JSFServerSession server;
+
+ public JSFClientSession getClient() { return client; }
+ public JSFServerSession getServer() { return server; }
+
+
+ public EmbJoprTestToolkit(JSFClientSession client, JSFServerSession server) {
+ this.client = client;
+ this.server = server;
+ }
+
+
+
+
+
+ /**
+ * Single nav tree instance.
+ *
+ * Using instance instead of static methods is necessary
+ * if we want to subclass this tools for AS 4 tests in the future.
+ */
+ protected final NavTree navTree = new NavTree();
+
+ /**
+ * Single tab menu instance.
+ *
+ * Using instance instead of static methods is necessary
+ * if we want to subclass this tools for AS 4 tests in the future.
+ */
+ protected final TabMenu tabMenu = new TabMenu();
+
+
+
+
+
+
+ /**
+ * Inner class to encapsulate navigation tree operations.
+ *
+ * Note that this class does not hold any element reference,
+ * because the reference becomes invalid with every navigation action.
+ *
+ * Instead, all these methods call client methods.
+ */
+ protected class NavTree {
+
+ public static final String ID_NAV_TREE_FORM = "navTreeForm";
+
+ private void clickRootNode() throws IOException, EmbJoprTestException {
+ DomElement element = (DomElement)client.getElement(ID_NAV_TREE_FORM);
+ if( null == element )
+ 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']");
+
+ // No XSLT 2.0 support :(
+ // 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, '"+ID_NAV_TREE_FORM+":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();
+ }
+
+
+ public void waitForNavTreeLoaded(){
+ sleep(1500);///
+ // TODO: Use ActiveConditionChecker
+
+ }
+
+
+ /**
+ * 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 navTreeForm = (DomElement)client.getElement(ID_NAV_TREE_FORM);
+
+ // A table which has an anchor containing given text.
+ // 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+"']]";
+ // Node has @id = navTreeForm:navTree:136:137:138:139:143:195::instanceNodeOrLeafLink
+ // Let's rely on the ":text" id part only and suppose there will be just one link in that TD.
+ String xPath = ".//table[.//td[contains(@id,':text')]//a[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);
+
+ }
+
+
+ /**
+ * Need a standard JSFUnit API to replace this code.
+ * @see getNodeByLabel().getLabelLink()
+ */
+ public HtmlAnchor getNodeLink(String linkLabel) throws HtmlElementNotFoundException
+ {
+ return getLinkInsideForm(ID_NAV_TREE_FORM, linkLabel);
+ }
+
+
+ /**
+ * Finds the arrow icon in the nav tree that corresponds to the resource
+ * 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) throws HtmlElementNotFoundException
+ {
+ HtmlAnchor link = getNodeLink(resourceName);
+ String id = link.getIdAttribute();
+
+ // An example id is: "navTreeForm:navTree:81:82:83:84::typeSummaryLink"
+ // The icon's id would be: "81:82:83:84::typeSummary:handle:img:collapsed"
+ int index = id.lastIndexOf("Link");
+ id = id.substring(0, index) + ":handle";
+ return (ClickableElement)client.getElement(id);
+ }
+
+ }// class NavTree
+
+
+
+ /**
+ * Represents nav tree node.
+ * Contains convenience methods to work with the node.
+ */
+ protected class NavTreeNode {
+
+ /** Keeps the table element of this node. */
+ private HtmlElement elem;
+ public HtmlElement getElement() { return this.elem; }
+
+ private NavTreeNode( HtmlTable nodeTable ){
+ this.elem = nodeTable;
+ }
+
+ /** Returns true if this node is expanded. */
+ public boolean isExpanded() throws EmbJoprTestException
+ {
+ HtmlAnchor arrowLink = this.getArrowLink();
+ HtmlElement img = (HtmlElement)arrowLink.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.");
+
+ }
+
+ /** 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";
+ return (HtmlAnchor) this.elem.getFirstByXPath( xPath );
+ }
+
+ /** Returns the arrow's link. */
+ public HtmlAnchor getArrowLink(){
+ 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();
+ }
+
+
+ }// class NavTreeNode()
+
+
+
+
+
+
+
+
+ /**
+ * Inner class to encapsulate tab menu operations.
+ */
+ protected class TabMenu {
+
+ public TabContentBox getTabContentBox() throws HtmlElementNotFoundException {
+
+ HtmlElement contentElement = (HtmlElement) client.getElement("content");
+ HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath("div[@class='tabmenubox']");
+ if( null == tabContentBox )
+ throw new HtmlElementNotFoundException("Tab content box not found using div[@class='tabmenubox'] XPath");
+
+ return new TabContentBox(tabContentBox);
+ }
+
+ 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+"']";
+ ClickableElement tabContent = element.getFirstByXPath(xPath);
+
+
+ if( null == tabContent )
+ throw new HtmlElementNotFoundException("Tab '"+label+"' not found using XPath '"+xPath+"'");
+
+ return tabContent;
+
+ }
+
+ /** 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");
+ }
+
+ /** 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");
+ }
+
+ /** Shotcut - getTab(label).click(); Not necesarilly clicks an anchor. */
+ public void clickTab( String label ) throws IOException, ActionNotAvailableException, HtmlElementNotFoundException {
+
+ StyledElement tabContent = getTab(label);
+ if( !( tabContent instanceof ClickableElement ) )
+ throw new ActionNotAvailableException("Tab element <"+tabContent.getTagName()+"> is not clickable: "+label);
+
+ ((ClickableElement)tabContent).click();
+
+ }
+
+ }
+
+
+ /**
+ * Base class for parts that will check their validity before performing actions.
+ * Not necessary if we pay attention to validity, but why not check it -
+ * performance is not a question for us.
+ *
+ * TODO: Instead, use the Page returned from click() etc.
+ */
+ protected class PageContextAwareElement {
+ private URL validForURL;
+ private String validForDate;
+
+ /** Store the context identifiing attributes upon creation. */
+ public PageContextAwareElement() {
+ // TODO: Shouldn't we store the elements's page instead of current?
+ this.validForDate = client.getContentPage().getWebResponse().getResponseHeaderValue("Date");
+ this.validForURL = client.getContentPage().getWebResponse().getUrl();
+ }
+
+ /**
+ * Checks whether this element is still valid in the current web page context,
+ * i.e. whether we are still on the page in which this element existed.
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ 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 element wrapper was created from another page and is not valid now.");
+ }
+ }
+
+ }
+
+ /**
+ * Base class for parts that will check their validity before performing actions.
+ * Not necessary if we pay attention to validity, but why not check it.
+ */
+ protected class PageAware {
+
+ private Page validForPage;
+
+ public PageAware(){
+ this.validForPage = client.getContentPage();
+ }
+
+ /**
+ * Checks whether this element is still valid in the current web page context,
+ * i.e. whether we are still on the page in which this element existed.
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ public void checkIfStillValid() throws PageHasChangedException {
+ if( !client.getContentPage().equals( this.validForPage ) ){
+ throw new PageHasChangedException(
+ "This element wrapper was created from another page and is not valid now.",
+ client.getContentPage(), this.validForPage );
+ }
+ }
+ }
+
+
+ /**
+ * Inner class for manipulation with tab content box.
+ */
+ protected class TabContentBox extends PageAware {
+
+ private HtmlElement element;
+ public HtmlElement getElement() { return element; }
+
+ public TabContentBox(HtmlElement element) {
+ super();
+ this.element = element;
+ }
+
+ /**
+ * Returns first table under given header.
+ *
+ * Unfortunately, headers are not H2 or similar, but DIV class="instructionalText".
+ * To be revised later.
+ *
+ * @return
+ */
+ public ContentTable getTableUnderHeader( String headerText ) throws ActionOutOfSyncException
+ {
+ checkIfStillValid();
+
+ String xPath = "*[contains(normalize-space(), '"+headerText+"')]/following::table";
+ // [@id='resourceSummaryForm:dataTable'] - is this reliable?
+ HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
+ return new ContentTable(tableElement);
+ }
+
+ /**
+ * Returns first table in the content box.
+ * @param headerText
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ public ContentTable getFirstTable() throws ActionOutOfSyncException
+ {
+ checkIfStillValid();
+
+ String xPath = ".//form//table[contains( normalize-space(@id), ':dataTable')]";
+ // [@id='resourceSummaryForm:dataTable'] - is this reliable?
+ HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
+ return new ContentTable(tableElement);
+ }
+
+
+ /**
+ * Finds first button with given label inside this box.
+ * @param label
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ public HtmlButtonInput getButtonByLabel( String label )
+ throws HtmlElementNotFoundException, ActionOutOfSyncException {
+
+ checkIfStillValid();
+
+ HtmlButtonInput button = this.element.getFirstByXPath(".//input[normalize-space(@value)='"+label+"']");
+ if( null == button )
+ throw new HtmlElementNotFoundException("Button labelled '"+label+"' not found.");
+
+ return button;
+
+ }
+
+ }// inner class TabContentBox
+
+
+
+ /**
+ * Contains convenience methods for accessing content tables in EmbJopr.
+ */
+ protected class ContentTable {
+
+ public static final String ID_CATEGORY_DATA_TABLE = "categorySummaryForm:dataTable";
+ public static final String ID_RESOURCE_DATA_TABLE = "resourceSummaryForm:dataTable";
+
+ private HtmlTable element;
+ public HtmlTable getElement() { return element; }
+
+ /**
+ * Creates a data table wrapper for the given table element.
+ */
+ public ContentTable( HtmlTable element ) {
+ this.element = element;
+ }
+
+ /**
+ * Creates a data table wrapper for first found element with one of these IDs:
+ * ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE
+ *
+ * This method assumes there's only one "data table" per page.
+ * If not, it simply returns the first in the order of IDs searched.
+ * You can always specify the element using ContentTable( HtmlTable element ).
+ */
+ public ContentTable() throws HtmlElementNotFoundException {
+
+ // Find the data table - try some known IDs.
+ String[] elemIDs = { ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE };
+ Element elem = null;
+ for( String elemID : elemIDs ){
+ elem = client.getElement(elemID);
+ if( null != elem )
+ break;
+ }
+ if( null == elem )
+ throw new HtmlElementNotFoundException(
+ "Can't find the content table element, searched IDs: "
+ + elemIDs.toString() );
+
+ this.element = (HtmlTable)elem;
+ }
+
+
+ // Columns maps
+ private List<String> colLabels = null;
+ private Map<String, Integer> colIndexes = null;
+ //private boolean analyzedButNotFound = false;
+
+
+
+ /**
+ * Returns the first row that contains given text, or throws HtmlElementNotFoundException.
+ * @param text
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * when no row contains specified text.
+ */
+ public ContentTableRow getFirstRowContainingText( String text )
+ throws HtmlElementNotFoundException
+ {
+ if( 0 == element.getRowCount() )
+ throw new HtmlElementNotFoundException("Table has no rows.");
+
+ // TODO: Escape the single quotes. By doubling?
+ // http://books.google.com/books?id=jzqFMlM0gb0C&pg=PA308&lpg=PA308&dq=xquer...
+ String xPath = ".//tr[contains(string(), '"+text+"')]";
+ HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
+ if( null == elm )
+ throw new HtmlElementNotFoundException(xPath);
+ return new ContentTableRow(elm, this);
+ }
+
+
+
+ /**
+ * Returns wrapper of the table row which contains a link with given label,
+ * or null when the no such row is found.
+ */
+ public ContentTableRow findFirstRowContainingLink( String linkLabel )
+ {
+ if( 0 == element.getRowCount() )
+ return null;
+
+ String xPath = ".//tr[.//a[normalize-space()='"+linkLabel+"']]";
+ HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
+ if( null == elm )
+ return null;
+ return new ContentTableRow(elm, this);
+ }
+
+ public List<ContentTableRow> getRows(){
+ if( 0 == element.getRowCount() )
+ return Collections.EMPTY_LIST;
+
+ String xPath = "./tbody/tr";
+ List<HtmlTableRow> trList = (List) element.getByXPath(xPath);
+ List<ContentTableRow> rows = new ArrayList(trList.size());
+ for (HtmlTableRow tr : trList) {
+ rows.add( new ContentTableRow(tr, this));
+ }
+ return rows;
+ }
+
+ /**
+ * Returns wrapper of the table row which contains a link with given label.
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * when no row with such label found.
+ */
+ public ContentTableRow getFirstRowContainingLink( String linkLabel )
+ throws HtmlElementNotFoundException
+ {
+ if( 0 == element.getRowCount() )
+ throw new HtmlElementNotFoundException("Table has no rows.");
+
+ String xPath = ".//tr[.//a[normalize-space()='"+linkLabel+"']]";
+ HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
+ if( null == elm )
+ throw new HtmlElementNotFoundException(
+ "Can't find row containing link '"+linkLabel+"' using XPath: "+xPath);
+ return new ContentTableRow(elm, this);
+ }
+
+ /**
+ * Creates a list of columns headers
+ * and a label => col index map.
+ */
+ public void analyzeColumns() throws HtmlElementNotFoundException
+ {
+
+ /*if( this.analyzedButNotFound )
+ throw new HtmlElementNotFoundException("Table has no column headers.");
+ /**/ // 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 position()=1]/th";
+ List<HtmlTableHeaderCell> colHeaders = (List<HtmlTableHeaderCell>) this.element.getByXPath(xPath);
+
+ if( 0 == colHeaders.size() ){
+ //this.analyzedButNotFound = true;
+ throw new HtmlElementNotFoundException("Table has no column headers.");
+ }
+
+ List<String> colLabels_ = new ArrayList(colHeaders.size());
+ Map<String, Integer> colIndexes_ = new HashMap(colHeaders.size());
+
+ //for( HtmlTableHeaderCell th : colHeaders ){
+ for( int i = 0; i < colHeaders.size(); i++ ) {
+ HtmlTableHeaderCell th = colHeaders.get(i);
+ String sHeader = th.getTextContent();
+ colLabels_.add( sHeader );
+ colIndexes_.put( sHeader, i );
+ }
+
+ this.colLabels = colLabels_;
+ this.colIndexes = colIndexes_;
+
+ }
+
+ /**
+ * Returns an index of the column with given name in the TH header,
+ * or throws HtmlElementNotFound in two cases:
+ * 1) Table does not have column headers
+ * 2) No header with such name was found.
+ *
+ * @param colName
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ */
+ public int getColumnIndexByName( String colName ) throws HtmlElementNotFoundException {
+ if( null == this.colIndexes )
+ this.analyzeColumns();
+
+ Integer index = this.colIndexes.get(colName);
+ if( null == index )
+ throw new HtmlElementNotFoundException("No column named '"+colName+"'.");
+
+ return index;
+ }
+
+ }// inner class ContentTable
+
+
+
+
+
+ /**
+ * Provides extra method that parses text-like info table (with one column).
+ */
+ protected class ContentInfoTable extends ContentTable {
+
+ public ContentInfoTable(HtmlTable element) {
+ super(element);
+ }
+
+ /**
+ * Parses the content of the table for properties.
+ * @return
+ */
+ public Properties getProperties()
+ {
+ Properties props = new Properties();
+
+ // The template has label in span/strong and the value as text in td.
+ String xPath = ".//tr/td[span/strong]";
+ List<HtmlTableCell> cells = (List<HtmlTableCell>) this.getElement().getByXPath(xPath);
+ for( HtmlTableCell cell : cells ){
+ String[] parts = cell.getTextContent().split(":");
+ props.put(parts[0], parts[1]);
+ }
+ return props;
+ }
+
+ }// inner class ContentInfoTable
+
+
+
+ /**
+ * Row of a content table.
+ * Contains convenience methods for accessing content table rows in EmbJopr.
+ */
+ protected class ContentTableRow {
+
+ private HtmlTableRow element;
+ public HtmlTableRow getElement() { return element; }
+
+ private ContentTable containingTable;
+
+ private ContentTableRow(HtmlTableRow elm, ContentTable containingTable) {
+ this.element = elm;
+ this.containingTable = containingTable;
+ }
+
+ /**
+ * 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.
+ * @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 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);
+ if( !(elm instanceof HtmlButton ) && !(elm instanceof HtmlButtonInput) )
+ throw new HtmlElementNotFoundException("Element is not a button, but: "+elm.getClass().getName());
+
+ return (ClickableElement)elm;
+ }
+
+
+ /**
+ * Gives the (first) link from the cell of this row, from the column with given header.
+ * @param colName
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
+ * in two cases:
+ * 1) Table has no column of given name
+ * 2) There's no link in that cell.
+ */
+ public HtmlAnchor getFirstLinkFromColumn(String colName) throws HtmlElementNotFoundException
+ {
+ HtmlTableCell cell = this.getCellByColumnName(colName);
+
+ String xPath = ".//a";
+ HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
+
+ if( null == link )
+ throw new HtmlElementNotFoundException("No link found in column '"+colName+"'");
+
+ return link;
+ }
+
+
+ /**
+ * Returns the link with given label.
+ * @param string
+ */
+ public HtmlAnchor getLinkByLabel(String linkLabel) throws HtmlElementNotFoundException {
+ String xPath = ".//a[normalize-space()='"+linkLabel+"']";
+ HtmlAnchor link = (HtmlAnchor) this.element.getFirstByXPath(xPath);
+ if( null == link ){
+ StringBuilder sb = new StringBuilder();
+ List<HtmlElement> linksFound = this.element.getHtmlElementsByTagName("a");
+ for( HtmlElement linkFound : linksFound ){
+ sb.append("'").append( ((HtmlAnchor)linkFound).getTextContent() ).append("', ");
+ }
+ String availLinks = StringUtils.removeEnd( sb.toString(), ", " );
+
+ throw new HtmlElementNotFoundException("Can't find link using '"+xPath+"', available: "+availLinks);
+ }
+ return link;
+ }
+
+ /**
+ * Returns the cell of this table from given index,
+ * or throws IndexOutOfBoundsException.
+ *
+ * TODO: May throw IndexOutOfBoundsException - leave unchecked?
+ *
+ * @param index
+ * @return
+ */
+ public HtmlTableCell getCell( int index ){
+ HtmlTableCell cell = this.element.getCell(index);
+ 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
+ {
+ 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();
+ }
+
+
+ }// inner class ContentTableRow
+
+
+
+
+ /**
+ * Pagination control
+ * Not tested yet.
+ */
+ public class ContentBoxPagination {
+
+ //private HtmlElement element;
+ //public HtmlElement getElement() { return element; }
+
+ private static final String ID_PAGE_CONTROLS = "categorySummaryForm:dataTableScroller";
+ private static final String ID_PAGE_SIZE_SELECT = "categorySummaryForm:currentPageSize";
+ private static final String ID_PAGINATION_TOTAL_ITEMS = "paginationTotalItems";
+
+ protected HtmlDivision getPageContols(){
+ return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
+ }
+
+ protected HtmlSelect getPageSizeSelect(){
+ return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
+ }
+
+ public int getTotalItemsCount() throws ActionNotAvailableException
+ {
+ Element e = client.getElement(ID_PAGINATION_TOTAL_ITEMS);
+ String textContent = e.getTextContent();
+ String[] parts = textContent.split(":");
+ if( parts.length < 2 )
+ throw new ActionNotAvailableException("Total pagination items count expected after 'Total:' or similar.");
+
+ String countStr = parts[1].trim();
+ try{
+ return NumberUtils.createInteger( countStr );
+ }catch(NumberFormatException ex ){
+ throw new ActionNotAvailableException("Can't parse pagination items count from '"+countStr+"'", ex);
+ }
+ }
+
+ protected HtmlSpan getGoSpan( String spanLabel ) throws HtmlElementNotFoundException {
+ String xPath = ".//span[normalize-space() = '"+spanLabel+"']";
+ HtmlSpan span = getPageContols().getFirstByXPath(xPath);
+ if( null == span )
+ throw new HtmlElementNotFoundException(
+ "Span with '"+spanLabel+"' not found using XPath '"+xPath+"'");
+ return span;
+ }
+
+ protected HtmlTableCell getGoPage( int pageNumber ) throws HtmlElementNotFoundException{
+ String xPath = ".//td[normalize-space() = '"+pageNumber+"']";
+ HtmlElement td = getPageContols().getFirstByXPath(xPath);
+ if( null == td )
+ throw new HtmlElementNotFoundException(
+ "Page number "+pageNumber+" not found. Try 1 - "+this.getPageCount());
+ return (HtmlTableCell) td;
+ }
+
+
+ public boolean goFirst() throws IOException, HtmlElementNotFoundException{
+ // TODO: Compare old and new page object reference?
+ HtmlSpan goSpan = getGoSpan("First");
+ goSpan.click();
+ return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
+ }
+
+ public boolean goPrev() throws IOException, HtmlElementNotFoundException{
+ HtmlSpan goSpan = getGoSpan("Prev");
+ goSpan.click();
+ return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
+ }
+
+ public boolean goNext() throws IOException, HtmlElementNotFoundException{
+ HtmlSpan goSpan = getGoSpan("Next");
+ goSpan.click();
+ return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
+ }
+
+ public boolean goLast() throws IOException, HtmlElementNotFoundException{
+ HtmlSpan goSpan = getGoSpan("Last");
+ goSpan.click();
+ return !"".equals( ((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
+ }
+
+ public void goPage( int pageNumber ) throws IOException, HtmlElementNotFoundException{
+ getGoPage(pageNumber).click();
+ }
+
+
+ public boolean isPageActive( int pageNumber ) throws IOException, HtmlElementNotFoundException{
+ return !getGoPage(pageNumber).getStyleAttribute().contains("-inact");
+ }
+
+ public int getPageCount(){
+ String xPath = ".//td[ count(./*) = 0 and normalize-space() > 0 ]";
+ List<?> elements = getPageContols().getByXPath(xPath);
+ return elements.size();
+ }
+
+ public int getItemsPerPage() throws HtmlElementNotFoundException, ActionNotAvailableException {
+ String selectText = getPageSizeSelect().asText();
+ try {
+ return NumberUtils.createInteger( selectText );
+ }
+ catch( NumberFormatException ex ){
+ throw new ActionNotAvailableException("Can't parse 'items per page' from '"+selectText+"'.", ex);
+ }
+ }
+ public void setItemsPerPage( int num ) throws HtmlElementNotFoundException {
+ String optionValue = ""+num;
+ HtmlSelect pageSizeSelect = getPageSizeSelect();
+
+ try{
+ pageSizeSelect.getOptionByValue(optionValue);
+ }
+ catch( ElementNotFoundException ex ){
+ // Print out available options.
+ StringBuilder sb = new StringBuilder(pageSizeSelect.getOptionSize());
+ for( HtmlOption opt : pageSizeSelect.getOptions() ){
+ sb.append(" ").append(opt.getValueAttribute());
+ }
+ String possibleOptions = sb.toString().trim().replace(" ", ", ");
+
+ throw new HtmlElementNotFoundException("Specified option is invalid. Try one of: "+possibleOptions, ex);
+ }
+
+ pageSizeSelect.setSelectedAttribute(optionValue, true);
+ }
+
+ }// ContentBoxPagination
+
+
+
+ /**
+ * Finds a <a> tag inside a form that has a particular label.
+ *
+ * TODO: Create Form wrapper.
+ */
+ public HtmlAnchor getLinkInsideForm(String formId, String linkLabel) throws HtmlElementNotFoundException
+ {
+ HtmlForm form = (HtmlForm)client.getElement(formId);
+ String xPath = ".//a[contains(normalize-space(), '"+linkLabel+"']";
+ HtmlAnchor link = form.getFirstByXPath(xPath);
+ if( null == link )
+ throw new HtmlElementNotFoundException("Can't find row containing link '"+linkLabel+"' using XPath: "+xPath);
+ return link;
+ }
+
+
+
+
+ /** Calls Thread.sleep(ms), ignores the InterruptedException. */
+ @SuppressWarnings("empty-statement")
+ public static void sleep( int ms ) {
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException ex) {
+ ; // We don't care, that's the purpose of this method.
+ }
+ }
+
+
+
+ // TODO
+ protected class JMXDeploymentInfo {
+
+ // Etc...
+ public boolean isDeployed(){
+ return false;
+ }
+
+ }
+
+ // TODO
+ protected class FileDeploymentInfo {
+
+ // Etc...
+ public boolean isDeployed(){
+ return false;
+ }
+
+ }
+
+ // TODO
+ protected class EmbJoprDeploymentInfo {
+
+ // Etc...
+ public boolean isDeployed(){
+ return false;
+ }
+
+ }
+
+
+
+
+}// class EmbJoprTestToolkit
15 years, 10 months
EMBJOPR SVN: r206 - trunk/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-10 20:35:30 -0400 (Tue, 10 Mar 2009)
New Revision: 206
Modified:
trunk/jsfunit/pom.xml
Log:
Root node summary test put back
Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml 2009-03-10 23:47:02 UTC (rev 205)
+++ trunk/jsfunit/pom.xml 2009-03-11 00:35:30 UTC (rev 206)
@@ -364,11 +364,7 @@
<excludes>
<exclude>**/as4/**</exclude>
<!--
- <exclude>**/as5/*Datasource*</exclude>
-->
- <!-- Temporarily disable as it fails now -->
- <exclude>**/as5/EarTest.java</exclude>
- <exclude>**/*ServerNodeSummaryTest*</exclude>
</excludes>
<systemProperties>
<property>
15 years, 10 months