[embjopr-commits] EMBJOPR SVN: r322 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.
embjopr-commits at lists.jboss.org
embjopr-commits at lists.jboss.org
Thu Apr 23 12:35:49 EDT 2009
Author: ozizka at redhat.com
Date: 2009-04-23 12:35:49 -0400 (Thu, 23 Apr 2009)
New Revision: 322
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JBossASNodeTest.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.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:
EAR and WAR tests updated - ConfigurationTab tests enabled
Added JBossASNodeTest.java
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-04-23 14:17:52 UTC (rev 321)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-04-23 16:35:49 UTC (rev 322)
@@ -28,6 +28,7 @@
public static final String SYSPROP_TESTDATA_DIR = "jsfunit.testdata";
public static final String SYSPROP_TEMP_DIR = "jsfunit.tempdir";
public static String SYSPROP_JBOSS_CONFIG = "jboss.configuration";
+ public static String SYSPROP_CARGO_JBOSS_HOME_DIR = "jsfunit.jboss.home.dir";
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-04-23 14:17:52 UTC (rev 321)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-04-23 16:35:49 UTC (rev 322)
@@ -22,6 +22,7 @@
package org.jboss.jopr.jsfunit.as5;
+import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import org.jboss.jopr.jsfunit.util.DescribedCondition;
import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
@@ -396,7 +397,7 @@
* Changes EAR configuration, and checks whether the changes were saved.
*
*/
- public void DISABLEDtestEarConfigurationTab() throws IOException, EmbJoprTestException {
+ public void testEarConfigurationTab() throws IOException, EmbJoprTestException {
// Deploy the EAR.
String earFilePath = ejtt.getTestDataDir() +"/ear/"+ BASIC_EAR;
@@ -410,7 +411,11 @@
// Navigate to the Configuration tab
ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
earRow.getLinkByLabel(BASIC_EAR).click();
+
+ Page prevPage = client.getContentPage();
ejtt.tabMenu.clickConfigurationTab();
+ assertNotSame("We should move to other page after clicking the Config tab.",
+ prevPage, client.getContentPage());
// Read properties.
Properties props = new Properties();
@@ -452,7 +457,7 @@
* Changes EAR configuration, and verifies that the changes were NOT saved.
*
*/
- public void DISABLEDtestEarConfigurationTabCancel() throws IOException, EmbJoprTestException {
+ public void testEarConfigurationTabCancel() throws IOException, EmbJoprTestException {
// Deploy the EAR.
String earFilePath = ejtt.getTestDataDir() +"/ear/"+ BASIC_EAR;
@@ -466,7 +471,11 @@
// Navigate to the Configuration tab
ContentTableRow earRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
earRow.getLinkByLabel(BASIC_EAR).click();
+
+ Page prevPage = client.getContentPage();
ejtt.tabMenu.clickConfigurationTab();
+ assertNotSame("We should move to other page after clicking the Config tab.",
+ prevPage, client.getContentPage());
// Load properties (we will use their names).
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JBossASNodeTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JBossASNodeTest.java (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/JBossASNodeTest.java 2009-04-23 16:35:49 UTC (rev 322)
@@ -0,0 +1,162 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jboss.jopr.jsfunit.as5;
+
+import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import java.io.IOException;
+import java.util.Properties;
+import javax.management.JMException;
+import org.apache.commons.lang.math.NumberUtils;
+import org.jboss.jopr.jsfunit.EmbjoprTestCase;
+import org.jboss.jopr.jsfunit.JMXUtils;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentInfoTable;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTable;
+
+/**
+ *
+ * @author ondra
+ */
+public class JBossASNodeTest extends EmbjoprTestCase {
+
+ public void testASNodeMetricsTab() throws EmbJoprTestException, IOException, JMException {
+
+ // JBoss App Server:${config} node
+ String pageText = client.getPageAsText();
+
+ // Whole page contains
+ String jbossConfig = ejtt.getJBossConfig();
+ String pageHeaderText = "JBoss AS 5 ("+jbossConfig+")";
+ //assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
+ assertTrue("Content doesn't contain the header: "+pageHeaderText,
+ client.getElement("content").getTextContent().contains(pageHeaderText));
+
+ ContentTable table;
+ ContentInfoTable infoTable;
+ String headerText;
+ Properties properties;
+
+ JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
+
+
+ /*
+ * General Properties
+ Name:JBoss AS 5 (default)
+ Version:5.1.0.CR1
+ Description:JBoss Application Server
+ */
+ headerText = "General Properties";
+ assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
+ table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
+ infoTable = ejtt.getContentInfoTable(table.getElement());
+ properties = infoTable.getProperties();
+
+ assertEquals("General Properties / Name", pageHeaderText, properties.getProperty("Name") );
+
+ String versionPrefix = "5.1";
+ String jmxMBeanName = "jboss.system:type=Server";
+ versionPrefix = (String) jmxUtils.getMBeanAttribute(jmxMBeanName, "VersionNumber");
+
+ assertTrue("General Properties / Version startsWith('"+versionPrefix+"')",
+ properties.getProperty("Version","~not found~").startsWith(versionPrefix) );
+ assertEquals("General Properties / Description", "JBoss Application Server", properties.get("Description") );
+
+
+ /*
+ * Resource Traits
+ Server Name: default
+ Server Home Dir: /home/brq/ozizka/.../jboss-as-5.x/build/output/jboss-5.1.0.CR1/server/default
+ Version Name: The Oracle
+ Build Date: April 22 2009
+ Start Date: Wed Apr 22 18:26:43 CEST 2009
+ */
+ headerText = "Resource Traits";
+ assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
+ table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
+ infoTable = ejtt.getContentInfoTable(table.getElement());
+ properties = infoTable.getProperties();
+
+ assertEquals("Resource Traits / Server Name", ejtt.getJBossConfig(),
+ properties.getProperty("Server Name"));
+
+ assertEquals("Resource Traits / Server Home Dir",
+ String.format("%s/server/%s", ejtt.getJBossHomeDir(), ejtt.getJBossConfig()),
+ properties.getProperty("Server Home Dir"));
+
+
+ /*
+ * Metrics Summary
+ Name Value Description
+ Active Thread Count 7.0 The current number of active threads for this app server instance
+ JVM Free Memory 183.6MB The amount of free memory for the JVM this app server instance is running on
+ JVM Total Memory 218.7MB The amount of total memory for the JVM this app server instance is running on
+ */
+ headerText = "Metrics Summary";
+ assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
+ table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
+
+ // Get values as properties.
+ table.analyzeColumns();
+ Properties metricsProps = table.getProperties("Name", "Value");
+ log.info( headerText +" 1st: "+ metricsProps.toString() );
+
+ // Active Thread Count
+ int threads1 = NumberUtils.toInt(metricsProps.getProperty("Active Thread Count"));
+ double memFree1 = NumberUtils.toDouble(metricsProps.getProperty("JVM Free Memory"));
+ double memTotal1 = NumberUtils.toDouble(metricsProps.getProperty("JVM Total Memory"));
+
+
+ // Do some requests to add threads.
+
+ // Create HTMLUnit WebClient.
+ WebClient wc = new WebClient(BrowserVersion.FIREFOX_3);
+ wc.setCssEnabled(false);
+ wc.setJavaScriptEnabled(false);
+ // Get some page.
+ wc.getPage("http://localhost:8080/");
+
+ // Allocate some memory to decrease free mem.
+ byte tmp[] = new byte[5 * 1024 * 1024]; // Few MB.
+
+
+
+ // Refresh the page
+ ((HtmlPage)client.getContentPage()).refresh();
+
+ // Read new values.
+ headerText = "Metrics Summary";
+ assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
+ table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
+
+ // Get values as properties.
+ table.analyzeColumns();
+ metricsProps = table.getProperties("Name", "Value");
+ log.info( headerText +" 2nd: "+ metricsProps.toString() );
+
+ // Active Thread Count
+ int threads2 = NumberUtils.toInt(metricsProps.getProperty("Active Thread Count"));
+ double memFree2 = NumberUtils.toDouble(metricsProps.getProperty("JVM Free Memory"));
+ double memTotal2 = NumberUtils.toDouble(metricsProps.getProperty("JVM Total Memory"));
+
+ log.info( "Value | old | new ");
+ log.info( String.format("Threads: %d, %d", threads1, threads2) );
+ log.info( String.format("Mem free: %f, %f", memFree1, memFree2) );
+ log.info( String.format("Mem total: %f, %f", memTotal1, memTotal2) );
+
+ assertTrue("New thread count should be >= old. Is: "+threads1 +","+ threads2, threads1 > threads2);
+ assertTrue("New free mem should be <= old. Is: "+memFree1 +","+ memFree2, memFree1 < memFree2);
+ assertTrue("New total mem should be = old. Is: "+memTotal1 +","+ memTotal2, memTotal1 == memTotal2);
+
+ }
+
+
+}// class
+
+
+
+
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-04-23 14:17:52 UTC (rev 321)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-04-23 16:35:49 UTC (rev 322)
@@ -22,6 +22,7 @@
package org.jboss.jopr.jsfunit.as5;
+import com.gargoylesoftware.htmlunit.Page;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
@@ -389,7 +390,7 @@
* Changes WAR configuration, and checks whether the changes were saved.
*
*/
- public void DISABLEDtestWarConfigurationTab() throws IOException, EmbJoprTestException, HtmlElementNotFoundException, Exception {
+ public void testWarConfigurationTab() throws IOException, EmbJoprTestException, HtmlElementNotFoundException, Exception {
final String DEPLOYABLE_NAME = BASIC_WAR_04;
@@ -405,9 +406,11 @@
// Navigate to the Configuration tab
ContentTableRow appRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
appRow.getLinkByLabel(DEPLOYABLE_NAME).click();
- DebugUtils.writeFile("target/A1.html", client.getPageAsText());
+
+ Page prevPage = client.getContentPage();
ejtt.tabMenu.clickConfigurationTab();
- DebugUtils.writeFile("target/A2.html", client.getPageAsText());
+ assertNotSame("We should move to other page after clicking the Config tab.",
+ prevPage, client.getContentPage());
// Read properties.
Properties props = new Properties();
@@ -448,7 +451,7 @@
*
* FAILS because some of the values are read-only. EMBJOPR-96
*/
- public void DISABLEDtestWarConfigurationTabCancel() throws IOException, EmbJoprTestException {
+ public void testWarConfigurationTabCancel() throws IOException, EmbJoprTestException {
final String DEPLOYABLE_NAME = BASIC_WAR_05;
@@ -465,7 +468,11 @@
// Navigate to the Configuration tab
ContentTableRow row = ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
row.getLinkByLabel(DEPLOYABLE_NAME).click();
+
+ Page prevPage = client.getContentPage();
ejtt.tabMenu.clickConfigurationTab();
+ assertNotSame("We should move to other page after clicking the Config tab.",
+ prevPage, client.getContentPage());
// Load properties (we will use their names).
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-04-23 14:17:52 UTC (rev 321)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-04-23 16:35:49 UTC (rev 322)
@@ -107,6 +107,10 @@
return System.getProperty(AppConstants.SYSPROP_JBOSS_CONFIG);
}
+ public String getJBossHomeDir() {
+ return System.getProperty(AppConstants.SYSPROP_CARGO_JBOSS_HOME_DIR);
+ }
+
public JavaScriptEngine getJavaScriptEngine(){
return client.getContentPage().getEnclosingWindow().getWebClient().getJavaScriptEngine();
}
@@ -978,9 +982,36 @@
return index;
}
+
+ /**
+ * Creates a properties using values from this table.
+ * @param keyColName Name of column containing the key (e.g. "Name").
+ * @param valueColName Name of column containing the value (e.g. "Value").
+ */
+ public Properties getProperties( String keyColName, String valueColName ) throws HtmlElementNotFoundException
+ {
+ int keyColIndex = this.getColumnIndexByName(keyColName);
+ int valColindex = this.getColumnIndexByName(valueColName);
+
+ Properties props = new Properties();
+
+ for( ContentTableRow row : this.getRows() ){
+ String key = row.getCell( keyColIndex ).getTextContent();
+ String value = row.getCell( valColindex ).getTextContent();
+ props.setProperty(key, value);
+ }
+
+ return props;
+ }
+
+
+
}// inner class ContentTable
+
+
+
/**
* Creates a data table wrapper for first found element with one of these IDs:
* ID_CATEGORY_DATA_TABLE, ID_RESOURCE_DATA_TABLE
More information about the embjopr-commits
mailing list