EMBJOPR SVN: r246 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
by embjopr-commits@lists.jboss.org
Author: fjuma
Date: 2009-03-20 09:03:03 -0400 (Fri, 20 Mar 2009)
New Revision: 246
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
Log:
Fixed the change made to getDeleteButton() in EmbjoprTestCase.java so that we use the variable formId instead of "resourceSummaryForm".
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-20 03:26:13 UTC (rev 245)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-20 13:03:03 UTC (rev 246)
@@ -156,7 +156,7 @@
String[] idElements = id.split(":");
String row = idElements[idElements.length - 2];
// resourceSummaryForm:dataTable:2:removeButton
- return (HtmlButtonInput)client.getElement("resourceSummaryForm:dataTable:" + row + ":removeButton");
+ return (HtmlButtonInput)client.getElement(formId + ":dataTable:" + row + ":removeButton");
}
/**
15 years, 10 months
EMBJOPR SVN: r245 - 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-19 23:26:13 -0400 (Thu, 19 Mar 2009)
New Revision: 245
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.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:
WAR tests created, EAR tests updated, EJTT updates.
EmbjoprTestCase: getNavTreeLink() - changed ID of the Delete button - "resourceSummaryForm:" prepended
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-03-20 03:11:17 UTC (rev 244)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-03-20 03:26:13 UTC (rev 245)
@@ -30,6 +30,7 @@
+
/**
* Information about deployable types -
* navigation tree labels, archive extensions,
@@ -38,18 +39,22 @@
public enum DeployableTypes {
// Mandatory: first, fourth
- EAR(AppConstants.NAV_EAR, ".ear", null, "application/ear"),
- WAR(AppConstants.NAV_WAR, ".war", null, "application/war"),
- EJB(AppConstants.NAV_EJB, ".jar", null, " application/java-archive"),
- SAR(AppConstants.NAV_SAR, ".sar", "-service.xml", "application/sar"),
- RAR(AppConstants.NAV_RAR, ".rar", null, "application/rar"),
- MC_BEAN(AppConstants.NAV_MC, "", null, "application/java-archive");
+ // Nav tree link label, testdata/$dir, extension, suffix, mime type.
+ EAR(AppConstants.NAV_EAR, "ear", ".ear", null, "application/ear"),
+ WAR(AppConstants.NAV_WAR, "war", ".war", null, "application/war"),
+ EJB(AppConstants.NAV_EJB, "ejb", ".jar", null, " application/java-archive"),
+ SAR(AppConstants.NAV_SAR, "sar", ".sar", "-service.xml", "application/sar"),
+ RAR(AppConstants.NAV_RAR, "rar", ".rar", null, "application/rar"),
+ MC_BEAN(AppConstants.NAV_MC, "mc", "", null, "application/java-archive");
// -- Fields --
protected final String navTreeLabel;
public String getNavTreeLabel() { return navTreeLabel; }
+ protected final String dataDir;
+ public String getDataDir() { return dataDir; }
+
protected final String extension;
public String getExtension() { return extension; }
@@ -61,13 +66,17 @@
+
// -- Constructors --
private DeployableTypes(
- String navTreeLabel, String extension,
+ String navTreeLabel,
+ String dataDir,
+ String extension,
String suffix, String mimeType)
{
this.navTreeLabel = navTreeLabel;
+ this.dataDir = dataDir;
this.extension = extension;
this.suffix = suffix;
this.mimeType = mimeType;
@@ -75,8 +84,8 @@
}// enum DeployableTypes
+
-
/** Several ways how to deploy / undeploy. */
public enum DeploymentMeans {
VIA_EMBJOPR,
@@ -98,14 +107,19 @@
public static final String NAV_WAR = "Web Application (WAR)s";
public static final String EAR_MALFORMED_APP_FILENAME = "malformed-application-xml.ear";
+ public static final String WAR_FILENAME_MALFORMED_APP = "malformed-web-xml.war";
// Test Archives
public static final String BASIC_JAR = "deployment-ejb.jar";
public static final String BASIC_EAR = "eardeployment.ear";
public static final String EAR_UNPACKED = "unpacked-ear1.ear";
public static final String EAR_UNPACKED_ZIP = "unpacked-ear1.ear.zip";
+
public static final String BASIC_WAR = "hellothere.war";
+ public static final String WAR_UNPACKED = "unpacked-web1.war";
+ public static final String WAR_UNPACKED_ZIP = "unpacked-web1.war.zip";
+
// Defaults
public static final String[] WAR_DEFAULTS = new String[]{
"ROOT.war", "invoker.war",
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-20 03:11:17 UTC (rev 244)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-20 03:26:13 UTC (rev 245)
@@ -155,7 +155,8 @@
String id = link.getIdAttribute();
String[] idElements = id.split(":");
String row = idElements[idElements.length - 2];
- return (HtmlButtonInput)client.getElement("dataTable:" + row + ":removeButton");
+ // resourceSummaryForm:dataTable:2:removeButton
+ return (HtmlButtonInput)client.getElement("resourceSummaryForm:dataTable:" + row + ":removeButton");
}
/**
@@ -173,9 +174,7 @@
if (linkText.contains(linkLabel)) return link;
}
- throw new IllegalStateException("Link for '"
- + linkLabel
- + "' not found.");
+ throw new IllegalStateException("Link for '"+ linkLabel +"' not found.");
}
/**
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-20 03:11:17 UTC (rev 244)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-03-20 03:26:13 UTC (rev 245)
@@ -434,7 +434,7 @@
/**
- * Changes EAR configuration, and checks whether the changes were saved.
+ * Changes EAR configuration, and verifies that the changes were NOT saved.
*
* FAILS because some of the values are read-only. EMBJOPR-96
*/
@@ -457,8 +457,8 @@
// Load properties (we will use their names).
Properties propsToSet = new Properties();
- String filePath = ejtt.getTestDataDir()+"/ear/"+"ear-conf-basic.properties";
- propsToSet.load(new FileInputStream( filePath ));
+ String propsFilePath = ejtt.getTestDataDir()+"/ear/"+"ear-conf-basic.properties";
+ propsToSet.load(new FileInputStream( propsFilePath ));
// Get the current properties.
Properties propsOriginal = getFormPropertiesValues( propsToSet );
@@ -485,9 +485,7 @@
/**
- * Changes EAR configuration, and checks whether the changes were saved.
- *
- * FAILS because some of the values are read-only. EMBJOPR-96
+ * Redeploys EAR.
*/
public void testEarRedeployment() throws IOException, EmbJoprTestException {
@@ -526,9 +524,9 @@
/**
* Deploys exploded EAR and checks whether it is reported as exploded.
*
- * FAILS: EMBJOPR-95
+ * DISABLED - Badly written test, to be fixed. TODO: Hot-deploy
*/
- public void testUnzippedEarReportedAsExploded() throws IOException, EmbJoprTestException {
+ public void DISABLEDtestUnzippedEarReportedAsExploded() throws IOException, EmbJoprTestException {
// Deploy the EAR.
String earFilePath = ejtt.getTestDataDir() + "/ear/"+BASIC_EAR;
@@ -665,7 +663,7 @@
}
finally {
// Delete the EAR dir.
- deleteFromDeployDir(EAR_UNPACKED_ZIP);
+ deleteFromDeployDir(EAR_UNPACKED);
}
}
@@ -845,7 +843,7 @@
- // TODO: Move to utils
+ // TODO: Moved to EJTT, remove from here.
private void deleteFromDeployDir( String deployableName ) throws IOException{
String deployDir = ejtt.getDeployDir();
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-03-20 03:11:17 UTC (rev 244)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-03-20 03:26:13 UTC (rev 245)
@@ -22,36 +22,43 @@
package org.jboss.jopr.jsfunit.as5;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletRequest;
+import com.gargoylesoftware.htmlunit.WebClient;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
+
import org.jboss.jopr.jsfunit.*;
import com.gargoylesoftware.htmlunit.html.*;
-import java.io.IOException;
+import java.io.*;
+import java.util.Properties;
+import javax.faces.application.FacesMessage;
import junit.framework.Test;
import junit.framework.TestSuite;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import com.gargoylesoftware.htmlunit.WebClient;
-import java.io.File;
-import java.io.FileNotFoundException;
-import org.jboss.jopr.jsfunit.exceptions.ActionNotAvailableException;
-import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
+import org.apache.commons.lang.math.RandomUtils;
+import org.jboss.jopr.jsfunit.exceptions.*;
+import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
+import org.jboss.jopr.jsfunit.util.DescribedCondition;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
+import org.w3c.dom.Node;
-
-
/**
* This class contains tests for testing the EmbJopr Application
* Management Functions for Web Components with JBoss AS 5.
- *
- * @author Shelly McGowan
*
+ * Most tests currently fail because of
+ * JBAS-6640: Undeploying and deploying the same WAR in short time fails.
*/
public class WarTest extends ApplicationTestBaseAS5 {
+ public static final int DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL = 6000;
+ public static final int DEPLOY_UP_STATE_WAIT_CHECK_RETRIES = 50;
+
+
+
/**
- * @return the suite of tests being tested
- */
-
- public static Test suite()
- {
+ * @return the suite of tests being tested
+ */
+ public static Test suite() {
return new TestSuite(WarTest.class);
}
@@ -90,6 +97,10 @@
HtmlPage page = (HtmlPage)webClient.getPage("http://localhost:" + port + "/hellothere/hello.jsp");
assertTrue(page.asText().contains("HELLO WORLD"));
+ }
+ finally {
+ //undeployWAR(BASIC_WAR);
+
// Undeploy the WAR
HtmlButtonInput deleteButton = getAppDeleteButton(BASIC_WAR);
deleteButton.click();
@@ -98,14 +109,598 @@
// reason, JBoss doesn't undeploy the MBeans
// JBAS-XXXX
//assertFalse(isWarDeployed(BASIC_WAR));
+
}
+ }
+
+
+
+
+
+
+ public void DISABLEDtestBadWarRedeploy() throws IOException, HtmlElementNotFoundException, ActionNotAvailableException {
+
+ try {
+ String filePath = ejtt.getTestDataDir() + "/war/"+AppConstants.WAR_FILENAME_MALFORMED_APP;
+ deployWAR(filePath);
+
+ checkClientAndServerMessages("Failed to create Resource", "Failed to create Resource", true);
+ }
finally {
undeployWAR(BASIC_WAR);
}
}
+
+
+
+
+
+ public void testNavigationToWar() throws IOException, HtmlElementNotFoundException, ActionOutOfSyncException, ActionNotAvailableException, EmbJoprTestException, InterruptedException, ActionOutOfSyncException
+ {
+
+ // JBossAS Servers node
+ NavTreeNode nodeServers = ejtt.getNavTree().getNodeByLabel("JBossAS Servers");
+ nodeServers.click();
+
+ {
+ String headerText = "JBossAS Server";
+
+ assertTrue("Page doesn't contain the header: "+headerText,
+ client.getPageAsText().contains(headerText));
+
+ assertTrue("EmbJopr should list at least one server (the one it is running on)" +
+ " and that should be in the UP sate.",
+ client.getPageAsText().contains("UP"));
+ // Check whether the server is listed. If not, Exception is thrown.
+ ContentTableRow row =
+ ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("JBoss Application Server")
+ .getFirstRowContainingLink("JBoss App Server:default");
+ // Click the server link
+ //HtmlAnchor link row.getLinkByLabel("JBoss App Server:default");
+ Node firstLink = row.getCellByColumnName("Name").getElementsByTagName("a").item(0);
+ if( null == firstLink || !(firstLink instanceof HtmlAnchor) )
+ throw new HtmlElementNotFoundException("Can't find the server link.");
+
+ ((HtmlAnchor)firstLink).click();
+ }
+
+ // JBoss App Server:${config} node
+ {
+ String pageText = client.getPageAsText();
+
+ String headerText = "JBoss App Server:default";
+ assertTrue("Page doesn't contain the header: "+headerText,
+ pageText.contains(headerText));
+
+ headerText = "General Properties";
+ assertTrue("Page doesn't contain the header: "+headerText,
+ pageText.contains(headerText));
+
+ // TODO: This page reports "Version:5.0 CR1" - EMBJOPR-77
+
+ ejtt.getNavTree().getNodeByLabel("Applications").click();
+
+ }
+
+
+ // Applications node
+ {
+ // Whooo-hooo! So much to click through!
+
+ 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 = 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.
+ HtmlAnchor link = row.getFirstLinkFromColumn("Name");
+ link.click();
+ }
+
+
+ {
+ // Go back to applications Sumary screen.
+ ejtt.getNavTree().getNodeByLabel("Applications").click();
+ }
+
+
+ // Concrete appliction node.
+ {
+
+ // Deploy the WAR.
+ String filePath = ejtt.getTestDataDir() + "/war/"+BASIC_WAR;
+ deployWarRepeatedly( filePath );
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+
+ // Get to the app through listing.
+ log.debug("Looking for row with: "+BASIC_WAR);
+
+ // Commented out: we would have to click trough pages.
+ //ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+ ContentTableRow row = ejtt.getTabMenu().getTabContentBox()
+ .findLinkRowInDataTableUsingPagination(BASIC_WAR);
+
+ assertTrue("Page doesn't list "+BASIC_WAR+" in Summary tab.", row != null );
+
+ // Go to the summary through listed item.
+ row.getLinkByLabel(BASIC_WAR).click();
+ /**/
+
+
+ // Other way to get to app: through nav tree.
+ ejtt.getNavTree().getNodeArrow(NAV_WAR).click();
+ ejtt.navTree.waitUntilNodeLoadedByAjax(BASIC_WAR, 500, 15);
+ ejtt.navTree.getNodeByLabel(BASIC_WAR).click();
+ /**/
+
+
+ // Check that we have the summary tab for the selected WAR.
+ assertTrue( "WAR name "+BASIC_WAR+" not found in the content box.",
+ ejtt.getTabMenu().getTabContentBox().getElement().getTextContent().contains(BASIC_WAR) );
+
+ // Go to the summary through nav tree node.
+ NavTreeNode appNode = ejtt.getNavTree().getNodeByLabel(NAV_WAR);
+ if( !appNode.isExpanded() ){
+ log.info("Expanding.");
+ appNode.getArrowLink().click();
+ Thread.sleep(2000);
+ }
+ ejtt.getNavTree().getNodeByLabel(BASIC_WAR).click();
+ // Check that we have the summary tab for the selected WAR.
+ ejtt.getTabMenu().getTabContentBox().getElement().getTextContent().contains(BASIC_WAR);
+
+ undeployWAR(BASIC_WAR);
+
+ }
+
+
+ }// testNavigationToWar()
+
+
+
+
+
+
+
/**
+ * Tests the values shown in the Summary tab of WAR.
+ *
+ * FAILS because of: EMBJOPR-110
+ */
+ public void testWarSummaryTab() throws EmbJoprTestException, IOException, Exception {
+
+ final int DEPLOY_TIMEOUT_SEC = 120;
+
+ // Deploy the WAR
+ String appFilePath = System.getProperty(SYSPROP_TESTDATA_DIR) + "/war/"+BASIC_WAR;
+ deployWarRepeatedly( appFilePath );
+
+ try {
+
+ // Wait until the WAR appears...
+ // Should be present when the page is reloaded.
+ // TODO: Replace with waitUntil~()
+ new ActiveConditionChecker(new DescribedCondition("WAR appears in Summary tab list") {
+ public boolean isTrue() throws Exception {
+ // Refresh, then check.
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ContentTableRow appRow = ejtt.getDefaultContentTable().findFirstRowContainingLink(BASIC_WAR);
+ return null != appRow;
+ }
+ }).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(2000, 5);
+ /**/
+
+
+ ContentTableRow appRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+
+ // Wait until the Status is "UP".
+ // TODO: Replace with ActiveConditionChecker.
+ int maxLoops = DEPLOY_TIMEOUT_SEC;
+ do {
+ String statusText = appRow.getCellTextByColumnName("Status");
+ log.debug("WAR Status: "+statusText);
+ if( "UP".equals(statusText) )
+ break;
+
+ // Refresh page after 1 second.
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ appRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+
+ // We don't want an infinite loop by mistake.
+ if( maxLoops-- <= 0 ){
+ throw new EmbJoprTestException("WAR "+BASIC_WAR+" not UP after "+DEPLOY_TIMEOUT_SEC+" seconds.");
+ }
+ } while( true );
+
+ // FAILS because of EMBJOPR-80.
+ appRow.getLinkByLabel(BASIC_WAR).click();
+
+
+ // Check the values in info table(s)
+
+ // General Properties
+ HtmlTable genpropTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("General Properties").getElement();
+ ContentInfoTable infoTable = ejtt.getContentInfoTable( genpropTable );
+ Properties props = infoTable.getProperties();
+ log.info("General Properties: "+props.toString());
+
+ assertEquals(BASIC_WAR, props.getProperty("Name").trim());
+ //assertEquals("?", props.getProperty("Version")); // TODO: Where does RHQ get the version from?
+
+
+ // Resource Traits
+ infoTable = ejtt.getContentInfoTable(
+ ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Resource Traits").getElement() );
+ props = infoTable.getProperties();
+ log.info("Resource Traits: "+props.toString());
+ log.debug("Path: "+props.getProperty("Path"));///
+
+
+ String path = ejtt.getDeployDir()+"/"+BASIC_WAR;
+ assertEquals(path, props.getProperty("Path").trim());
+ assertEquals("no", props.getProperty("Exploded?").trim());
+
+ // Metrics Summary
+ HtmlTable summaryTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Metrics Summary").getElement();
+ infoTable = ejtt.getContentInfoTable(summaryTable);
+ // (nothing here yet)
+
+
+ }
+ finally {
+ // Undeploy the WAR
+ undeployWAR( BASIC_WAR );
+ }
+
+ }// testWarSummary()
+
+
+
+
+
+
+
+ /**
+ * Changes WAR configuration, and checks whether the changes were saved.
+ *
+ * FAILS because some of the values are read-only. EMBJOPR-96
+ */
+ public void testWarConfigurationTab() throws IOException, EmbJoprTestException, HtmlElementNotFoundException, Exception {
+
+ // Deploy the WAR.
+ String filePath = ejtt.getTestDataDir() +"/war/"+ BASIC_WAR;
+ deployWarRepeatedly( filePath );
+
+ try {
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, BASIC_WAR, DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+ // Navigate to the Configuration tab
+ ContentTableRow appRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+ appRow.getLinkByLabel(BASIC_WAR).click();
+ ejtt.tabMenu.clickConfigurationTab();
+
+ // Read properties.
+ Properties props = new Properties();
+ String propsFilePath = ejtt.getTestDataDir()+"/war/"+"war-conf-basic.properties";
+ props.load(new FileInputStream( propsFilePath ));
+
+
+ // Set the configuration options and Save
+ fillOutForm(props);
+ //ejtt.getTabMenu().getTabContentBox().getButtonByLabel("Save");
+ ejtt.getClickableByID("resourceConfigurationForm:saveButton").click();
+
+
+ // Check whether the properties were saved.
+ ejtt.tabMenu.clickConfigurationTab();
+
+ // TODO: We don't see the success message! EMBJOPR-89
+ //checkClientAndServerMessages("successfully", "successfully", false);
+
+ // FAILS because some of the values are read-only. EMBJOPR-96
+ checkForm(props);
+
+ // TODO: Finish when the properties are marked read-only.
+
+ }
+ finally {
+ undeployWAR(BASIC_WAR);
+ }
+
+ }
+
+
+
+
+
+ /**
+ * Changes WAR configuration, and verifies that the changes were NOT saved.
+ *
+ * FAILS because some of the values are read-only. EMBJOPR-96
+ */
+ public void testWarConfigurationTabCancel() throws IOException, EmbJoprTestException {
+
+ // Deploy the WAR.
+ String filePath = ejtt.getTestDataDir() +"/war/"+ BASIC_WAR;
+ deployWarRepeatedly( filePath );
+
+ try {
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, BASIC_WAR,
+ DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+ // Navigate to the Configuration tab
+ ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+ row.getLinkByLabel(BASIC_WAR).click();
+ ejtt.tabMenu.clickConfigurationTab();
+
+
+ // Load properties (we will use their names).
+ Properties propsToSet = new Properties();
+ String propsFilePath = ejtt.getTestDataDir()+"/war/"+"war-conf-basic.properties";
+ propsToSet.load(new FileInputStream( propsFilePath ));
+
+ // Get the current properties.
+ Properties propsOriginal = getFormPropertiesValues( propsToSet );
+
+
+ // Set the configuration options and CANCEL
+ fillOutForm( propsToSet );
+ ejtt.getClickableByID("resourceConfigurationForm:cancelButton").click();
+
+
+ // TODO: We should get back to Conf tab automatically: EMBJOPR-100
+ ejtt.tabMenu.clickConfigurationTab();
+
+ // Now check whether the values are the same as before editing.
+ checkForm( propsOriginal );
+
+ }
+ finally {
+ undeployWAR(BASIC_WAR);
+ }
+
+ }
+
+
+
+
+ /**
+ * Redeploys WAR.
+ *
+ * Fails because of: EMBJOPR-109
+ */
+ public void testWarRedeployment() throws IOException, EmbJoprTestException {
+
+ // Deploy the WAR.
+ String appFilePath = ejtt.getTestDataDir() +"/war/"+ BASIC_WAR;
+ deployWarRepeatedly( appFilePath );
+
+ try {
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, BASIC_WAR, DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+ // Navigate to the Configuration tab
+ ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+ row.getLinkByLabel(BASIC_WAR).click();
+ ejtt.tabMenu.clickContentTab();
+
+ String xPath = ".//table//input[@type='file']";
+ HtmlFileInput fileInput = ejtt.tabMenu.getTabContentBox().getElement().getFirstByXPath(xPath);
+ fileInput.setValueAttribute(appFilePath);
+ xPath = ".//table//input[@type='submit']";
+ HtmlSubmitInput submit = ejtt.tabMenu.getTabContentBox().getElement().getFirstByXPath(xPath);
+ submit.click();
+
+ }
+ finally {
+ DebugUtils.writeFile("target/redeployment.html", client.getPageAsText());///
+ undeployWAR(BASIC_WAR);
+ }
+
+ }
+
+
+
+ /**
+ * Deploys exploded WAR and checks whether it is reported as exploded.
+ *
+ * DISABLED - Badly written test, to be fixed. TODO: Hot-deploy
+ */
+ public void DISABLEDtestUnzippedWarReportedAsExploded() throws IOException, EmbJoprTestException {
+
+ // Deploy the WAR.
+ String WARFilePath = ejtt.getTestDataDir() + "/war/"+BASIC_WAR;
+ deployWarRepeatedly( WARFilePath );
+
+ try {
+ // Wait for WAR to be deployed and UP
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, BASIC_WAR, DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+ // Click the WAR link
+ ejtt.getTabMenu().getTabContentBox().getFirstTable()
+ .getFirstRowContainingText(BASIC_WAR).getFirstLinkFromColumn("Name").click();
+
+ DebugUtils.writeFile("target/res_traits.html", client.getPageAsText());///
+
+ ContentTable table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Resource Traits");
+ ContentInfoTable infoTable = ejtt.getTabMenu().getTabContentBox().getContentInfoTable(table.getElement());
+ Properties props = infoTable.getProperties();
+ log.info("Resource Traits: "+props.toString());
+ log.debug("Exploded?: "+props.getProperty("Exploded?"));
+
+ assertEquals("'Exploded?' should be 'yes'", "yes", props.getProperty("Exploded?")/*.toLowerCase()*/ );
+
+ }
+ finally {
+ undeployWAR(BASIC_WAR);
+ }
+
+ }
+
+
+
+
+ /**
+ * Checks WAR metrics tab.
+ */
+ public void testWarMetricsTab() throws IOException, EmbJoprTestException {
+
+ // Deploy the WAR.
+ String WARFilePath = ejtt.getTestDataDir() + "/war/"+BASIC_WAR;
+ deployWarRepeatedly( WARFilePath );
+
+ try {
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, BASIC_WAR, DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+ // Navigate to the Metrics tab
+ ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+ row.getLinkByLabel(BASIC_WAR).click();
+ ejtt.tabMenu.clickMetricsTab();
+
+ // Resource Traits
+
+ // Check the Path.
+ HtmlTable tbl = ejtt.getTabMenu().getTabContentBox().
+ getTableUnderHeader("Trait Values").getElement();
+ ContentInfoTable infoTable = ejtt.getContentInfoTable( tbl );
+ Properties props = infoTable.getProperties();
+
+ String path = ejtt.getDeployDir()+"/"+BASIC_WAR;
+ assertEquals(path, props.getProperty("Path").trim());
+
+
+ }
+ finally {
+ undeployWAR(BASIC_WAR);
+ }
+
+ }
+
+
+ /**
+ * Changes WAR configuration, and checks whether the changes were saved.
+ *
+ * FAILS because some of the values are read-only. EMBJOPR-96
+ */
+ public void testWarMetricsTabRefreshButton() throws IOException, EmbJoprTestException, HtmlElementNotFoundException, Exception {
+
+ // Deploy the WAR.
+ String WARFilePath = ejtt.getTestDataDir() + "/war/"+BASIC_WAR;
+ deployWarRepeatedly( WARFilePath );
+
+ try {
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, BASIC_WAR,
+ DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+ // Navigate to the Metrics tab
+ ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_WAR);
+ row.getLinkByLabel(BASIC_WAR).click();
+ ejtt.tabMenu.clickMetricsTab();
+
+ // Click the Refresh button.
+ // Can this change to submit? Perhaps set an ID and use ejtt.getClickableById().
+ ejtt.tabMenu.getTabContentBox().getButtonByLabel("Refresh").click();
+
+ // Check that we are still on the right tab.
+ assertTrue("Metrics tab is active", ejtt.tabMenu.isTabActive("Metrics") );
+ assertTrue("Page contains WAR name", client.getPageAsText().contains(BASIC_WAR) );
+ assertTrue("Page contains 'Refresh'", client.getPageAsText().contains("Refresh") );
+
+ }
+ finally {
+ undeployWAR(BASIC_WAR);
+ }
+
+ }
+
+
+ /**
+ * Deploys an exploded WAR application.
+ *
+ * FAILS when undeploying, because:
+ *
+org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException: Couldn't delete following files:
+ /home/ondra/work/JOPRembedded/embjopr-svn-trunk/jsfunit/target/jboss5x/deploy/unpacked-web1.war
+
+ at org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit$Deployment.deleteDirectory(EmbJoprTestToolkit.java:1662)
+ at org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit$Deployment.deleteFromDeployDir(EmbJoprTestToolkit.java:1652)
+ at org.jboss.jopr.jsfunit.as5.WarTest.testDeployUnpackedWar(WarTest.java:663)
+ *
+ * TODO: Catch exceptions in finally and log them only (in all tests),
+ * to get the eventual real exception from the try block.
+ *
+ * TODO: Think up how to simulate hot-undeploy.
+ * Should we rename it to other dir and then delete?
+ *
+ * Perhaps it just still didn't process the deployed war when trying to undeploy?
+ * "Condition 'WAR unpacked-web1.war appears in embjopr as deployed' not satisfied,
+ * 0 retries left. Leaving the wait loop."
+ * Should we wait more? Or is it caused by failures of some previous tests?
+ *
+ */
+ public void testDeployUnpackedWar() throws IOException, EmbJoprTestException {
+
+
+ // Deploy the unpacked WAR.
+ // We have to use hotdeploy - can't upload a directory.
+ log.info("Unzipping war/"+WAR_UNPACKED_ZIP);
+ ejtt.deployment.unzipToDeployDir("war/"+WAR_UNPACKED_ZIP, "");
+
+ try {
+ // Loop, wait for the app to appear.
+ log.info("Waiting for WAR to appear.");
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.WAR, WAR_UNPACKED,
+ DEPLOY_UP_STATE_WAIT_CHECK_INTERVAL, DEPLOY_UP_STATE_WAIT_CHECK_RETRIES, this);
+
+
+ ejtt.getNavTree().getNodeByLabel(NAV_WAR).click();
+
+ ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(WAR_UNPACKED);
+
+ // TODO: Finish
+
+ // TODO: Check whether Exploded?: yes. EMBJOPR-95
+
+ // TODO: DeploymentUtils, DeployableTypes, isAvailable enum inner classes
+
+ // TODO: Preliminary test - check system properties, their validity, java version, etc.
+ }
+ finally {
+ // Delete the WAR dir.
+ ejtt.deployment.deleteFromDeployDir(WAR_UNPACKED);
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+ /**
* Deploys WAR.
*/
private void deployWAR( String warFilePath )
@@ -128,28 +723,91 @@
fileInput.setContentType("application/war");
fileInput.setValueAttribute(warFilePath);
client.click("createContentForm:addButton");
+
+ // Log server message.
+ ejtt.logServerMessage();
+
+ // Todo: Write some waitUntilDeployed().
ejtt.sleep( 2000 );
}
+
+ /**
+ * Deploys WAR; if fails, waits 5 seconds and re-tries; this is repeated 3 times.
+ */
+ private void deployWarRepeatedly( final String warFilePath )
+ throws IOException, HtmlElementNotFoundException, EmbJoprTestException
+ {
+
+ try {
+
+ // Try it 3x in 5 second interval.
+ new ActiveConditionChecker( new DescribedCondition("WAR '"+warFilePath+"' succesfuly deployed") {
+ public boolean isTrue() throws Exception {
+ deployWAR(warFilePath);
+ if( server.getFacesMessages().hasNext() ){
+ FacesMessage msg = server.getFacesMessages().next();
+ if( msg.getSeverity() == FacesMessage.SEVERITY_INFO )
+ return true;
+ else
+ ejtt.logServerMessage("Deployment error: ");
+ }
+ return false;
+ }
+ }).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(5000, 3);
+
+ }
+ catch( Exception ex ){
+ throw new EmbJoprTestException(ex.getMessage());
+ }
+
+
+ }// deployWarRepeatedly()
+
+
+ /**
+ * Undeploys war.
+ *
+ * TODO: When tested, merge to EJTT.Deployment.
+ */
private void undeployWAR( String warFileName )
throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
{
// Navigate to Enterprise Archives
- ejtt.getNavTree().getNodeLink(NAV_EAR).click();
+ ejtt.getNavTree().getNodeLink(NAV_WAR).click();
ejtt.getTabMenu().clickSummaryTab();
- HtmlButtonInput deleteButton = getAppDeleteButton( warFileName );
- deleteButton.click();
+ /// DEBUG dump
+ //String dumpFile = "undeploy"+RandomUtils.nextInt()+".html";
+ //log.debug("Dumping page to: "+dumpFile);
+ //DebugUtils.writeFile(dumpFile, client.getPageAsText());
+ //HtmlButtonInput deleteButton = getAppDeleteButton( warFileName ).click();
+
+ // Find the row containing the deployable. Use the pagination if needed.
+ ContentTableRow appRow = ejtt.getTabMenu().getTabContentBox().
+ findLinkRowInDataTableUsingPagination(warFileName);
+
+ /// DEBUG dump
+ //log.debug("Dumping page to: "+dumpFile+"2");
+ //DebugUtils.writeFile(dumpFile+"2", client.getPageAsText());
+
+ if( null == appRow ){
+ log.warn("Can't find row with WAR to undeploy: "+warFileName);
+ return;
+ }
+
+ appRow.getButtonByLabel("Delete").click();
+
// Log the message (with prefix of potential warning)
ejtt.logServerMessage("Something went wrong with undeploy: ");
- // Sleep for 3 sec. TODO: write some waitForUndeployed()
- ejtt.sleep( 3000 );
+ // Sleep for 3 sec. TODO: write some waitForUndeployed(), as negation of opposite.
+ ejtt.sleep( 2000 );
}
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-20 03:11:17 UTC (rev 244)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java 2009-03-20 03:26:13 UTC (rev 245)
@@ -3,6 +3,7 @@
import org.jboss.jopr.jsfunit.*;
import org.apache.commons.lang.StringUtils;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jsfunit.jsfsession.JSFClientSession;
import org.jboss.logging.*;
@@ -17,9 +18,12 @@
Condition condition;
private boolean dumpPageOnTimout = false;
private boolean throwExceptionOnTimout = false;
- private EmbjoprTestCase test;
+ // Used when dumping the page in case of exceeded timeout.
+ private String dumpFileName;
+ private JSFClientSession client;
+
public ActiveConditionChecker(Condition condition) {
this.condition = condition;
}
@@ -31,9 +35,20 @@
log.info("Waiting for condition: "+condition.getDescription());
while( retries-- > 0 ){
- if( this.condition.isTrue() )
+ if( this.condition.isTrue() ){
+ log.info(" Condition '"+condition.getDescription()+"' satisfied.");
return true;
- log.info(" Condition not satisfied, "+retries+" left. Sleeping for "+msInterval+" ms.");
+ }
+
+ if( retries <= 0){
+ log.info(" Condition '"+condition.getDescription()+"' not satisfied, "
+ +retries+" retries left. Leaving the wait loop.");
+ break;
+ }
+
+
+ log.info(" Condition '"+condition.getDescription()+"' not satisfied, "
+ +retries+" retries left. Sleeping for "+msInterval+" ms.");
try {
Thread.sleep(msInterval);
} catch (InterruptedException ex){
@@ -46,7 +61,8 @@
if( this.dumpPageOnTimout ){
try {
// Since this is still inner class, we could use 'this'.
- DebugUtils.writeFile("target/"+test.getName()+".html", test.getClient().getPageAsText());///
+ log.info("Dumping page text to: "+this.dumpFileName);
+ DebugUtils.writeFile("target/"+this.dumpFileName, this.client.getPageAsText());///
} catch (Exception ex) { log.error("Can't dump page.", ex); }
}
@@ -67,8 +83,15 @@
// This has nothing to do with condition checking, but is convenient shorthand...
public ActiveConditionChecker dumpPageOnTimeout(EmbjoprTestCase test) {
+ if( null == test ) return this;
+ return dumpPageOnTimeout( test.getName()+".html", test.getClient() );
+ }
+
+ // This has nothing to do with condition checking, but is convenient shorthand...
+ public ActiveConditionChecker dumpPageOnTimeout(String dumpFileName, JSFClientSession client) {
this.dumpPageOnTimout = true;
- this.test = test;
+ this.dumpFileName = dumpFileName;
+ this.client = client;
return this;
}
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-20 03:11:17 UTC (rev 244)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-20 03:26:13 UTC (rev 245)
@@ -6,17 +6,27 @@
import com.gargoylesoftware.htmlunit.Page;
import java.util.*;
+import java.util.logging.Level;
import org.jboss.jopr.jsfunit.exceptions.*;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import javax.faces.application.FacesMessage;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.jboss.jopr.jsfunit.AppConstants;
+import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
+import org.jboss.jopr.jsfunit.DebugUtils;
+import org.jboss.jopr.jsfunit.EmbjoprTestCase;
import org.jboss.jsfunit.jsfsession.*;
import org.jboss.logging.Logger;
import org.mozilla.javascript.NativeFunction;
@@ -385,18 +395,19 @@
*/
public class TabMenu {
- public TabContentBox getTabContentBox() throws HtmlElementNotFoundException {
-
+ public TabContentBox getTabContentBox() throws HtmlElementNotFoundException
+ {
HtmlElement contentElement = (HtmlElement) client.getElement("content");
- HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath("div[@class='tabmenubox']");
+ String xPath = "div[@class='tabmenubox' or @class='notabmenubox']";
+ HtmlElement tabContentBox = (HtmlElement) contentElement.getFirstByXPath(xPath);
if( null == tabContentBox )
- throw new HtmlElementNotFoundException("Tab content box not found using div[@class='tabmenubox'] XPath");
+ throw new HtmlElementNotFoundException("Tab content box not found using XPath: "+xPath);
return new TabContentBox(tabContentBox);
}
- public ClickableElement getTabByLabel( String label ) throws HtmlElementNotFoundException {
-
+ public ClickableElement getTabByLabel( 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);
@@ -406,10 +417,10 @@
throw new HtmlElementNotFoundException("Tab '"+label+"' not found using XPath '"+xPath+"'");
return tabContent;
-
}
- public ClickableElement getTabByID( String tabID ) throws HtmlElementNotFoundException {
+ public ClickableElement getTabByID( String tabID ) throws HtmlElementNotFoundException
+ {
ClickableElement element = (ClickableElement)client.getElement(tabID);
if( null == element )
throw new HtmlElementNotFoundException("Tab with id '"+tabID+"' not found, perhaps disabled?");
@@ -536,6 +547,7 @@
+
/**
* Inner class for manipulation with tab content box.
*/
@@ -564,13 +576,18 @@
* Unfortunately, headers are not H2 or similar, but DIV class="instructionalText".
* To be revised later.
*/
- public ContentTable getTableUnderHeader( String headerText ) throws ActionOutOfSyncException
+ public ContentTable getTableUnderHeader( String headerText ) throws ActionOutOfSyncException, HtmlElementNotFoundException
{
checkIfStillValid();
String xPath = "*[contains(normalize-space(), '"+headerText+"')]/following::table";
// [@id='resourceSummaryForm:dataTable'] - is this reliable?
HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
+ if( null == tableElement ){
+ throw new HtmlElementNotFoundException(
+ "Table under header '"+headerText+"' not found using XPath: "+xPath);
+ }
+
return new ContentTable(tableElement);
}
@@ -637,10 +654,59 @@
}
+ /**
+ * Tries to find a data table row with given deployable, using pagination if needed.
+ * @returns The row wrapper if found, or null.
+ */
+ public ContentTableRow findLinkRowInDataTableUsingPagination(String label)
+ throws HtmlElementNotFoundException, IOException
+ {
+
+ ContentTableRow row = null;
+
+ if( null == getTabMenu().getTabContentBox().getPagination().getPageContols() ){
+ log.debug("No page controls present - that probably means that only single page is listed.");
+ }
+ else{
+ log.debug("Number of pages: "+getTabMenu().getTabContentBox().getPagination().getPageCount());
+ }
+
+
+ int currentPage = 1;
+
+ // For all pages...
+ do {
+ HtmlTable tableElm = (HtmlTable) client.getElement("resourceSummaryForm:dataTable");
+ if( null == tableElm ){
+ throw new HtmlElementNotFoundException(
+ "Data table not found (looking for ID 'resourceSummaryForm:dataTable'");
+ }
+
+ ContentTable table = new ContentTable(tableElm);
+ row = table.findFirstRowContainingText(label);
+
+ // Did we find?
+ if( null != row )
+ break;
+ else
+ log.debug("Row with '"+label+"' not present on page "+currentPage+".");
+
+ } while (
+ // Infinite loop prevention.
+ currentPage++ < 20
+ // Pagination is not rendered if not needed.
+ && null != getTabMenu().getTabContentBox().getPagination().getPageContols()
+ // goNext() returns true if there's a next page to go.
+ && getTabMenu().getTabContentBox().getPagination().goNext()
+ );
+
+ return row;
+ }
+
+
}// inner class TabContentBox
-
/**
* Contains convenience methods for accessing content tables in EmbJopr.
*/
@@ -656,6 +722,8 @@
* Creates a data table wrapper for the given table element.
*/
public ContentTable( HtmlTable element ) {
+ if( null == element )
+ throw new IllegalArgumentException("null given as element for ContentTable.");
this.element = element;
}
@@ -708,15 +776,30 @@
// 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+"')]";
+ //String xPath = ".//tr[contains(string(), '"+text+"')]";
+ String xPath = ".//tr[.//*[contains(string(), '"+text+"')]]";
HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
if( null == elm )
throw new HtmlElementNotFoundException(xPath);
return new ContentTableRow(elm, this);
}
+ /** Same as getFirstRowContainingText(), only returns null if row is not found. */
+ public ContentTableRow findFirstRowContainingText( String text )
+ throws HtmlElementNotFoundException
+ {
+ if( 0 == element.getRowCount() )
+ return null;
+ String xPath = ".//tr[.//*[contains(string(), '"+text+"')]]";
+ HtmlTableRow elm = (HtmlTableRow) element.getFirstByXPath(xPath);
+ if( null == elm )
+ return null;
+ 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.
@@ -853,19 +936,26 @@
}
/**
- * Parses the content of the table for properties.
- * @return
+ * Parses the content of the table properties.
+ * @returns Set of properties extracted from rows
+ * whose plain text has the 'Name: Value' format.
*/
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]";
+ String xPath = ".//tr/td[span/strong | strong]";
+ //String xPath = ".//tr/td[span/strong] | .//tr/td[.//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]);
+ String cellText = cell.getTextContent();
+ String[] parts = cellText.split(":");
+ if( parts.length != 2 ){
+ log.warn("Cell text not in format 'Name: Value': "+cellText);
+ continue;
+ }
+ props.setProperty(parts[0].trim(), parts[1].trim());
}
return props;
}
@@ -906,7 +996,7 @@
public ClickableElement getButtonByLabel( String label ) throws HtmlElementNotFoundException
{
String xPath = ".//input[@type='button' and normalize-space(@value) = '"+label+"']" +
- " || .//button[normalize-space() = '"+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);
@@ -1010,14 +1100,21 @@
private static final String ID_PAGE_SIZE_SELECT = "categorySummaryForm:currentPageSize";
private static final String ID_PAGINATION_TOTAL_ITEMS = "paginationTotalItems";
- public HtmlDivision getPageContols(){
- return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
+ /** Returns the HTML element of the bar with "First | Prev | 1 2 | Next Last" controls. */
+ public HtmlDivision getPageContols() throws HtmlElementNotFoundException {
+ //return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
+ return (HtmlDivision) getTabMenu().getTabContentBox().getElement()
+ .getFirstByXPath(".//*[contains(@id, 'SummaryForm:dataTableScroller')]");
}
- public HtmlSelect getPageSizeSelect(){
- return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
+ /** Returns the HTML Select element of page size selection. */
+ public HtmlSelect getPageSizeSelect() throws HtmlElementNotFoundException {
+ //return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
+ return (HtmlSelect) getTabMenu().getTabContentBox().getElement()
+ .getFirstByXPath(".//select[contains(@id, 'SummaryForm:currentPageSize')]");
}
+ /** Returns total items count, taken from the "Total: N" element. */
public int getTotalItemsCount() throws ActionNotAvailableException
{
Element e = client.getElement(ID_PAGINATION_TOTAL_ITEMS);
@@ -1087,7 +1184,7 @@
return !getGoPage(pageNumber).getStyleAttribute().contains("-inact");
}
- public int getPageCount(){
+ public int getPageCount() throws HtmlElementNotFoundException {
String xPath = ".//td[ count(./*) = 0 and normalize-space() > 0 ]";
List<?> elements = getPageContols().getByXPath(xPath);
return elements.size();
@@ -1135,6 +1232,17 @@
public HtmlAnchor getLinkInsideForm(String formId, String linkLabel) throws HtmlElementNotFoundException
{
HtmlForm form = (HtmlForm)client.getElement(formId);
+ if( null == form ){
+ /// Dump the page
+ String normID = StringUtils.replaceChars(formId, "\\/.: ", "-----");
+ String dumpFileName = "target/formNotFound-"+ formId +".html";
+ log.debug("Dumping page to file: "+dumpFileName);
+ try { DebugUtils.writeFile(dumpFileName, client.getPageAsText()); }
+ catch (Exception ex) { log.warn("getLinkInsideForm(): "+ ex.toString()); }
+
+ throw new HtmlElementNotFoundException("Form element of given ID not found: "+formId);
+ }
+
String xPath = ".//a[contains(normalize-space(), '"+linkLabel+"')]";
HtmlAnchor link = form.getFirstByXPath(xPath);
if( null == link )
@@ -1147,11 +1255,12 @@
/** Calls Thread.sleep(ms), ignores the InterruptedException. */
@SuppressWarnings("empty-statement")
- public static void sleep( int ms ) {
+ public void sleep( int ms ) {
try {
- Thread.sleep(3000);
+ Thread.sleep(ms);
} catch (InterruptedException ex) {
- ; // We don't care, that's the purpose of this method.
+ log.warn("EJTT.sleep() interrupted.");
+ // We don't care more, that's the purpose of this method.
}
}
@@ -1224,26 +1333,16 @@
}
+ public final Deployment deployment = new Deployment();
public class Deployment {
// TODO: Shortcuts:
/*
- private void deployWAR( String warFilePath ){
-
- }
-
- private void undeployWAR( String warFileName ){
-
- }
-
- private void deployEAR( String warFilePath ){
-
- }
-
- private void undeployEAR( String warFileName ){
-
- }
+ private void deployWAR( String warFilePath ){}
+ private void undeployWAR( String warFileName ){}
+ private void deployEAR( String warFilePath ){}
+ private void undeployEAR( String warFileName ){}
// Etc. */
@@ -1253,7 +1352,7 @@
*
* @param type Type of the deployable - EAR, SAR, WAR, ...
*/
- private void deployViaEmbJopr( AppConstants.DeployableTypes type, String filePath )
+ public void deployViaEmbJopr( AppConstants.DeployableTypes type, String filePath )
throws IOException, HtmlElementNotFoundException
{
if( !(new File(filePath)).exists())
@@ -1283,7 +1382,7 @@
*
* @param type Type of the deployable - EAR, SAR, WAR, ...
*/
- private void undeployViaEmbJopr( AppConstants.DeployableTypes type, String fileName )
+ public void undeployViaEmbJopr( AppConstants.DeployableTypes type, String fileName )
throws IOException, HtmlElementNotFoundException, ActionNotAvailableException, ActionOutOfSyncException
{
@@ -1306,12 +1405,292 @@
}// undeployViaEmbJopr()
- }
+ // TODO: The following was copied from EarTest.java; remove from there.
+ /** Convenience method, setting mustBeUP to true. */
+ public boolean isDeployedAccordingToEmbJopr( DeployableTypes type, String deployableName )
+ throws HtmlElementNotFoundException, IOException, ActionNotAvailableException{
+ return isDeployedAccordingToEmbJopr( type, deployableName, true );
+ }
+ /**
+ * Returns true if EmbJopr lists a deployable of given type and name,
+ * and it's State is UP; false otherwise.
+ */
+ public boolean isDeployedAccordingToEmbJopr(
+ DeployableTypes type, String deployableName, boolean mustBeUP )
+ throws HtmlElementNotFoundException, IOException, ActionNotAvailableException
+ {
+ // Refresh / go to the appropriate page.
+ getNavTree().getNodeByLabel( type.getNavTreeLabel() ).click();
+ // Pagination
+ //int totalItemsCount = getTabMenu().getTabContentBox().getPagination().getTotalItemsCount();
+
+ /*
+ ContentTableRow appRow = null;
+
+ // Search trough all pages.
+ int currentPage = 1;
+ do {
+ appRow = getDefaultContentTable().findFirstRowContainingLink(deployableName);
+ if( null != appRow ){
+ break;
+ }else{
+ log.debug("Row with "+deployableName+" not present on page "+currentPage+".");
+ }
+ } while( currentPage++ < 20 && getTabMenu().getTabContentBox().getPagination().goNext() );
+
+ */
+
+ // Find the row containing the deployable. Use the pagination if needed.
+ ContentTableRow appRow = getTabMenu().getTabContentBox().
+ findLinkRowInDataTableUsingPagination(deployableName);
+
+ if( null == appRow ){
+ log.debug("Row with '"+deployableName+"' not found.");
+ return false;
+ }
+
+ if( !mustBeUP ){
+ // Not needed to be UP; we found it, thus return true.
+ return true;
+ }
+
+ String statusText = appRow.getCellTextByColumnName("Status");
+ if( "UP".equals(statusText) ){
+ return true;
+ }else{
+ log.debug("Row with "+deployableName+" has Status == '"+statusText+"' != UP.");
+ return false;
+ }
+
+ }// isDeployedAccordingToEmbJopr()
+
+
+
+ /**
+ * Waits for the deployable to be in the UP State.
+ *
+ * @param type Type of deployable - EAR, WAR, SAR, ...
+ * @param name Name of the deployable, like 'hello.war'.
+ */
+ public void waitActivelyForDeployment(
+ final DeployableTypes type, final String name,
+ int intervalMS, int retries
+ )
+ throws EmbJoprTestException, IOException
+ {
+ waitActivelyForDeployment(type, name, intervalMS, retries, null);
+ }
+
+ /**
+ * Waits for the deployable to be in the UP State.
+ *
+ * @param type Type of deployable - EAR, WAR, SAR, ...
+ * @param name Name of the deployable, like 'hello.war'.
+ */
+ public void waitActivelyForDeployment(
+ final DeployableTypes type, final String name,
+ int intervalMS, int retries,
+ EmbjoprTestCase test // used for page dump
+ )
+ throws EmbJoprTestException, IOException
+ {
+ try {
+ //final EmbJoprTestToolkit selfEjtt = getEjtt();
+
+ String conditionDesc = type.name()+" "+name+" appears in embjopr as deployed";
+ ActiveConditionChecker checker =
+ new ActiveConditionChecker(new DescribedCondition(conditionDesc) {
+
+ int callsMade = 0;
+
+ public boolean isTrue() throws HtmlElementNotFoundException, IOException, ActionNotAvailableException {
+ // Refresh the page if this is not the first call.
+ if (callsMade++ > 0) {
+ selfEjtt.refreshPage();
+ }
+ // If found, return true.
+ return isDeployedAccordingToEmbJopr(type, name);
+ // If found, return true.
+ }
+ }).throwOnTimeout();
+
+ if( null != test )
+ checker.dumpPageOnTimeout(test);
+
+ boolean deployedSuccessfuly = checker.waitWithTimeout( intervalMS, retries );
+ }
+ catch( EmbJoprTestException ex ){ throw ex; }
+ catch( IOException ex ){ throw ex; }
+ // Wrap all exceptions to EmbJoprTestException.
+ catch( Exception ex ){
+ throw new EmbJoprTestException("Exception thrown while actively waiting for condition.", ex);
+ }
+ }
+
+
+
+ /**
+ * Returns true if there's a file of the given name in server's deploy dir;
+ * false otherwise.
+ */
+ private boolean isDeployedAccordingToFileSystem( DeployableTypes type, String name )
+ {
+ String deployPath = getDeployDir();
+ String fileName = deployPath+"/"+name;
+ return (new File(fileName)).exists();
+ }
+
+ private void undeployViaFileSystem( String name ) throws EmbJoprTestException{
+ String deployPath = getDeployDir();
+ String fileName = deployPath+"/"+name;
+ File fileToDelete = new File(fileName);
+
+ if( !fileToDelete.exists() )
+ throw new EmbJoprTestException("Deployable doesn't exist: "+fileName);
+
+ if(fileToDelete.isFile()){
+ if( !fileToDelete.delete() ){
+ throw new EmbJoprTestException("Unable to delete: "+fileName);
+ }
+ }else if(fileToDelete.isDirectory()){
+ deleteDirectory(fileToDelete);
+ }
+
+ }// isDeployedAccordingToFileSystem()
+
+
+
+ /**
+ * Unzips given archive from testdata dir to server's deploy/ dir.
+ * @param relativeArchivePath Path of the archive relative to testdata dir.
+ * @param relativeDestDir Path of the destination dir relative to deploy dir.
+ */
+ public void unzipToDeployDir( String relativeArchivePath, String relativeDestDir )
+ throws FileNotFoundException, IOException
+ {
+
+ String destDir = getTestDataDir()+"/"+relativeDestDir;
+ String archivePath = getTestDataDir()+"/"+relativeArchivePath;
+
+ log.info("Unzipping '"+archivePath+"' to '"+destDir+"'.");
+
+ unzipArchive( archivePath, destDir );
+ }
+
+
+
+ /**
+ * Unzips archive from the given path to the given destination dir.
+ */
+ public void unzipArchive(String archivePath, String destDir)
+ throws FileNotFoundException, IOException
+ {
+
+ FileInputStream fis = new FileInputStream( archivePath );
+ ZipInputStream zin = new ZipInputStream(new BufferedInputStream(fis));
+
+ ZipEntry entry;
+ while( null != (entry = zin.getNextEntry()) ){
+
+ if(entry.isDirectory()) {
+ // Assume directories are stored parents first then children.
+ log.info("Extracting directory: " + entry.getName());
+ // This is not robust, just for demonstration purposes.
+ (new File(destDir +"/"+ entry.getName())).mkdir();
+ continue;
+ }
+
+ log.info("Extracting file: " + entry.getName());
+
+ final int BUFFER = 2048;
+ FileOutputStream fos = new FileOutputStream( destDir +"/"+ entry.getName());
+ BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
+
+ int count;
+ byte[] data = new byte[BUFFER];
+ while ((count = zin.read(data, 0, BUFFER)) != -1) {
+ dest.write(data, 0, count);
+ }
+ dest.flush();
+ dest.close();
+ zin.closeEntry();
+
+ }
+
+ zin.close();
+
+ }
+
+
+
+
+ public void deleteFromDeployDir( String deployableName ) throws IOException, EmbJoprTestException{
+
+ String deployDir = getDeployDir();
+
+ File dirToDelete = new File( deployDir, deployableName);
+
+ // Just not to delete something accidentally...
+ // For tests:
+ // /.../embjopr-svn-trunk/jsfunit/target/jboss5x/deploy/unpacked-web1.war.zip
+ /*if( ! dirToDelete.getCanonicalPath().contains("/server/") )
+ throw new EmbJoprTestException( "Path to deployable doesn't contain '/server/': "
+ +dirToDelete.getCanonicalPath() );
+ /**/
+
+ // Check if not outside deploy dir.
+ if( !dirToDelete.getCanonicalPath().startsWith( deployDir ) )
+ throw new IllegalArgumentException(
+ " The resulting path is outside deploy dir: "+dirToDelete.getCanonicalPath());
+
+ log.info("Deleting '"+dirToDelete.getPath()+"'...");
+ deleteDirectory( dirToDelete );
+ }
+
+
+
+ public /*static*/ void deleteDirectory(File path) throws EmbJoprTestException
+ {
+ List<String> undeletableFiles = new ArrayList();
+ deleteDirectory(path, undeletableFiles);
+ if( !undeletableFiles.isEmpty() ){
+ throw new EmbJoprTestException("Couldn't delete following files: \n "+
+ StringUtils.join(undeletableFiles, "\n ") + "\n");
+ }
+ }
+
+ public /*static*/ void deleteDirectory(File path, List<String> undeletableFiles)
+ {
+ if( path.exists() ) {
+ File[] files = path.listFiles();
+ for(int i=0; i<files.length; i++) {
+ if(files[i].isDirectory()) {
+ deleteDirectory(files[i], undeletableFiles );
+ }
+ else {
+ if( !files[i].delete() ){
+ undeletableFiles.add(files[i].getAbsolutePath());
+ }
+ }
+ }
+ }
+ if( ! path.delete() )
+ undeletableFiles.add( path.getAbsolutePath() );
+ }
+
+
+ }// class Deployment
+
+
+
+
+
+
// TODO
protected class JMXDeploymentInfo {
15 years, 10 months
EMBJOPR SVN: r244 - in trunk/jsfunit/testdata: war and 1 other directory.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-19 23:11:17 -0400 (Thu, 19 Mar 2009)
New Revision: 244
Added:
trunk/jsfunit/testdata/unpacked-web1.war/
trunk/jsfunit/testdata/war/malformed-web-xml.war
trunk/jsfunit/testdata/war/unpacked-web1.war.zip
trunk/jsfunit/testdata/war/war-conf-basic.properties
Log:
Data for WAR tests.
Added: trunk/jsfunit/testdata/war/malformed-web-xml.war
===================================================================
(Binary files differ)
Property changes on: trunk/jsfunit/testdata/war/malformed-web-xml.war
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/jsfunit/testdata/war/unpacked-web1.war.zip
===================================================================
(Binary files differ)
Property changes on: trunk/jsfunit/testdata/war/unpacked-web1.war.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/jsfunit/testdata/war/war-conf-basic.properties
===================================================================
--- trunk/jsfunit/testdata/war/war-conf-basic.properties (rev 0)
+++ trunk/jsfunit/testdata/war/war-conf-basic.properties 2009-03-20 03:11:17 UTC (rev 244)
@@ -0,0 +1,14 @@
+
+blackList = false
+cache = false
+domain = my.domain
+excluded = my.excluded
+excludedExport = my.excludedExport
+# ALL, NON_EMPTY
+exportAll = ALL
+importAll = false
+included = my.included
+name = my.name
+parentDomain = my.parentDomain
+parentFirst = false
+version = 10.9.8.7
\ No newline at end of file
15 years, 10 months
EMBJOPR SVN: r243 - trunk/core/src/main/java/org/jboss/on/embedded/ui.
by embjopr-commits@lists.jboss.org
Author: ips
Date: 2009-03-19 22:44:02 -0400 (Thu, 19 Mar 2009)
New Revision: 243
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
Log:
turn down some noisy logging; remove redundant imports
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2009-03-18 16:26:04 UTC (rev 242)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/NavigationAction.java 2009-03-20 02:44:02 UTC (rev 243)
@@ -30,6 +30,19 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.measurement.Availability;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceCreationDataType;
+import org.rhq.core.domain.resource.ResourceType;
+import org.richfaces.component.UITree;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
import org.jboss.on.embedded.Constants;
import org.jboss.on.embedded.manager.ResourceManager;
import org.jboss.on.embedded.manager.ResourceManagerFactory;
@@ -39,22 +52,6 @@
import org.jboss.on.embedded.ui.nav.PlatformResourceTreeNode;
import org.jboss.on.embedded.ui.nav.ResourceTypeTreeNode;
import org.jboss.on.embedded.ui.nav.TreeNodeWithResource;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.core.Events;
-import org.jboss.seam.annotations.Factory;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Out;
-import org.jboss.seam.annotations.Scope;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.measurement.Availability;
-import org.rhq.core.domain.measurement.AvailabilityType;
-import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceCreationDataType;
-import org.rhq.core.domain.resource.ResourceType;
-import org.richfaces.component.UITree;
-import org.richfaces.component.html.HtmlTree;
/**
* NavigationAction creates the navigation objects.
@@ -63,6 +60,7 @@
* @author Charles Crouch
* @author Ian Springer
*/
+// TODO (ips): Remove obsolete commented-out code.
// TODO: Go through this class and try to ensure the minimum amount of things are public.
// Most actions should be dealing with CommonActionUtil for getting hold of resources etc.
@Name("navigationAction")
@@ -387,7 +385,8 @@
// TODO could consider renaming this getCurrentNavigationNode()
public JONTreeNode getSelectedNode()
{
- log.debug("Finding node for path [" + getCurrentPath() + "]...");
+ if (log.isTraceEnabled())
+ log.trace("Finding node for path [" + getCurrentPath() + "]...");
JONTreeNode selectedNode = getRootNode().findNode(getCurrentPath());
ResourceManager resourceManager = ResourceManagerFactory.resourceManager();
if (selectedNode == null) {
15 years, 10 months
EMBJOPR SVN: r242 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-18 12:26:04 -0400 (Wed, 18 Mar 2009)
New Revision: 242
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
Log:
getNavTreeArrow(): Added waitUntilNodeLoadedByAjax() for nodes being loaded by AJAX after expanding parent node.
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-18 14:55:19 UTC (rev 241)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-18 16:26:04 UTC (rev 242)
@@ -186,7 +186,11 @@
*/
public ClickableElement getNavTreeArrow(String resourceName) throws EmbJoprTestException {
- ejtt.navTree.waitUntilReady(100, 15); // Tree.Item can be still loading.
+ // Tree.Item JS object can be still loading.
+ ejtt.navTree.waitUntilReady(100, 15);
+ // After expanding some node, it's children are loaded using AJAX.
+ // Here, we wait for the node with given label to appear in the nav tree.
+ ejtt.navTree.waitUntilNodeLoadedByAjax(resourceName, 200, 10);
HtmlAnchor link = getNavTreeLink(resourceName);
String id = link.getIdAttribute();
15 years, 10 months
EMBJOPR SVN: r241 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5.
by embjopr-commits@lists.jboss.org
Author: fjuma
Date: 2009-03-18 10:55:19 -0400 (Wed, 18 Mar 2009)
New Revision: 241
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
Log:
Made a minor change to configureResource() in ResourceTestBase.java.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-03-18 14:30:15 UTC (rev 240)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-03-18 14:55:19 UTC (rev 241)
@@ -118,8 +118,7 @@
checkClientAndServerMessages(expectedMessage, expectedMessage, false);
// Verify that the properties were set correctly
- propertiesMap.putAll(propertiesMapChanges);
- checkComponentProperties(propertiesMap, resourceName, componentType);
+ checkComponentProperties(propertiesMapChanges, resourceName, componentType);
}
/**
15 years, 10 months
EMBJOPR SVN: r240 - trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource.
by embjopr-commits@lists.jboss.org
Author: charles.crouch(a)jboss.com
Date: 2009-03-18 10:30:15 -0400 (Wed, 18 Mar 2009)
New Revision: 240
Modified:
trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java
Log:
EMBJOPR-89 don't end the conversation until after the redirect
Modified: trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java
===================================================================
--- trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java 2009-03-18 13:38:25 UTC (rev 239)
+++ trunk/core/src/main/java/org/jboss/on/embedded/ui/configuration/resource/ResourceConfigurationUIBean.java 2009-03-18 14:30:15 UTC (rev 240)
@@ -36,7 +36,6 @@
import org.rhq.core.clientapi.server.configuration.ConfigurationUpdateResponse;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
-import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
@@ -176,7 +175,7 @@
}
if (result == "success") {
- Conversation.instance().end(true);
+ Conversation.instance().end(false);
}
return result;
}
15 years, 10 months
EMBJOPR SVN: r239 - 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-18 09:38:25 -0400 (Wed, 18 Mar 2009)
New Revision: 239
Added:
trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml
trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml
Modified:
trunk/jsfunit/pom.xml
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
Log:
Adding metrics tests for topics.
Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml 2009-03-17 22:18:25 UTC (rev 238)
+++ trunk/jsfunit/pom.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -120,6 +120,18 @@
<version>2.1.0.CR3</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>jboss.messaging</groupId>
+ <artifactId>jboss-messaging-client</artifactId>
+ <version>1.4.3.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.javaee</groupId>
+ <artifactId>jboss-javaee</artifactId>
+ <version>5.0.1.GA</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java 2009-03-17 22:18:25 UTC (rev 238)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JMSTest.java 2009-03-18 13:38:25 UTC (rev 239)
@@ -27,8 +27,10 @@
import junit.framework.Test;
import java.util.Map;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Iterator;
import java.util.Set;
+import java.util.ArrayList;
import org.jboss.jopr.jsfunit.*;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -39,6 +41,20 @@
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.managed.api.ComponentType;
import java.io.File;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSubscriber;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.ConnectionFactory;
+import javax.jms.TextMessage;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
/**
* This class contains tests for managing JMS topics and queues
@@ -80,7 +96,32 @@
private static final ComponentType TOPIC_COMPONENT_TYPE = KnownComponentTypes.JMSDestination.Topic.getType();
private static final String SERVICE_FILE_ROOT_ELEMENT = "server";
private static final String SERVICE_FILE_CHILD_ELEMENT = "mbean";
-
+ private static final String TOPIC_FACTORY = "/ConnectionFactory";
+ private static final String QUEUE_FACTORY = "/ConnectionFactory";
+ private static final String CLIENT_ID = "EmbjoprTest";
+
+ // Topic Metrics
+ private static final String ALL_MSG_COUNT = "All Message Count";
+ private static final String ALL_SUB_COUNT = "All Subscriptions Count";
+ private static final String DURABLE_MSG_COUNT = "Durable Message Count";
+ private static final String DURABLE_SUB_COUNT = "Durable Subscriptions Count";
+ private static final String NON_DURABLE_MSG_COUNT = "Non Durable Message Count";
+ private static final String NON_DURABLE_SUB_COUNT = "Non Durable Subscriptions Count";
+
+ // Queue Metrics
+ private static final String CONSUMER_COUNT = "Consumer Count";
+ private static final String DELIVERING_COUNT = "Delivering Count";
+ private static final String MSG_COUNT = "Message Count";
+ private static final String SCHEDULED_MSG_COUNT = "Scheduled Message Count";
+ private static final String COUNT = "Count";
+ private static final String COUNT_DELTA = "Count Delta";
+ private static final String DEPTH = "Depth";
+ private static final String DEPTH_DELTA = "Depth Delta";
+ private static final String TIME_LAST_UPDATE = "Time Last Update";
+
+ private TopicConnection topicConnection = null;
+ private QueueConnection queueConnection = null;
+
/**
* Create a new topic or queue using the given destination type and properties.
*/
@@ -109,7 +150,7 @@
*/
protected Map<String, MetaValue> createQueue(String queueName) throws IOException, EmbJoprTestException {
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(queueName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.FALSE));
propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new Integer(1500)));
@@ -129,7 +170,7 @@
* values.
*/
protected Map<String, MetaValue> createTopic(String topicName) throws IOException, EmbJoprTestException {
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(topicName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(70000)));
@@ -162,6 +203,123 @@
return super.getSpecificComponentProperties(componentName, type, specificProperties);
}
+ /**
+ * Create a topic session and return it.
+ */
+ protected TopicSession createTopicSession() throws Exception {
+ InitialContext context = new InitialContext();
+ Object tmp = context.lookup(TOPIC_FACTORY);
+
+ TopicConnectionFactory tcf = (TopicConnectionFactory)tmp;
+ topicConnection = tcf.createTopicConnection();
+ topicConnection.setClientID(CLIENT_ID);
+
+ TopicSession topicSession = topicConnection.createTopicSession(Boolean.FALSE,
+ TopicSession.AUTO_ACKNOWLEDGE);
+ topicConnection.start();
+
+ return topicSession;
+ }
+
+ /**
+ * Create a non-durable topic subscriber and return it.
+ */
+ protected TopicSubscriber createNonDurableTopicSubscriber(TopicSession session,
+ Topic topic) throws JMSException {
+ return session.createSubscriber(topic);
+ }
+
+ /**
+ * Create a durable topic subscriber and return it.
+ */
+ protected TopicSubscriber createDurableTopicSubscriber(TopicSession session,
+ Topic topic,
+ String subscriptionName) throws JMSException {
+ return session.createDurableSubscriber(topic, subscriptionName);
+ }
+
+ /**
+ * Create a TopicPublisher for the given topic and
+ * publish the given number of messages.
+ */
+ protected void publishMessages(TopicSession session,
+ Topic topic,
+ int numMessages) throws JMSException {
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ for(int i = 0; i < numMessages; i++) {
+ TextMessage message = session.createTextMessage("Message " + i);
+ publisher.publish(message);
+ }
+
+ publisher.close();
+ }
+
+ /**
+ * Lookup and return the topic given by jndiName.
+ */
+ protected Topic getTopic(String jndiName) throws NamingException {
+ InitialContext context = new InitialContext();
+ Topic topic = (Topic)context.lookup(jndiName);
+
+ return topic;
+ }
+
+ /**
+ * Close all connections.
+ */
+ protected void disconnect() throws JMSException {
+
+ if(topicConnection != null) {
+ topicConnection.close();
+ topicConnection = null;
+ }
+
+ if(queueConnection != null) {
+ queueConnection.close();
+ queueConnection = null;
+ }
+ }
+
+ /**
+ * Get the list of metrics that appear on the summary
+ * page for topics.
+ */
+ protected ArrayList<String> getTopicSummaryMetrics() {
+ ArrayList<String> topicSummaryMetrics = new ArrayList<String>();
+
+ // The metrics we need to check on the summary tab
+ // TODO: add the summary page metrics that need to be checked -
+ // currently no summary metrics are displayed on the page (EMBJOPR-90)
+
+ return topicSummaryMetrics;
+ }
+
+ /**
+ * Get the list of metrics that appear on the summary
+ * page for queues.
+ */
+ protected ArrayList<String> getQueueSummaryMetrics() {
+ ArrayList<String> queueSummaryMetrics = new ArrayList<String>();
+
+ // The metrics we need to check on the summary tab
+ // TODO: add the summary page metrics that need to be checked -
+ // currently no summary metrics are displayed on the page (EMBJOPR-90)
+
+ return queueSummaryMetrics;
+ }
+
+ /**
+ * Make sure we close any topic or queue
+ * connections.
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ disconnect();
+ }
+
+
/*
* CREATION TESTS
*/
@@ -208,7 +366,7 @@
ComponentType componentType) throws Exception {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new Integer(2500)));
@@ -259,7 +417,7 @@
private void createDestinationMissingRequiredValue(DestinationType destinationType,
String destinationTemplate) throws IOException, EmbJoprTestException {
// Leave the JNDI name unset
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("fullSize", SimpleValueSupport.wrap(new Integer(80000)));
@@ -303,7 +461,7 @@
String destinationTemplate,
String jndiName) throws IOException, EmbJoprTestException {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("downCacheSize", SimpleValueSupport.wrap(new Integer(2500)));
@@ -351,7 +509,7 @@
String destinationTemplate,
String jndiName) throws IOException, EmbJoprTestException {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
propertiesMap.put("clustered", SimpleValueSupport.wrap(Boolean.TRUE));
propertiesMap.put("messageCounterHistoryDayLimit", SimpleValueSupport.wrap(new Integer(0)));
@@ -397,7 +555,7 @@
String destinationTemplate,
String jndiName) throws IOException, EmbJoprTestException {
// The properties we want to configure
- Map<String, MetaValue> propertiesMap = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
createDestination(destinationType, destinationTemplate, propertiesMap);
@@ -509,7 +667,7 @@
// The properties we are going to change
// (Before: messageCounterHistoryDayLimit=-1, redeliveryDelay=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String, MetaValue>();
propertiesMapChanges.put("messageCounterHistoryDayLimit", SimpleValueSupport.wrap(new Integer(0)));
propertiesMapChanges.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(40000)));
@@ -534,7 +692,7 @@
// The properties we are going to change
// (Before: maxDeliveryAttempts=-1, redeliveryDelay=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String, MetaValue>();
propertiesMapChanges.put("maxDeliveryAttempts", SimpleValueSupport.wrap(new Integer(15)));
propertiesMapChanges.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(40000)));
@@ -561,7 +719,7 @@
// The properties we are going to change
// (Before: messageCounterHistoryDayLimit=5, redeliveryDelay=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String, MetaValue>();
propertiesMapChanges.put("messageCounterHistoryDayLimit", SimpleValueSupport.wrap(new Integer(0)));
propertiesMapChanges.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(40000)));
@@ -586,7 +744,7 @@
// The properties we are going to change
// (Before: redeliveryDelay=60000, maxDeliveryAttempts=-1 )
- Map<String, MetaValue> propertiesMapChanges = new HashMap<String, MetaValue>();
+ Map<String, MetaValue> propertiesMapChanges = new LinkedHashMap<String, MetaValue>();
propertiesMapChanges.put("redeliveryDelay", SimpleValueSupport.wrap(new Long(40000)));
propertiesMapChanges.put("maxDeliveryAttempts", SimpleValueSupport.wrap(new Integer(15)));
@@ -732,4 +890,296 @@
// Clean up
deleteDestination(destinationType, jndiName);
}
+
+ /*
+ * METRICS TESTS
+ */
+
+ /**
+ * Test Name: testTopicMetricsAfterCreation
+ * Assertion: Verify that topic metrics are correct after topic
+ * creation.
+ */
+ public void testTopicMetricsAfterCreation() throws Exception {
+ String jndiName = "MetricsAfterTopicCreation";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "0.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "0.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneNonDurableSubscription
+ * Assertion: Verify that topic metrics are correct after creating
+ * a non-durable subscriber for the topic.
+ */
+ public void testTopicMetricsAfterOneNonDurableSubscription() throws Exception {
+ String jndiName = "MetricsAfterOneNonDurableTopicSubscriber";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.FALSE);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneNonDurableSubscriptionUsingExistingServiceFile
+ * Assertion: Verify that topic metrics are correct after creating
+ * a non-durable subscriber for the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterOneNonDurableSubscriptionUsingExistingServiceFile() throws Exception {
+ String jndiName = "MetricsOneNonDurableTopicSubscriberExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.FALSE);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneDurableSubscription
+ * Assertion: Verify that topic metrics are correct after creating
+ * a durable subscriber for the topic.
+ */
+ public void testTopicMetricsAfterOneDurableSubscription() throws Exception {
+ String jndiName = "MetricsAfterOneDurableTopicSubscriber";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.TRUE);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneDurableSubscriptionUsingExistingServiceFile
+ * Assertion: Verify that topic metrics are correct after creating
+ * a durable subscriber for the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterOneDurableSubscriptionUsingExistingServiceFile() throws Exception {
+ String jndiName = "MetricsOneDurableTopicSubscriberExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterOneSubscription(jndiName, Boolean.TRUE);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterOne*Subscription* tests.
+ */
+ private void checkTopicMetricsAfterOneSubscription(String jndiName,
+ Boolean isDurable) throws Exception {
+
+ // Create a subscriber
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+
+ if(isDurable) {
+ createDurableTopicSubscriber(session, topic, jndiName + "Subscriber1");
+ } else {
+ createNonDurableTopicSubscriber(session, topic);
+ }
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "0.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "1.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+
+ if(isDurable) {
+ expectedMetrics.put(DURABLE_SUB_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "0.0");
+ } else {
+ expectedMetrics.put(DURABLE_SUB_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "1.0");
+ }
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleSubscriptions()
+ * Assertion: Verify that topic metrics are correct after multiple subscribers
+ * for the topic are created.
+ */
+ public void testTopicMetricsAfterMultipleSubscriptions() throws Exception {
+ String jndiName = "MetricsAfterMultipleTopicSubscribers";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterMultipleSubscriptions(jndiName);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleSubscriptionsUsingExistingServiceFile()
+ * Assertion: Verify that topic metrics are correct after multiple subscribers
+ * for the topic are created. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterMultipleSubscriptionsUsingExistingServiceFile() throws Exception {
+ String jndiName = "MetricsMultipleTopicSubscribersExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterMultipleSubscriptions(jndiName);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterMultipleSubscriptions* tests.
+ */
+ private void checkTopicMetricsAfterMultipleSubscriptions(String jndiName) throws Exception {
+
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+
+ // Create multiple subscriptions (2 durable ones, 2 non-durable ones)
+ for(int i = 0; i < 2; i++) {
+ createDurableTopicSubscriber(session, topic, jndiName + "Subscriber" + i);
+ createNonDurableTopicSubscriber(session, topic);
+ }
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "0.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "4.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "2.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "2.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneMessage()
+ * Assertion: Verify that topic metrics are correct after sending
+ * one message to the topic.
+ */
+ public void testTopicMetricsAfterOneMessage() throws Exception {
+ String jndiName = "TopicMetricsAfterOneMessage";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterOneMessage(jndiName);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterOneMessageUsingExistingServiceFile()
+ * Assertion: Verify that topic metrics are correct after sending
+ * one message to the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterOneMessageUsingExistingServiceFile() throws Exception {
+ String jndiName = "TopicMetricsOneMessageExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterOneMessage(jndiName);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterOneMessage* tests.
+ */
+ private void checkTopicMetricsAfterOneMessage(String jndiName) throws Exception {
+
+ // Create a subscriber for the topic and then publish
+ // 1 message
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+ createDurableTopicSubscriber(session, topic, jndiName + "Subscriber1");
+
+ publishMessages(session, topic, 1);
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "1.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "1.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "0.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "0.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+
+
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleMessages()
+ * Assertion: Verify that topic metrics are correct after sending
+ * multiple message to the topic.
+ */
+ public void testTopicMetricsAfterMultipleMessages() throws Exception {
+ String jndiName = "TopicMetricsAfterMultipleMessages";
+
+ // Create the topic first
+ createTopic(jndiName);
+
+ checkTopicMetricsAfterMultipleMessages(jndiName);
+ }
+
+ /**
+ * Test Name: testTopicMetricsAfterMultipleMessagesUsingExistingServiceFile()
+ * Assertion: Verify that topic metrics are correct after sending
+ * multiple message to the topic. Use a topic that already exists.
+ */
+ public void testTopicMetricsAfterMultipleMessagesUsingExistingServiceFile() throws Exception {
+ String jndiName = "TopicMetricsMultipleMessagesExistingTopic";
+
+ expandNavTreeArrow(JMS_NAV_LABEL);
+ checkTopicMetricsAfterMultipleMessages(jndiName);
+ }
+
+ /**
+ * Common code for the testTopicMetricsAfterMultipleMessages* tests.
+ */
+ private void checkTopicMetricsAfterMultipleMessages(String jndiName) throws Exception {
+
+ TopicSession session = createTopicSession();
+ Topic topic = getTopic(jndiName);
+
+ // Create 1 durable subscriber, 1 non-durable subscriber
+ // and then publish 3 messages
+ createDurableTopicSubscriber(session, topic, jndiName + "Subscriber");
+ createNonDurableTopicSubscriber(session, topic);
+
+ publishMessages(session, topic, 3);
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+ expectedMetrics.put(ALL_MSG_COUNT, "6.0");
+ expectedMetrics.put(ALL_SUB_COUNT, "2.0");
+ expectedMetrics.put(DURABLE_MSG_COUNT, "3.0");
+ expectedMetrics.put(NON_DURABLE_MSG_COUNT, "3.0");
+ expectedMetrics.put(DURABLE_SUB_COUNT, "1.0");
+ expectedMetrics.put(NON_DURABLE_SUB_COUNT, "1.0");
+
+ checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+ DestinationType.TOPIC);
+ }
+
+ /**
+ * Common code for the metrics tests.
+ */
+ private void checkDestinationMetrics(String jndiName,
+ Map<String, String> expectedMetrics,
+ ArrayList<String> summaryMetrics,
+ DestinationType destinationType) throws Exception {
+
+ checkResourceMetrics(JMS_NAV_LABEL, destinationType.getNavLabel(),
+ jndiName, expectedMetrics, summaryMetrics);
+
+ // Clean up
+ disconnect();
+ deleteDestination(destinationType, jndiName);
+ }
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-03-17 22:18:25 UTC (rev 238)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java 2009-03-18 13:38:25 UTC (rev 239)
@@ -34,6 +34,8 @@
import java.io.File;
import org.jboss.managed.api.ComponentType;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import java.util.ArrayList;
+import java.util.Iterator;
/**
* This class contains basic methods for creating, configuring, and deleting
@@ -48,11 +50,11 @@
private final String MAX_ITEMS_PER_PAGE="20";
// Error messages
- public static final String INVALID_VALUE_MESSAGE="An invalid value was specified for one or more properties";
- public static final String MISSING_VALUE_MESSAGE="Value is required";
- public static final String OUT_OF_RANGE_MESSAGE="Specified attribute is not between the expected values";
- public static final String INVALID_INTEGER_MESSAGE="Value is not a valid integer";
-
+ public static final String INVALID_VALUE_MESSAGE = "An invalid value was specified for one or more properties";
+ public static final String MISSING_VALUE_MESSAGE = "Value is required";
+ public static final String OUT_OF_RANGE_MESSAGE = "Specified attribute is not between the expected values";
+ public static final String INVALID_INTEGER_MESSAGE = "Value is not a valid integer";
+
// Success messages
public static final String ADD_MESSAGE = "Successfully added new ";
public static final String DELETE_MESSAGE = "Successfully deleted ";
@@ -208,15 +210,67 @@
protected void navigateToPage(String resourceCategory,
String resourceSubCategory,
String resourceName,
- String tabName) throws IOException, EmbJoprTestException {
+ String tabName) throws Exception {
//refreshTreeNode(resourceCategory);
- ClickableElement datasourceTypeArrow = getNavTreeArrow(resourceSubCategory);
- datasourceTypeArrow.click();
+ ClickableElement resourceTypeArrow = getNavTreeArrow(resourceSubCategory);
+ resourceTypeArrow.click();
- HtmlAnchor datasource = getNavTreeLink(resourceName);
- datasource.click();
+ HtmlAnchor resource = getNavTreeLink(resourceName);
+ resource.click();
HtmlAnchor tabLink = (HtmlAnchor)client.getElement(tabName);
tabLink.click();
}
+
+ /**
+ * Make sure that the metrics corresponding to the given resource
+ * are correct.
+ *
+ * @param metricsMap maps metric names to the expected metric values.
+ *
+ * Assumes the resource tree node (eg. "JMS Destinations", "Datasources",
+ * etc.) is already expanded.
+ */
+ protected void checkResourceMetrics(String resourceCategory,
+ String resourceSubCategory,
+ String resourceName,
+ Map<String, String> metricsMap,
+ ArrayList<String> summaryMetrics) throws Exception {
+
+ // Navigate to the metrics page for the resource
+ navigateToPage(resourceCategory, resourceSubCategory,
+ resourceName, METRICS_TAB);
+
+ checkMetricValues(metricsMap.keySet().iterator(), metricsMap,
+ "Incorrect metric value for ");
+
+ if(summaryMetrics.size() > 0) {
+
+ // Check values under the "Summary" tab
+ HtmlAnchor summaryLink = (HtmlAnchor)client.getElement(SUMMARY_TAB);
+ summaryLink.click();
+
+ checkMetricValues(summaryMetrics.iterator(), metricsMap,
+ "Incorrect summary metric value for ");
+ }
+ }
+
+ /**
+ * Compare the actual metric values for this resource to
+ * the expected values.
+ *
+ * @param i is an Iterator over the metrics we want to check
+ * @param metricsMap maps metric names to their expected values
+ */
+ protected void checkMetricValues(Iterator i, Map<String, String> metricsMap, String errorMessage) {
+
+ while(i.hasNext()) {
+ String metricName = (String)i.next();
+
+ String expected = metricsMap.get(metricName);
+ String actual = getMetricValueFromTable(metricName, "dataTable");
+ actual = normalizeIfDoubleExpected(expected, actual);
+ assertEquals(errorMessage + " '"+ metricName + "'", expected, actual);
+ }
+ }
}
Added: trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/MetricsMultipleTopicSubscribersExistingTopic-service.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=MetricsMultipleTopicSubscribersExistingTopic" code="org.jboss.jms.server.destination.TopicService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute name="JNDIName">MetricsMultipleTopicSubscribersExistingTopic</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added: trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/MetricsOneDurableTopicSubscriberExistingTopic-service.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=MetricsOneDurableTopicSubscriberExistingTopic" code="org.jboss.jms.server.destination.TopicService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute name="JNDIName">MetricsOneDurableTopicSubscriberExistingTopic</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added: trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/MetricsOneNonDurableTopicSubscriberExistingTopic-service.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=MetricsOneNonDurableTopicSubscriberExistingTopic" code="org.jboss.jms.server.destination.TopicService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute name="JNDIName">MetricsOneNonDurableTopicSubscriberExistingTopic</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added: trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/TopicMetricsMultipleMessagesExistingTopic-service.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=TopicMetricsMultipleMessagesExistingTopic" code="org.jboss.jms.server.destination.TopicService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute name="JNDIName">TopicMetricsMultipleMessagesExistingTopic</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
Added: trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml (rev 0)
+++ trunk/jsfunit/testdata/destinations/TopicMetricsOneMessageExistingTopic-service.xml 2009-03-18 13:38:25 UTC (rev 239)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+ <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=TopicMetricsOneMessageExistingTopic" code="org.jboss.jms.server.destination.TopicService">
+ <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+ <attribute name="JNDIName">TopicMetricsOneMessageExistingTopic</attribute>
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+</server>
15 years, 10 months
EMBJOPR SVN: r238 - 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-17 18:18:25 -0400 (Tue, 17 Mar 2009)
New Revision: 238
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
War test updated, EJTT: Deployment part created with deploy/undeploy methods.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-03-17 22:18:25 UTC (rev 238)
@@ -28,19 +28,25 @@
public static final String SYSPROP_TESTDATA_DIR = "jsfunit.testdata";
+
+
/**
* Information about deployable types -
- * navigation tree labels, archive extensions, and XML descriptor suffixes.
+ * navigation tree labels, archive extensions,
+ * XML descriptor suffixes, and MIME type.
*/
public enum DeployableTypes {
- EAR(AppConstants.NAV_EAR, ".ear", null),
- WAR(AppConstants.NAV_WAR, ".war", null),
- EJB(AppConstants.NAV_EJB, ".jar", null),
- SAR(AppConstants.NAV_SAR, ".sar", "-service.xml"),
- RAR(AppConstants.NAV_RAR, ".rar", null),
- MC_BEAN(AppConstants.NAV_MC, "", null);
+ // Mandatory: first, fourth
+ EAR(AppConstants.NAV_EAR, ".ear", null, "application/ear"),
+ WAR(AppConstants.NAV_WAR, ".war", null, "application/war"),
+ EJB(AppConstants.NAV_EJB, ".jar", null, " application/java-archive"),
+ SAR(AppConstants.NAV_SAR, ".sar", "-service.xml", "application/sar"),
+ RAR(AppConstants.NAV_RAR, ".rar", null, "application/rar"),
+ MC_BEAN(AppConstants.NAV_MC, "", null, "application/java-archive");
+ // -- Fields --
+
protected final String navTreeLabel;
public String getNavTreeLabel() { return navTreeLabel; }
@@ -50,21 +56,33 @@
protected final String suffix;
public String getSuffix() { return suffix; }
+ protected final String mimeType;
+ public String getMimeType() { return mimeType; }
- private DeployableTypes(String navTreeLabel, String extension, String suffix) {
+
+
+ // -- Constructors --
+
+ private DeployableTypes(
+ String navTreeLabel, String extension,
+ String suffix, String mimeType)
+ {
this.navTreeLabel = navTreeLabel;
this.extension = extension;
this.suffix = suffix;
+ this.mimeType = mimeType;
}
+
}// enum DeployableTypes
-
+ /** Several ways how to deploy / undeploy. */
public enum DeploymentMeans {
VIA_EMBJOPR,
VIA_FILESYSTEM,
- VIA_JMX
+ VIA_JMX,
+ VIA_MANAGEMENTVIEW
}
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-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-17 22:18:25 UTC (rev 238)
@@ -22,16 +22,10 @@
package org.jboss.jopr.jsfunit;
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 org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.math.NumberUtils;
-import org.w3c.dom.Element;
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-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-03-17 22:18:25 UTC (rev 238)
@@ -914,7 +914,7 @@
ejtt.sleep( 2000 );
// Log the message
- logServerMessage("Something went wrong with deploy: ");
+ ejtt.logServerMessage("Something went wrong with deploy: ");
}
private void undeployEar( String earFileName ) throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
@@ -923,33 +923,19 @@
// Navigate to Enterprise Archives
ejtt.getNavTree().getNodeLink(NAV_EAR).click();
- ejtt.getTabMenu().clickTab("Summary");
+ ejtt.getTabMenu().clickSummaryTab();
HtmlButtonInput deleteButton = getAppDeleteButton( earFileName );
deleteButton.click();
- // Log the message
- logServerMessage("Something went wrong with undeploy: ");
+ // Log the message (with prefix of potential warning)
+ ejtt.logServerMessage("Something went wrong with undeploy: ");
- // Sleep for 3 sec.
+ // Sleep for 3 sec. TODO: write some waitForUndeployed()
ejtt.sleep( 3000 );
}
- private void logServerMessage(){ logServerMessage(""); }
- private void logServerMessage( String warnPrefix ){
- if( server.getFacesMessages().hasNext() ){
- FacesMessage msg = server.getFacesMessages().next();
- if( msg.getSeverity() == FacesMessage.SEVERITY_INFO ){
- log.info( msg.getSummary() +"\n"+ msg.getDetail() );
- }else{
- log.warn( warnPrefix + msg.getSummary() +"\n"+ msg.getDetail() );
- }
- }
- }
-
-
-
}// class EarTest
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-03-17 22:18:25 UTC (rev 238)
@@ -27,11 +27,13 @@
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
-import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import com.gargoylesoftware.htmlunit.WebClient;
-import org.jboss.jopr.jsfunit.exceptions.DeploymentException;
+import java.io.File;
+import java.io.FileNotFoundException;
+import org.jboss.jopr.jsfunit.exceptions.ActionNotAvailableException;
+import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
@@ -62,57 +64,94 @@
* deployed. Undeploy the archive.
*
*/
- public void testBasicWarDeployment() throws IOException
+ public void testBasicWarDeployment()
+ throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
{
- deployWAR();
+ String filePath = ejtt.getTestDataDir() + "/war/"+BASIC_WAR;
- // Check the success message.
- String expectedMessage = "Resource hellothere.war created successfully!";
- checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+ try {
+ deployWAR( filePath );
- // Use JMX to assert that the WAR really did deploy successfully
- assertTrue("WAR was not deployed according to JMX", isWarDeployed("hellothere.war"));
+ // Check the success message.
+ String expectedMessage = "Resource hellothere.war created successfully!";
+ checkClientAndServerMessages(expectedMessage, expectedMessage, false);
- // use HtmlUnit to test the newly deployed war in a new WebClient session
- // note that I have full access to the FacesContext and the previous request
- //Thread.sleep(3000); // Give JBoss some time to launch the webapp.
- HttpServletRequest request =
- (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
- int port = request.getLocalPort();
- WebClient webClient = new WebClient();
- HtmlPage page = (HtmlPage)webClient.getPage("http://localhost:" + port + "/hellothere/hello.jsp");
- assertTrue(page.asText().contains("HELLO WORLD"));
+ // Use JMX to assert that the WAR really did deploy successfully
+ assertTrue("WAR was not deployed according to JMX", isWarDeployed(BASIC_WAR));
- // Undeploy the WAR
- HtmlButtonInput deleteButton = getAppDeleteButton("hellothere.war");
- deleteButton.click();
+ // use HtmlUnit to test the newly deployed war in a new WebClient session
+ // note that I have full access to the FacesContext and the previous request
+ //Thread.sleep(3000); // Give JBoss some time to launch the webapp.
+ HttpServletRequest request =
+ (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
+ int port = request.getLocalPort();
+ WebClient webClient = new WebClient();
+ HtmlPage page = (HtmlPage)webClient.getPage("http://localhost:" + port + "/hellothere/hello.jsp");
+ assertTrue(page.asText().contains("HELLO WORLD"));
- // This assert doesn't work. jopr does remove the WAR, but for some
- // reason, JBoss doesn't undeploy the MBeans
- // JBAS-XXXX
- //assertFalse(isWarDeployed("hellothere.war"));
+ // Undeploy the WAR
+ HtmlButtonInput deleteButton = getAppDeleteButton(BASIC_WAR);
+ deleteButton.click();
+
+ // This assert doesn't work. jopr does remove the WAR, but for some
+ // reason, JBoss doesn't undeploy the MBeans
+ // JBAS-XXXX
+ //assertFalse(isWarDeployed(BASIC_WAR));
+ }
+ finally {
+ undeployWAR(BASIC_WAR);
+ }
}
/**
* Deploys WAR.
*/
- private void deployWAR() throws IOException {
- // click the nave tree
- HtmlAnchor warLink = getNavTreeLink(NAV_WAR);
- warLink.click();
+ private void deployWAR( String warFilePath )
+ throws IOException, HtmlElementNotFoundException
+ {
+ if( !(new File(warFilePath)).exists())
+ throw new FileNotFoundException(warFilePath);
+
+ log.info("Deploying: "+warFilePath);
+ // Navigate to Enterprise Archives
+ //ejtt.getNavTree().getNodeLink(NAV_WAR).click();
+ ejtt.getNavTree().getNodeLink(AppConstants.DeployableTypes.WAR.getNavTreeLabel()).click();
+
// click on the "Add new resource" button
client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
- // upload hellothere.war
+ // Upload the file
HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
fileInput.setContentType("application/war");
- fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/war/hellothere.war");
+ fileInput.setValueAttribute(warFilePath);
client.click("createContentForm:addButton");
+ ejtt.sleep( 2000 );
}
+
+ private void undeployWAR( String warFileName )
+ throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
+ {
+
+ // Navigate to Enterprise Archives
+ ejtt.getNavTree().getNodeLink(NAV_EAR).click();
+
+ ejtt.getTabMenu().clickSummaryTab();
+
+ HtmlButtonInput deleteButton = getAppDeleteButton( warFileName );
+ deleteButton.click();
+
+ // Log the message (with prefix of potential warning)
+ ejtt.logServerMessage("Something went wrong with undeploy: ");
+
+ // Sleep for 3 sec. TODO: write some waitForUndeployed()
+ 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-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-17 22:18:25 UTC (rev 238)
@@ -9,12 +9,16 @@
import org.jboss.jopr.jsfunit.exceptions.*;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
+import javax.faces.application.FacesMessage;
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.jboss.logging.Logger;
import org.mozilla.javascript.NativeFunction;
import org.w3c.dom.Element;
@@ -28,10 +32,11 @@
*/
public class EmbJoprTestToolkit {
+ private Logger log = Logger.getLogger(EmbJoprTestToolkit.class.getName());
+
protected JSFClientSession client;
protected JSFServerSession server;
private EmbJoprTestToolkit selfEjtt; // For closures.
-
public JSFClientSession getClient() { return client; }
public JSFServerSession getServer() { return server; }
@@ -1204,6 +1209,109 @@
+
+ public void logServerMessage(){ logServerMessage(""); }
+
+ public void logServerMessage( String warnPrefix ){
+ if( server.getFacesMessages().hasNext() ){
+ FacesMessage msg = server.getFacesMessages().next();
+ if( msg.getSeverity() == FacesMessage.SEVERITY_INFO ){
+ log.info( msg.getSummary() +"\n"+ msg.getDetail() );
+ }else{
+ log.warn( warnPrefix + msg.getSummary() +"\n"+ msg.getDetail() );
+ }
+ }
+ }
+
+
+
+ public class Deployment {
+
+ // TODO: Shortcuts:
+ /*
+ private void deployWAR( String warFilePath ){
+
+ }
+
+ private void undeployWAR( String warFileName ){
+
+ }
+
+ private void deployEAR( String warFilePath ){
+
+ }
+
+ private void undeployEAR( String warFileName ){
+
+ }
+ // Etc. */
+
+
+
+ /**
+ * Deploys the deployable using EmbJopr's web UI.
+ *
+ * @param type Type of the deployable - EAR, SAR, WAR, ...
+ */
+ private void deployViaEmbJopr( AppConstants.DeployableTypes type, String filePath )
+ throws IOException, HtmlElementNotFoundException
+ {
+ if( !(new File(filePath)).exists())
+ throw new FileNotFoundException(filePath);
+
+ log.info("Deploying: "+filePath);
+
+ // Navigate to appropriate page
+ getNavTree().getNodeLink(type.getNavTreeLabel()).click();
+
+ // click on the "Add new resource" button
+ client.click("actionHeaderForm:addNewContent"); // 404 if setThrowExceptionOnFailingStatusCode(true) above
+
+ // Upload the file
+ HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
+ fileInput.setContentType(type.getMimeType());
+ fileInput.setValueAttribute( filePath );
+ client.click("createContentForm:addButton");
+ sleep( 2000 );
+
+ }// deployViaEmbJopr()
+
+
+
+ /**
+ * Undeploys the deployable using EmbJopr's web UI.
+ *
+ * @param type Type of the deployable - EAR, SAR, WAR, ...
+ */
+ private void undeployViaEmbJopr( AppConstants.DeployableTypes type, String fileName )
+ throws IOException, HtmlElementNotFoundException, ActionNotAvailableException, ActionOutOfSyncException
+ {
+
+ // Navigate to Enterprise Archives
+ getNavTree().getNodeLink(type.getNavTreeLabel()).click();
+
+ getTabMenu().clickSummaryTab();
+
+ // Not tested
+ HtmlButtonInput deleteButton = (HtmlButtonInput) getTabMenu().getTabContentBox()
+ .getFirstTable().getFirstRowContainingText(fileName).getButtonByLabel("Delete");
+ deleteButton.click();
+
+ // Log the message (with prefix of potential warning)
+ logServerMessage("Something went wrong with undeploy: ");
+
+ // Sleep for 3 sec. TODO: write some waitForUndeployed()
+ sleep( 3000 );
+
+ }// undeployViaEmbJopr()
+
+
+ }
+
+
+
+
+
// TODO
protected class JMXDeploymentInfo {
15 years, 10 months
EMBJOPR SVN: r237 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util.
by embjopr-commits@lists.jboss.org
Author: ozizka(a)redhat.com
Date: 2009-03-17 15:32:30 -0400 (Tue, 17 Mar 2009)
New Revision: 237
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
Docs updated.
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-17 18:41:34 UTC (rev 236)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-17 19:32:30 UTC (rev 237)
@@ -160,6 +160,8 @@
* @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.
+ *
+ * @see EMBJOPR-92.
*/
public void waitUntilLoaded( int msInterval, int retries ) throws Exception {
final NavTree self = this;
@@ -273,6 +275,9 @@
}
+ /**
+ * Returns true if the JS function object 'Tree.Item' is initialized.
+ */
public boolean isReady(){
Object obj = getJavaScriptObject("Tree.Item");
if( null == obj ) return false;
@@ -281,6 +286,16 @@
return true;
}
+
+ /**
+ * Waits until the JS function object 'Tree.Item' is initialized.
+ * @param msInterval Millisecons between tries.
+ * @param retries Number of tries.
+ * @throws org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException
+ * wrapping whatever exception happens when checking the JS object's value.
+ *
+ * @see https://jira.jboss.org/jira/browse/EMBJOPR-101
+ */
public void waitUntilReady( int msInterval, int retries ) throws EmbJoprTestException {
final NavTree self = this;
try {
15 years, 10 months