[jboss-cvs] JBossAS SVN: r60037 - projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 26 19:45:07 EST 2007


Author: chilin
Date: 2007-01-26 19:45:07 -0500 (Fri, 26 Jan 2007)
New Revision: 60037

Added:
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsDestinationTestCase.java
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsPageTest.java
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsQueueTest.java
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsTopicTest.java
Modified:
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqPageTest.java
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqQueueTest.java
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java
Log:
Add initial webtests for JBoss Messaging.

Modified: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java	2007-01-27 00:39:47 UTC (rev 60036)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -52,11 +52,11 @@
  * @author <a href="chi.lin at unisys.com">Chi Lin </a>
  * @version $Revision$
  */
-public abstract class DestinationTestCase extends AdminConsoleTestCase {
+public abstract class JBossmqDestinationTestCase extends AdminConsoleTestCase {
 
-	private static Log log = LogFactory.getLog(DestinationTestCase.class);
+	private static Log log = LogFactory.getLog(JBossmqDestinationTestCase.class);
 
-	private final static String LIST_DESTINATIONS_PREFIX = "/admin/jms/destination/list.html?type=";
+	private final static String LIST_DESTINATIONS_PREFIX = "/admin/jbossmq/destination/list.html?type=";
 
 	/*
 	 * Define href used by the destination pages
@@ -90,7 +90,7 @@
 
 	protected final Properties msgProps;
 
-	public DestinationTestCase(String arg0) throws Exception {
+	public JBossmqDestinationTestCase(String arg0) throws Exception {
 		super(arg0);
 
 		/*
@@ -434,7 +434,7 @@
 	 *            The page to be verified
 	 * @throws Exception
 	 */
-	protected void verifyJBossmqSettingsPage(HtmlPage page) throws Exception {
+	protected void verifySettingsPage(HtmlPage page) throws Exception {
 		/*
 		 * Get the destination form and verify the existence of the input
 		 * fields:

Modified: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqPageTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqPageTest.java	2007-01-27 00:39:47 UTC (rev 60036)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqPageTest.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -273,7 +273,7 @@
 		final HtmlForm form = stateSqlPage.getFormByName("jms");
 		final HtmlTextInput createTablesOnStartup = (HtmlTextInput) form
 				.getInputByName("stateSqlMap(CREATE_TABLES_ON_STARTUP)");
-		final HtmlTextInput createUserTalbe = (HtmlTextInput) form
+		final HtmlTextInput createUserTable = (HtmlTextInput) form
 				.getInputByName("stateSqlMap(CREATE_USER_TABLE)");
 		final HtmlTextInput createRoleTable = (HtmlTextInput) form
 				.getInputByName("stateSqlMap(CREATE_ROLE_TABLE)");

Modified: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqQueueTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqQueueTest.java	2007-01-27 00:39:47 UTC (rev 60036)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqQueueTest.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -61,7 +61,7 @@
  * @author <a href="chi.lin at unisys.com">Chi Lin </a>
  * @version $Revision$
  */
-public class JBossmqQueueTest extends DestinationTestCase {
+public class JBossmqQueueTest extends JBossmqDestinationTestCase {
 
 	private static Log log = LogFactory.getLog(JBossmqQueueTest.class);
 
@@ -343,7 +343,7 @@
 		 */
 		HtmlPage destPage = getDestinationDetailPage(DESTINATION_QUEUE,
 				TEST_QUEUE);
-		verifyJBossmqSettingsPage(destPage);
+		verifySettingsPage(destPage);
 
 		/*
 		 * Click the "More" tab and verify the page:

Modified: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java	2007-01-27 00:39:47 UTC (rev 60036)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -58,7 +58,7 @@
  * @author <a href="chi.lin at unisys.com">Chi Lin </a>
  * @version $Revision$
  */
-public class JBossmqTopicTest extends DestinationTestCase {
+public class JBossmqTopicTest extends JBossmqDestinationTestCase {
 
 	private static Log log = LogFactory.getLog(JBossmqTopicTest.class);
 
@@ -404,7 +404,7 @@
 		 */
 		HtmlPage destPage = getDestinationDetailPage(DESTINATION_TOPIC,
 				TEST_TOPIC);
-		verifyJBossmqSettingsPage(destPage);
+		verifySettingsPage(destPage);
 
 		/*
 		 * Click the "More" tab and verify the page:

Added: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsDestinationTestCase.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsDestinationTestCase.java	                        (rev 0)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsDestinationTestCase.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -0,0 +1,487 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.admin.console.webtest;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import com.gargoylesoftware.htmlunit.html.HtmlTableBody;
+import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+/**
+ * Base class for integration tests of the destinations.
+ * 
+ * @author <a href="chi.lin at unisys.com">Chi Lin </a>
+ * @version $Revision: 59929 $
+ */
+public abstract class JmsDestinationTestCase extends AdminConsoleTestCase {
+
+	private static Log log = LogFactory.getLog(JmsDestinationTestCase.class);
+
+	private final static String LIST_DESTINATIONS_PREFIX = "/admin/jms/destination/list.html?type=";
+
+	/*
+	 * Define href used by the destination pages
+	 */
+	protected final static String HREF_SETTINGS_PAGE = "javascript:void(setPageAndSubmit('page1'))";
+
+	protected final static String HREF_MORE_PAGE = "javascript:void(setPageAndSubmit('page2'))";
+
+	protected final static String HREF_MESSAGES_PAGE = "javascript:void(setDispatchAndSubmit('viewMessages'))";
+
+	protected final static String HREF_SUBSCRIPTIONS_PAGE = "javascript:void(setDispatchAndSubmit('viewSubscriptions'))";
+
+	/*
+	 * Define submit buttons unique to the destination pages
+	 */
+	protected final static String VIEW_DATA_BUTTON = "View Data";
+
+	protected final static String REMOVE_ALL_MESSAGES_BUTTON = "Remove All Messages";
+	
+	protected final static String VIEW_MESSAGES_BUTTON = "View Messages";
+
+	protected final Properties msgProps;
+
+	public JmsDestinationTestCase(String arg0) throws Exception {
+		super(arg0);
+
+		/*
+		 * Load the message properties:
+		 */
+		msgProps = loadProperties(jmsMsgFile);
+	}
+
+	/**
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/**
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Get the html page containing a list of destinations of a specific type.
+	 * 
+	 * @param destType
+	 *            The type of the destination
+	 * @return The html page
+	 * @throws Exception
+	 */
+	protected HtmlPage getDestinationListPage(String destType) throws Exception {
+		/*
+		 * Get the Admin Console's home page then click the desired destination
+		 * link:
+		 */
+		HtmlPage homePage = (HtmlPage) webClient.getPage(adminUrl);
+		String href = LIST_DESTINATIONS_PREFIX + destType;
+		HtmlPage listPage = clickLink(homePage, href);
+		return listPage;
+	}
+
+	/**
+	 * Get the html page used to create a destination.
+	 * 
+	 * @param destType
+	 *            The type of the destination to create
+	 * @return The html page
+	 * @throws Exception
+	 */
+	protected HtmlPage getDestinationCreatePage(String destType)
+			throws Exception {
+		/*
+		 * Get the destinations list page and find the first
+		 * destinationIdentifier form:
+		 */
+		HtmlPage listPage = getDestinationListPage(destType);
+		HtmlForm idForm = listPage.getFormByName("destinationIdentifier");
+
+		/*
+		 * Click the "Create" button and return the page:
+		 */
+		HtmlPage createPage = clickButton(idForm, CREATE_BUTTON);
+		return createPage;
+	}
+
+	/**
+	 * Get the total number of destinations of a specific type.
+	 * 
+	 * @param destType
+	 *            The destination type
+	 * @return The number of destinations
+	 * @throws Exception
+	 */
+	protected int getNumberOfDestinations(String destType) throws Exception {
+		HtmlPage listPage = getDestinationListPage(destType);
+		int result = getNumberOfDestinations(listPage);
+		return result;
+	}
+
+	/**
+	 * Get the total number of destinations on a destination list page.
+	 * 
+	 * @param listPage
+	 *            The destination list page
+	 * @return The number of destinations
+	 * @throws Exception
+	 */
+	protected int getNumberOfDestinations(HtmlPage listPage) throws Exception {
+		int result = 0;
+
+		try {
+			HtmlTable table = (HtmlTable) listPage
+					.getHtmlElementById("destTable");
+			List forms = table.getHtmlElementsByTagName("form");
+			result = forms.size();
+		} catch (ElementNotFoundException e) {
+			// No destTable on the page, return 0
+		}
+
+		return result;
+	}
+
+	/**
+	 * Get the initial context of the JBoss naming service.
+	 */
+	protected InitialContext getInitialContext() {
+		InitialContext ctx = null;
+		Properties prop = new Properties();
+		prop.put(Context.PROVIDER_URL, "localhost:1099");
+		prop.put(Context.INITIAL_CONTEXT_FACTORY,
+				"org.jnp.interfaces.NamingContextFactory");
+		prop.put(Context.URL_PKG_PREFIXES,
+				"org.jboss.naming:org.jnp.interfaces");
+
+		try {
+			ctx = new InitialContext(prop);
+		} catch (NamingException e) {
+			fail("Unable to get initial context");
+		}
+		return ctx;
+	}
+
+	/**
+	 * Create a destination of a specific type, using the provided attributes.
+	 * 
+	 * @param destType
+	 *            The type of destination to be created
+	 * @param attMap
+	 *            The attribute name & value pairs
+	 * @return The html page returned after the "Create" button is clicked
+	 * @throws Exception
+	 */
+	protected HtmlPage createDestination(String destType, Map attMap)
+			throws Exception {
+		/*
+		 * Get the destination create page of appropriate type:
+		 */
+		HtmlPage createPage = getDestinationCreatePage(destType);
+
+		/*
+		 * Fill the attribute values using the provided list:
+		 */
+		String key = null;
+		String value = null;
+		HtmlTextInput htmlInput;
+		HtmlForm destForm = createPage.getFormByName("destination");
+		Set keys = attMap.keySet();
+		Iterator iter = keys.iterator();
+
+		while (iter.hasNext()) {
+			key = (String) iter.next();
+			value = (String) attMap.get(key);
+			htmlInput = (HtmlTextInput) destForm.getInputByName(key);
+			htmlInput.setValueAttribute(value);
+		}
+
+		/*
+		 * Click the "Save" button to create the destination :
+		 */
+		HtmlPage listPage = clickButton(destForm, SAVE_BUTTON);
+
+		return listPage;
+	}
+
+	/**
+	 * Remove the specified destination of a specific type.
+	 * 
+	 * @param destType
+	 *            The type of the destination
+	 * @param name
+	 *            The name of the destination
+	 * @param okReply
+	 *            True to provide a "Ok" reply to confirm the remove action,
+	 *            false to cancel the action
+	 * @return The resulting html page
+	 * @throws Exception
+	 */
+	protected HtmlPage removeDestination(String destType, String name,
+			boolean okReply) throws Exception {
+		/*
+		 * Get the destination entry from the list page:
+		 */
+		HtmlPage listPage = getDestinationListPage(destType);
+		HtmlForm form = getDestinationEntryFromList(listPage, name);
+
+		if (form != null) {
+			/*
+			 * A confirm box will pop up when we remove a destination. Register
+			 * a confirm handler to enter our choice:
+			 */
+			webClient.setConfirmHandler(new ConfirmHandlerImpl(okReply));
+
+			/*
+			 * Click the "Remove" button and verify the returned message, if
+			 * any:
+			 */
+			listPage = clickButton(form, REMOVE_BUTTON);
+			if (okReply) {
+				String expectedMsg = "The process of removing the "
+						+ destType
+						+ " has been started successfully, but may not yet have completed.";
+				assertTrue(EXP_MSG_NOT_FOUND,
+						findMessage(listPage, expectedMsg));
+			}
+
+			/*
+			 * Wait for hot deploy to complete its job:
+			 */
+			Thread.sleep(hotDeployWaitTime * 2);
+		}
+
+		return listPage;
+	}
+
+	/**
+	 * Get a specific destination entry from the provided destination list page.
+	 * 
+	 * @param listPage
+	 *            The destination list page
+	 * @param jndiName
+	 *            The jndi name of the destination to be located
+	 * @return The html form of the specified destination, or null if the entry
+	 *         is not found
+	 * @throws Exception
+	 */
+	protected HtmlForm getDestinationEntryFromList(HtmlPage listPage,
+			String jndiName) throws Exception {
+		/*
+		 * Get the destTable and walk through the forms and table bodies to find
+		 * the row containing the destination we're looking for:
+		 */
+		HtmlForm resultForm = null;
+		HtmlForm form = null;
+		List bodies = null;
+		HtmlTableBody tBody = null;
+		List rows = null;
+		HtmlTableRow row = null;
+
+		try {
+			HtmlTable table = (HtmlTable) listPage
+					.getHtmlElementById("destTable");
+			List forms = table.getHtmlElementsByTagName("form");
+			Iterator formIter = forms.iterator();
+
+			while (formIter.hasNext()) {
+				form = (HtmlForm) formIter.next();
+				bodies = form.getHtmlElementsByTagName("tbody");
+				assertEquals("Form should contain 1 <tbody>.", 1, bodies.size());
+
+				tBody = (HtmlTableBody) bodies.get(0);
+				rows = tBody.getRows();
+				assertEquals("<tbody> should contain 1 row.", 1, rows.size());
+
+				row = (HtmlTableRow) rows.get(0);
+				log.debug("name = " + row.getCell(0).asText());
+
+				/*
+				 * Check the jndi name to see if this is the one we're looking
+				 * for:
+				 */
+				if (jndiName.equals(row.getCell(0).asText())) {
+					log.debug("found our row");
+					resultForm = form;
+					break;
+				}
+			}
+		} catch (ElementNotFoundException e) {
+			/*
+			 * We'll end up here if there's no destination on the list page,
+			 * which is ok.
+			 */
+		}
+
+		return resultForm;
+	}
+
+	/**
+	 * Get the detailed page of a specific destination.
+	 * 
+	 * @param destType
+	 *            The type of the destination
+	 * @param jndiName
+	 *            The jndi name of the destination
+	 * @return The datailed destination page
+	 * @throws Exception
+	 */
+	protected HtmlPage getDestinationDetailPage(String destType, String jndiName)
+			throws Exception {
+		/*
+		 * Get destination list page of the specified type:
+		 */
+		HtmlPage listPage = getDestinationListPage(destType);
+
+		/*
+		 * Find the form entry with the specified jndiName:
+		 */
+		HtmlForm destForm = getDestinationEntryFromList(listPage, jndiName);
+
+		/*
+		 * Click the "View" button and return the page:
+		 */
+		HtmlPage viewPage = clickButton(destForm, VIEW_BUTTON);
+		return viewPage;
+	}
+
+	/**
+	 * Get the View Data page of a specific destination
+	 * 
+	 * @param destType
+	 *            The type of the destination
+	 * @param jndiName
+	 *            The jndi name of the destination
+	 * @return The view data page
+	 * @throws Exception
+	 */
+	protected HtmlPage getViewDataPage(String destType, String jndiName)
+			throws Exception {
+		/*
+		 * Get destination list page of the specified type:
+		 */
+		HtmlPage listPage = getDestinationListPage(destType);
+
+		/*
+		 * Find the form entry with the specified jndiName:
+		 */
+		HtmlForm destForm = getDestinationEntryFromList(listPage, jndiName);
+
+		/*
+		 * Click the "View Data" button and return the page:
+		 */
+		HtmlPage dataPage = clickButton(destForm, VIEW_DATA_BUTTON);
+		return dataPage;
+	}
+
+	/**
+	 * Verify the provided page contains the expected input fields of the
+	 * "Settings" page of a JBossMQ destination. Note that the values of the input
+	 * fields are not checked.
+	 * 
+	 * @param page
+	 *            The page to be verified
+	 * @throws Exception
+	 */
+	protected void verifySettingsPage(HtmlPage page) throws Exception {
+		/*
+		 * Get the destination form and verify the existence of the input
+		 * fields:
+		 */
+		HtmlForm form = page.getFormByName("destination");
+		HtmlTextInput name = (HtmlTextInput) form.getInputByName("name");
+		HtmlTextInput jndiName = (HtmlTextInput) form
+				.getInputByName("jndiName");
+		HtmlTextInput downCacheSize = (HtmlTextInput) form
+				.getInputByName("downCacheSize");
+		HtmlTextInput fullSize = (HtmlTextInput) form
+				.getInputByName("fullSize");
+		HtmlTextInput pageSize = (HtmlTextInput) form
+				.getInputByName("pageSize");
+		List securityRoles = form.getTextAreasByName("securityRoles");
+		assertEquals(1, securityRoles.size());
+	}
+
+	/**
+	 * Verify the provided page is a valid "Message Statistics" page, and the
+	 * message count reported on the page matches the specified value.
+	 * 
+	 * @param page
+	 *            The HtmlPage to be verified
+	 * @param type
+	 *            The destination type
+	 * @param name
+	 *            The destination name
+	 * @param totalEntries
+	 *            The total number of statistics entries expected on the page
+	 * @param entryNo
+	 *            The entry number to be checked
+	 * @param msgCount
+	 *            The expected message count on the specified entry
+	 * @throws Exception
+	 */
+	protected void verifyMessageStatisticsPage(HtmlPage page, String type,
+			String name, int totalEntries, int entryNo, int msgCount)
+			throws Exception {
+		/*
+		 * Verify the page heading:
+		 */
+		String expectedMsg = "Message Statistics: " + type + "/" + name;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(page, expectedMsg));
+
+		/*
+		 * Get the msgStatisticsTable and verify the number of rows on the table
+		 * equals to the expected entries plus one (header row):
+		 */
+		HtmlTable table = (HtmlTable) page
+				.getHtmlElementById("msgStatisticsTable");
+		int totalRows = table.getRowCount();
+		assertEquals(totalEntries + 1, totalRows);
+
+		/*
+		 * Verify the message count on the specified entry:
+		 */
+		assertEquals(Integer.toString(msgCount), table.getCellAt(entryNo, 4).asText());
+	}
+}
\ No newline at end of file

Added: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsPageTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsPageTest.java	                        (rev 0)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsPageTest.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -0,0 +1,1105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.admin.console.webtest;
+
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
+import com.gargoylesoftware.htmlunit.html.HtmlOption;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSelect;
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import com.gargoylesoftware.htmlunit.html.HtmlTableBody;
+import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
+import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+/**
+ * Integration tests for managing JBossMQ general settings.
+ * 
+ * @author <a href="chi.lin at unisys.com">Chi Lin </a>
+ * @version $Revision: 59929 $
+ */
+public class JmsPageTest extends AdminConsoleTestCase {
+
+	private static Log log = LogFactory.getLog(JmsPageTest.class);
+
+	private final static String URL_JMS_PAGE = "http://localhost:8080/admin/jms/list.html";
+
+	/*
+	 * Define various href anchors
+	 */
+	private final static String HREF_SETTINGS_PAGE = "javascript:void(setPageAndSubmit('page1'))";
+
+	private final static String HREF_MORE_PAGE = "javascript:void(setPageAndSubmit('page2'))";
+
+	private final static String HREF_MSG_SQL_PAGE = "javascript:void(setPageAndSubmit('page3'))";
+
+	private final static String HREF_USER_SQL_PAGE = "javascript:void(setPageAndSubmit('page4'))";
+
+	private final static String HREF_DATASOURCE_LOCALTX = "/admin/datasource/datasource/list.html?type=localtxdatasources";
+
+	private final URL jmsUrl;
+
+	protected final Properties msgProps;
+
+	public JmsPageTest(String arg0) throws Exception {
+		super(arg0);
+		jmsUrl = new URL(URL_JMS_PAGE);
+
+		/*
+		 * Load the message properties:
+		 */
+		msgProps = loadProperties(jbossmqMsgFile);
+	}
+
+	/**
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/**
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Verify the provided page contains the expected input fields of the jms
+	 * "Settings" page. Note that the value of the input fields are not checked.
+	 * 
+	 * @param jmsPage
+	 *            The HtmlPage to be verified.
+	 * @throws Exception
+	 */
+	private void verifyJmsSettingsPage(HtmlPage jmsPage) throws Exception {
+		/*
+		 * Get the jms form and verify the existence of the input fields:
+		 */
+		final HtmlForm form = jmsPage.getFormByName("jms");
+		final HtmlTextInput defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		final HtmlTextInput defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		final HtmlTextInput defaultTempQueuePageSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueuePageSize");
+		final HtmlTextInput prefetchSize = (HtmlTextInput) form
+				.getInputByName("prefetchSize");
+		final HtmlTextInput queuedExecutorPoolSize = (HtmlTextInput) form
+				.getInputByName("queuedExecutorPoolSize");
+		final HtmlTextInput securityDomain = (HtmlTextInput) form
+				.getInputByName("securityDomain");
+		final List textAreas = form.getTextAreasByName("defaultSecurityRoles");
+		assertEquals(1, textAreas.size());
+		final HtmlCheckBoxInput createMsgTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		final HtmlSelect msgDataSourceName = (HtmlSelect) form
+				.getSelectByName("msgDataSourceName");
+		final List msgDataSourceOptions = msgDataSourceName.getOptions();
+		final HtmlCheckBoxInput usingBatchUpdates = (HtmlCheckBoxInput) form
+				.getInputByName("usingBatchUpdates");
+		final HtmlCheckBoxInput createUserTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createUserTablesOnStartup");
+		final HtmlSelect userDataSourceName = (HtmlSelect) form
+				.getSelectByName("userDataSourceName");
+		final List userDataSourceOptions = userDataSourceName.getOptions();
+	}
+
+	/**
+	 * Verify the provided page contains the expected table and table cells of
+	 * the jms "More" page.
+	 * 
+	 * @param morePage
+	 *            The HtmlPage to be verified.
+	 * @throws Exception
+	 */
+	private void verifyMorePage(HtmlPage morePage) throws Exception {
+		/*
+		 * Get the jmsTable and verify it is not empty:
+		 */
+		final HtmlTable table = (HtmlTable) morePage
+				.getHtmlElementById("jmsTable");
+		final List rows = table.getRows();
+		assertFalse(TABLE_EMPTY, rows.isEmpty());
+
+		/*
+		 * Verify correct labels exist in the table:
+		 */
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("jms.view.defaultQueueJNDIContext"), table
+				.getCellAt(0, 0).asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("jms.view.defaultTopicJNDIContext"), table
+				.getCellAt(1, 0).asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("jms.view.jmsVersion"), table.getCellAt(2, 0)
+				.asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("jms.view.jmsProviderName"), table.getCellAt(3, 0)
+				.asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("jms.view.providerVersion"), table.getCellAt(4, 0)
+				.asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("jms.view.serverPeerID"), table.getCellAt(5, 0)
+				.asText());
+
+		/*
+		 * Verify the data column of each row is not null:
+		 */
+		HtmlTableRow row = null;
+		for (int i = 0; i < rows.size(); i++) {
+			row = (HtmlTableRow) rows.get(i);
+			assertNotNull("Null data in table, row = " + i, row.getCell(1));
+		}
+	}
+
+	/**
+	 * Verify the provided page contains the expected input fields of the jms
+	 * "Message SQL" page. Note that the value of the input fields are not
+	 * checked.
+	 * 
+	 * @param jmsPage
+	 *            The HtmlPage to be verified.
+	 * @throws Exception
+	 */
+	private void verifyMessageSqlPage(HtmlPage msgSqlPage) throws Exception {
+		/*
+		 * Verify the SQL properties for message persistence are present:
+		 */
+		final HtmlForm form = msgSqlPage.getFormByName("jms");
+		final HtmlTextInput blobType = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(BLOB_TYPE)");
+		final HtmlTextInput insertTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(INSERT_TX)");
+		final HtmlTextInput insertMessage = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(INSERT_MESSAGE)");
+		final HtmlTextInput selectAllUncommitedTxs = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(SELECT_ALL_UNCOMMITED_TXS)");
+		final HtmlTextInput selectMaxTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(SELECT_MAX_TX)");
+		final HtmlTextInput deleteAllTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_ALL_TX)");
+		final HtmlTextInput selectMessagesInDest = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(SELECT_MESSAGES_IN_DEST)");
+		final HtmlTextInput selectMessage = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(SELECT_MESSAGE)");
+		final HtmlTextInput markMessage = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(MARK_MESSAGE)");
+		final HtmlTextInput updateMessage = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(UPDATE_MESSAGE)");
+		final HtmlTextInput updateMarkedMessages = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(UPDATE_MARKED_MESSAGES)");
+		final HtmlTextInput updateMarkedMessagesWithTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(UPDATE_MARKED_MESSAGES_WITH_TX)");
+		final HtmlTextInput deleteMarkedMessagesWithTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_MARKED_MESSAGES_WITH_TX)");
+		final HtmlTextInput deleteTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_TX)");
+		final HtmlTextInput deleteMarkedMessages = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_MARKED_MESSAGES)");
+		final HtmlTextInput deleteTemporaryMessages = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_TEMPORARY_MESSAGES)");
+		final HtmlTextInput deleteMessage = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_MESSAGE)");
+		final HtmlTextInput createMessageTable = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_MESSAGE_TABLE)");
+		final HtmlTextInput createIdxMessageTxopTxid = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_IDX_MESSAGE_TXOP_TXID)");
+		final HtmlTextInput createIdxMessageDestination = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_IDX_MESSAGE_DESTINATION)");
+		final HtmlTextInput createTxTable = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_TX_TABLE)");
+		final HtmlTextInput createTablesOnStartup = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_TABLES_ON_STARTUP)");
+	}
+
+	/**
+	 * Verify the provided page contains the expected input fields of the jms
+	 * "State SQL" page. Note that the value of the input fields are not
+	 * checked.
+	 * 
+	 * @param jmsPage
+	 *            The HtmlPage to be verified.
+	 * @throws Exception
+	 */
+	private void verifyUserSqlPage(HtmlPage stateSqlPage) throws Exception {
+		/*
+		 * Verify the SQL properties for state persistence are present:
+		 */
+		final HtmlForm form = stateSqlPage.getFormByName("jms");
+		final HtmlTextInput createTablesOnStartup = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(CREATE_TABLES_ON_STARTUP)");
+		final HtmlTextInput createUserTalbe = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(CREATE_USER_TABLE)");
+		final HtmlTextInput createRoleTable = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(CREATE_ROLE_TABLE)");
+		final HtmlTextInput createSubscriptionTable = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(CREATE_SUBSCRIPTION_TABLE)");
+		final HtmlTextInput getSubscription = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(GET_SUBSCRIPTION)");
+		final HtmlTextInput lockSubscription = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(LOCK_SUBSCRIPTION)");
+		final HtmlTextInput getSubscriptionsForTopic = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(GET_SUBSCRIPTIONS_FOR_TOPIC)");
+		final HtmlTextInput insertSubscription = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(INSERT_SUBSCRIPTION)");
+		final HtmlTextInput updateSubscription = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(UPDATE_SUBSCRIPTION)");
+		final HtmlTextInput removeSubscription = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(REMOVE_SUBSCRIPTION)");
+		final HtmlTextInput getUserByClientid = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(GET_USER_BY_CLIENTID)");
+		final HtmlTextInput getUser = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(GET_USER)");
+	}
+
+	/**
+	 * Restore the jms settings back to the saved values.
+	 * 
+	 * @param jmsPage
+	 *            The current jms page
+	 * @param savedJmsPage
+	 *            The jms page the values are to be restored from
+	 * @throws Exception
+	 */
+	private void restoreJmsSettings(HtmlPage jmsPage, HtmlPage savedJmsPage)
+			throws Exception {
+		/*
+		 * Get the current and saved jms forms:
+		 */
+		HtmlForm form = jmsPage.getFormByName("jms");
+		HtmlForm savedForm = savedJmsPage.getFormByName("jms");
+
+		/*
+		 * Restore the values from the saved form:
+		 */
+		HtmlTextInput defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		defaultTempQueueDownCacheSize.setValueAttribute(savedForm
+				.getInputByName("defaultTempQueueDownCacheSize").asText());
+
+		HtmlTextInput defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		defaultTempQueueFullSize.setValueAttribute(savedForm.getInputByName(
+				"defaultTempQueueFullSize").asText());
+
+		HtmlTextInput defaultTempQueuePageSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueuePageSize");
+		defaultTempQueuePageSize.setValueAttribute(savedForm.getInputByName(
+				"defaultTempQueuePageSize").asText());
+
+		HtmlTextInput prefetchSize = (HtmlTextInput) form
+				.getInputByName("prefetchSize");
+		prefetchSize.setValueAttribute(savedForm.getInputByName("prefetchSize")
+				.asText());
+
+		HtmlTextInput queuedExecutorPoolSize = (HtmlTextInput) form
+				.getInputByName("queuedExecutorPoolSize");
+		queuedExecutorPoolSize.setValueAttribute(savedForm.getInputByName(
+				"queuedExecutorPoolSize").asText());
+
+		HtmlTextInput securityDomain = (HtmlTextInput) form
+				.getInputByName("securityDomain");
+		securityDomain.setValueAttribute(savedForm.getInputByName(
+				"securityDomain").asText());
+
+		List textAreas = form.getTextAreasByName("defaultSecurityRoles");
+		List savedTextAreas = savedForm
+				.getTextAreasByName("defaultSecurityRoles");
+		HtmlTextArea defaultSecurityRoles = (HtmlTextArea) textAreas.get(0);
+		HtmlTextArea savedDefaultSecurityRoles = (HtmlTextArea) savedTextAreas
+				.get(0);
+		defaultSecurityRoles.setText(savedDefaultSecurityRoles.getText());
+
+		HtmlCheckBoxInput createMsgTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		createMsgTablesOnStartup.setChecked(savedForm.getInputByName(
+				"createMsgTablesOnStartup").isChecked());
+
+		HtmlCheckBoxInput usingBatchUpdates = (HtmlCheckBoxInput) form
+				.getInputByName("usingBatchUpdates");
+		usingBatchUpdates.setChecked(savedForm.getInputByName(
+				"usingBatchUpdates").isChecked());
+
+		HtmlCheckBoxInput createUserTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createUserTablesOnStartup");
+		createUserTablesOnStartup.setChecked(savedForm.getInputByName(
+				"createUserTablesOnStartup").isChecked());
+
+		/*
+		 * Click the "Save" button to submit the form:
+		 */
+		clickButton(form, SAVE_BUTTON);
+	}
+
+	/**
+	 * Create a local transactions data source with the specified name,
+	 * connection url, and driver class.
+	 * 
+	 * @param jndiName
+	 *            The jndi name of the data source
+	 * @param connectionUrl
+	 *            The connection url
+	 * @param driverClass
+	 *            The driver class
+	 * @throws Exception
+	 */
+	private void createDataSource(String jndiName, String connectionUrl,
+			String driverClass) throws Exception {
+		/*
+		 * Get the jms home page and click the "Local Transactions" link:
+		 */
+		HtmlPage homePage = (HtmlPage) webClient.getPage(adminUrl);
+		HtmlPage localTxPage = clickLink(homePage, HREF_DATASOURCE_LOCALTX);
+
+		/*
+		 * Click the "Create" button:
+		 */
+		HtmlForm identifierForm = localTxPage
+				.getFormByName("datasourceIdentifier");
+		HtmlPage createPage = clickButton(identifierForm, CREATE_BUTTON);
+
+		/*
+		 * Get the "datasource" form and fill in data for the required
+		 * attributes:
+		 */
+		HtmlForm datasourceForm = createPage.getFormByName("datasource");
+
+		HtmlTextInput htmlJndiName = (HtmlTextInput) datasourceForm
+				.getInputByName("JNDIname");
+		htmlJndiName.setValueAttribute(jndiName);
+
+		HtmlTextInput htmlConnectionUrl = (HtmlTextInput) datasourceForm
+				.getInputByName("connectionURL");
+		htmlConnectionUrl.setValueAttribute(connectionUrl);
+
+		HtmlTextInput htmlDriverClass = (HtmlTextInput) datasourceForm
+				.getInputByName("driverClassName");
+		htmlDriverClass.setValueAttribute(driverClass);
+
+		/*
+		 * Click the "Save" button to create the data source:
+		 */
+		clickButton(datasourceForm, SAVE_BUTTON);
+	}
+
+	/**
+	 * Remove the specified local transactions data source.
+	 * 
+	 * @param jndiName
+	 *            The jndi name of the data source
+	 * @throws Exception
+	 */
+	private void removeDataSource(String jndiName) throws Exception {
+		/*
+		 * Get the jms home page and click the "Local Transactions" link:
+		 */
+		HtmlPage homePage = (HtmlPage) webClient.getPage(adminUrl);
+		HtmlPage localTxPage = clickLink(homePage, HREF_DATASOURCE_LOCALTX);
+
+		/*
+		 * Get the dsTable and walk through the forms and table bodies to find
+		 * the row containing the data source we're looking for:
+		 */
+		HtmlForm form = null;
+		List bodies = null;
+		HtmlTableBody tBody = null;
+		List rows = null;
+		HtmlTableRow row = null;
+
+		HtmlTable table = (HtmlTable) localTxPage.getHtmlElementById("dsTable");
+		List forms = table.getHtmlElementsByTagName("form");
+		Iterator formIter = forms.iterator();
+
+		while (formIter.hasNext()) {
+			form = (HtmlForm) formIter.next();
+			bodies = form.getHtmlElementsByTagName("tbody");
+			assertEquals("Form should contain 1 <tbody>.", 1, bodies.size());
+
+			tBody = (HtmlTableBody) bodies.get(0);
+			rows = tBody.getRows();
+			assertEquals("<tbody> should contain 1 row.", 1, rows.size());
+
+			row = (HtmlTableRow) rows.get(0);
+			log.debug("name = " + row.getCell(0).asText());
+			if (jndiName.equals(row.getCell(0).asText())) {
+				/*
+				 * Found our row. Register a confirm handler to ok the remove
+				 * request:
+				 */
+				log.debug("found our row");
+				webClient.setConfirmHandler(new ConfirmHandlerImpl(true));
+
+				/*
+				 * Remove the data source and exit the loop:
+				 */
+				clickButton(form, REMOVE_BUTTON);
+				break;
+			}
+		}
+	}
+
+	/**
+	 * Test the action to view the jms page.
+	 * 
+	 * @throws Exception
+	 */
+	public void testViewJmsPage() throws Exception {
+		/*
+		 * Get the jms home page:
+		 */
+		HtmlPage homePage = (HtmlPage) webClient.getPage(adminUrl);
+
+		/*
+		 * Click the "Manage JBossMQ" link and verify the page content:
+		 */
+		HtmlPage jmsPage = clickLink(homePage, HREF_MANAGE_JBOSS_MESSAGING);
+		verifyJmsSettingsPage(jmsPage);
+	}
+
+	/**
+	 * Test the action to click various tabs from the jms "Settings" page.
+	 * 
+	 * @throws Exception
+	 */
+	public void testClickTabsFromJmsPage() throws Exception {
+		/*
+		 * Get the jms page:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+
+		/*
+		 * Click the "More" tab and verify the corrct page was obtained:
+		 */
+		HtmlPage morePage = clickLink(jmsPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+
+		/*
+		 * Click the "Message SQL" tab and verify the corrct page was obtained:
+		 */
+		HtmlPage msgSqlPage = clickLink(jmsPage, HREF_MSG_SQL_PAGE);
+		verifyMessageSqlPage(msgSqlPage);
+
+		/*
+		 * Click the "User SQL" tab and verify the corrct page was obtained:
+		 */
+		HtmlPage userSqlPage = clickLink(jmsPage, HREF_USER_SQL_PAGE);
+		verifyUserSqlPage(userSqlPage);
+	}
+
+	/**
+	 * Test the action to click various tabs from the jms "More" page.
+	 * 
+	 * @throws Exception
+	 */
+	public void testClickTabsFromMorePage() throws Exception {
+		/*
+		 * Get the "More" page:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlPage morePage = clickLink(jmsPage, HREF_MORE_PAGE);
+
+		/*
+		 * Click the "Settings" tab and verify the page:
+		 */
+		HtmlPage settingsPage = clickLink(morePage, HREF_SETTINGS_PAGE);
+		verifyJmsSettingsPage(settingsPage);
+
+		/*
+		 * Click the "Message SQL" tab and verify the page:
+		 */
+		HtmlPage msgSqlPage = clickLink(morePage, HREF_MSG_SQL_PAGE);
+		verifyMessageSqlPage(msgSqlPage);
+
+		/*
+		 * Click the "User SQL" tab and verify the page:
+		 */
+		HtmlPage userSqlPage = clickLink(morePage, HREF_USER_SQL_PAGE);
+		verifyUserSqlPage(userSqlPage);
+	}
+
+	/**
+	 * Test the action to click various tabs from the jms "Message SQL" page.
+	 * 
+	 * @throws Exception
+	 */
+	public void testClickTabsFromMessageSqlPage() throws Exception {
+		/*
+		 * Get the "Message SQL" page:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlPage msgSqlPage = clickLink(jmsPage, HREF_MSG_SQL_PAGE);
+
+		/*
+		 * Click the "Settings" tab and verify the page:
+		 */
+		HtmlPage settingsPage = clickLink(msgSqlPage, HREF_SETTINGS_PAGE);
+		verifyJmsSettingsPage(settingsPage);
+
+		/*
+		 * Click the "More" tab and verify the page:
+		 */
+		HtmlPage morePage = clickLink(msgSqlPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+
+		/*
+		 * Click the "User SQL" tab and verify the page:
+		 */
+		HtmlPage userSqlPage = clickLink(msgSqlPage, HREF_USER_SQL_PAGE);
+		verifyUserSqlPage(userSqlPage);
+	}
+
+	/**
+	 * Test the action to click various tabs from the jms "User SQL" page.
+	 * 
+	 * @throws Exception
+	 */
+	public void testClickTabsFromUserSqlPage() throws Exception {
+		/*
+		 * Get the "State SQL" page:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlPage userSqlPage = clickLink(jmsPage, HREF_USER_SQL_PAGE);
+
+		/*
+		 * Click the "Settings" tab and verify the page:
+		 */
+		HtmlPage settingsPage = clickLink(userSqlPage, HREF_SETTINGS_PAGE);
+		verifyJmsSettingsPage(settingsPage);
+
+		/*
+		 * Click the "More" tab and verify the page:
+		 */
+		HtmlPage morePage = clickLink(userSqlPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+
+		/*
+		 * Click the "Message SQL" tab and verify the page:
+		 */
+		HtmlPage msgSqlPage = clickLink(userSqlPage, HREF_MSG_SQL_PAGE);
+		verifyMessageSqlPage(msgSqlPage);
+	}
+
+	/**
+	 * Test the action to update the jms attributes with invalid type of data.
+	 * 
+	 * @throws Exception
+	 */
+	public void testUpdateJmsAttributesWithInvalidDataType() throws Exception {
+		/*
+		 * Get the jms page & form:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlForm form = jmsPage.getFormByName("jms");
+
+		/*
+		 * Assign invalid type of data to the attributes:
+		 */
+		String badData = "badData";
+		HtmlTextInput defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		defaultTempQueueDownCacheSize.setValueAttribute(badData);
+
+		HtmlTextInput defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		defaultTempQueueFullSize.setValueAttribute(badData);
+
+		HtmlTextInput defaultTempQueuePageSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueuePageSize");
+		defaultTempQueuePageSize.setValueAttribute(badData);
+
+		HtmlTextInput prefetchSize = (HtmlTextInput) form
+				.getInputByName("prefetchSize");
+		prefetchSize.setValueAttribute(badData);
+
+		HtmlTextInput queuedExecutorPoolSize = (HtmlTextInput) form
+				.getInputByName("queuedExecutorPoolSize");
+		queuedExecutorPoolSize.setValueAttribute(badData);
+
+		/*
+		 * Click the "Save" button and verify the error messages were returned
+		 * correctly:
+		 */
+		jmsPage = clickButton(form, SAVE_BUTTON);
+		String jmsPageText = jmsPage.asText();
+
+		String expectedMsg = msgProps
+				.getProperty("jms.view.defaultTempQueueDownCacheSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(jmsPageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("jms.view.defaultTempQueueFullSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(jmsPageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("jms.view.defaultTempQueuePageSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(jmsPageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("jms.view.prefetchSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(jmsPageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("jms.view.queuedExecutorPoolSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(jmsPageText, expectedMsg));
+	}
+
+	/**
+	 * Test the action to cancel the jms attribute changes.
+	 * 
+	 * @throws Exception
+	 */
+	public void testCancelJmsAttributeChanges() throws Exception {
+		/*
+		 * Get the jms page & form:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlForm form = jmsPage.getFormByName("jms");
+
+		/*
+		 * Change the values of some attributes:
+		 */
+		HtmlTextInput defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		String savedDefaultTempQueueDownCacheSize = defaultTempQueueDownCacheSize
+				.asText();
+		defaultTempQueueDownCacheSize.setValueAttribute("1000");
+
+		HtmlTextInput defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		String savedDefaultTempQueueFullSize = defaultTempQueueFullSize
+				.asText();
+		defaultTempQueueFullSize.setValueAttribute("50000");
+
+		HtmlTextInput prefetchSize = (HtmlTextInput) form
+				.getInputByName("prefetchSize");
+		String savedPrefetchSize = prefetchSize.asText();
+		prefetchSize.setValueAttribute("100");
+
+		/*
+		 * Click the "Cancel" button and make sure the previous settings were
+		 * retained:
+		 */
+		jmsPage = clickButton(form, CANCEL_BUTTON);
+		form = jmsPage.getFormByName("jms");
+
+		defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		assertEquals(savedDefaultTempQueueDownCacheSize,
+				defaultTempQueueDownCacheSize.asText());
+
+		defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		assertEquals(savedDefaultTempQueueFullSize, defaultTempQueueFullSize
+				.asText());
+
+		prefetchSize = (HtmlTextInput) form.getInputByName("prefetchSize");
+		assertEquals(savedPrefetchSize, prefetchSize.asText());
+	}
+
+	/**
+	 * Test the action to update the jms attributes on the "Settings" page. All
+	 * attributes on the "Settings" page are modified except for the data
+	 * source, which will be tested in the testChangeDataSource() test case.
+	 * 
+	 * @throws Exception
+	 */
+	public void testUpdateJmsAttributesOnSettingsPage() throws Exception {
+		/*
+		 * Get the jms page & form and save a copy of the settings:
+		 */
+		HtmlPage savedJmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlForm form = jmsPage.getFormByName("jms");
+
+		/*
+		 * Assign new values to the attributes:
+		 */
+		HtmlTextInput defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		defaultTempQueueDownCacheSize.setValueAttribute("1000");
+
+		HtmlTextInput defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		defaultTempQueueFullSize.setValueAttribute("50000");
+
+		HtmlTextInput defaultTempQueuePageSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueuePageSize");
+		defaultTempQueuePageSize.setValueAttribute("1000");
+
+		HtmlTextInput prefetchSize = (HtmlTextInput) form
+				.getInputByName("prefetchSize");
+		prefetchSize.setValueAttribute("80");
+
+		HtmlTextInput queuedExecutorPoolSize = (HtmlTextInput) form
+				.getInputByName("queuedExecutorPoolSize");
+		queuedExecutorPoolSize.setValueAttribute("100");
+
+		HtmlTextInput securityDomain = (HtmlTextInput) form
+				.getInputByName("securityDomain");
+		securityDomain.setValueAttribute("java:/jaas/rmi-ssl");
+
+		List textAreas = form.getTextAreasByName("defaultSecurityRoles");
+		HtmlTextArea defaultSecurityRoles = (HtmlTextArea) textAreas.get(0);
+		String role1 = "test1:read:write";
+		String role2 = "test2:read:write:create";
+		defaultSecurityRoles.setText(role1 + NL + role2);
+
+		HtmlCheckBoxInput createMsgTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		createMsgTablesOnStartup.setChecked(false);
+
+		HtmlCheckBoxInput usingBatchUpdates = (HtmlCheckBoxInput) form
+				.getInputByName("usingBatchUpdates");
+		usingBatchUpdates.setChecked(true);
+
+		HtmlCheckBoxInput createUserTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createUserTablesOnStartup");
+		createUserTablesOnStartup.setChecked(true);
+
+		/*
+		 * Click the "Save" button to submit the changes:
+		 */
+		clickButton(form, SAVE_BUTTON);
+
+		/*
+		 * Sleep for a few seconds then get the jms page again and verify the
+		 * changes:
+		 */
+		Thread.sleep(hotDeployWaitTime * 2);
+		jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		form = jmsPage.getFormByName("jms");
+		defaultTempQueueDownCacheSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueDownCacheSize");
+		assertEquals("1000", defaultTempQueueDownCacheSize.asText());
+
+		defaultTempQueueFullSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueueFullSize");
+		assertEquals("50000", defaultTempQueueFullSize.asText());
+
+		defaultTempQueuePageSize = (HtmlTextInput) form
+				.getInputByName("defaultTempQueuePageSize");
+		assertEquals("1000", defaultTempQueuePageSize.asText());
+
+		prefetchSize = (HtmlTextInput) form.getInputByName("prefetchSize");
+		assertEquals("80", prefetchSize.asText());
+
+		queuedExecutorPoolSize = (HtmlTextInput) form
+				.getInputByName("queuedExecutorPoolSize");
+		assertEquals("100", queuedExecutorPoolSize.asText());
+
+		securityDomain = (HtmlTextInput) form.getInputByName("securityDomain");
+		assertEquals("java:/jaas/rmi-ssl", securityDomain.asText());
+
+		textAreas = form.getTextAreasByName("defaultSecurityRoles");
+		defaultSecurityRoles = (HtmlTextArea) textAreas.get(0);
+		assertEquals("2", defaultSecurityRoles.getRowsAttribute());
+		// HtmlTextArea.getText() converts "\r\n" to "\n" so the expected
+		// string must be build accordingly.
+		assertEquals(role1 + "\n" + role2, defaultSecurityRoles.getText()
+				.trim());
+
+		createMsgTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		assertFalse(ITEM_NOT_CHECKED, createMsgTablesOnStartup.isChecked());
+
+		usingBatchUpdates = (HtmlCheckBoxInput) form
+				.getInputByName("usingBatchUpdates");
+		assertTrue(ITEM_CHECKED, usingBatchUpdates.isChecked());
+
+		createUserTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createUserTablesOnStartup");
+		assertTrue(ITEM_NOT_CHECKED, createUserTablesOnStartup.isChecked());
+
+		/*
+		 * Restore the previous settings:
+		 */
+		restoreJmsSettings(jmsPage, savedJmsPage);
+
+		/*
+		 * Sleep for a few seconds for the changes to take effect before
+		 * starting the next test:
+		 */
+		Thread.sleep(hotDeployWaitTime * 2);
+	}
+
+	/**
+	 * Test the action to update the jms attributes on "Settings", "Message
+	 * SQL", and "User SQL" pages. Only selected attributes on each page are
+	 * updated.
+	 * 
+	 * @throws Exception
+	 */
+	public void testUpdateJmsAttributesOnMultiplePages() throws Exception {
+		/*
+		 * Get the jms page & form:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlForm form = jmsPage.getFormByName("jms");
+
+		/*
+		 * Change some attribute values on the "Settings" page, make sure all
+		 * check boxes are checked:
+		 */
+		HtmlTextInput prefetchSize = (HtmlTextInput) form
+				.getInputByName("prefetchSize");
+		prefetchSize.setValueAttribute("80");
+
+		HtmlCheckBoxInput createMsgTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		createMsgTablesOnStartup.setChecked(true);
+
+		HtmlCheckBoxInput usingBatchUpdates = (HtmlCheckBoxInput) form
+				.getInputByName("usingBatchUpdates");
+		usingBatchUpdates.setChecked(true);
+
+		HtmlCheckBoxInput createUserTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createUserTablesOnStartup");
+		createUserTablesOnStartup.setChecked(true);
+
+		/*
+		 * Switch to the "Message SQL" tab and verify the check box values are
+		 * retained as hidden attribues:
+		 */
+		HtmlPage msgSqlPage = clickLink(jmsPage, HREF_MSG_SQL_PAGE);
+		form = msgSqlPage.getFormByName("jms");
+
+		HtmlHiddenInput hiddenCreateMsgTablesOnStartup = (HtmlHiddenInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		assertEquals("on", hiddenCreateMsgTablesOnStartup.asText());
+
+		HtmlHiddenInput hiddenUsingBatchUpdates = (HtmlHiddenInput) form
+				.getInputByName("usingBatchUpdates");
+		assertEquals("on", hiddenUsingBatchUpdates.asText());
+
+		HtmlHiddenInput hiddenCreateUserTablesOnStartup = (HtmlHiddenInput) form
+				.getInputByName("createUserTablesOnStartup");
+		assertEquals("on", hiddenCreateUserTablesOnStartup.asText());
+
+		/*
+		 * TODO: Change some "Message SQL" property values:
+		 */
+		HtmlTextInput blobType = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(BLOB_TYPE)");
+		String savedBlobType = blobType.asText();
+		blobType.setValueAttribute("TEST_BLOB");
+
+		HtmlTextInput createTablesOnStartup = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_TABLES_ON_STARTUP)");
+		String savedCreateTablesOnStartup = createTablesOnStartup.asText();
+		createTablesOnStartup.setValueAttribute("TEST_VALUE");
+
+		/*
+		 * TODO: Switch to the "User SQL" tab and change some property values:
+		 */
+		HtmlPage userSqlPage = clickLink(msgSqlPage, HREF_USER_SQL_PAGE);
+		form = userSqlPage.getFormByName("jms");
+
+		HtmlTextInput getUser = (HtmlTextInput) form
+				.getInputByName("stateSqlMap(GET_USER)");
+		String savedGetUser = getUser.asText();
+		getUser.setValueAttribute("SOME SELECT STATEMENTS");
+
+		/*
+		 * Return to the "Settings" tab and save the changes:
+		 */
+		jmsPage = clickLink(userSqlPage, HREF_SETTINGS_PAGE);
+		form = jmsPage.getFormByName("jms");
+		clickButton(form, SAVE_BUTTON);
+
+		/*
+		 * Sleep for a few seconds then get the jms page again and verify the
+		 * changes:
+		 */
+		Thread.sleep(hotDeployWaitTime * 3);
+		jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		form = jmsPage.getFormByName("jms");
+
+		prefetchSize = (HtmlTextInput) form.getInputByName("prefetchSize");
+		assertEquals("80", prefetchSize.asText());
+
+		createMsgTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createMsgTablesOnStartup");
+		assertTrue(ITEM_NOT_CHECKED, createMsgTablesOnStartup.isChecked());
+
+		usingBatchUpdates = (HtmlCheckBoxInput) form
+				.getInputByName("usingBatchUpdates");
+		assertTrue(ITEM_NOT_CHECKED, usingBatchUpdates.isChecked());
+
+		createUserTablesOnStartup = (HtmlCheckBoxInput) form
+				.getInputByName("createUserTablesOnStartup");
+		assertTrue(ITEM_NOT_CHECKED, createUserTablesOnStartup.isChecked());
+
+		/*
+		 * TODO: Switch to the "Message SQL" tab and verify the changes:
+		 */
+		msgSqlPage = clickLink(jmsPage, HREF_MSG_SQL_PAGE);
+		form = msgSqlPage.getFormByName("jms");
+
+		blobType = (HtmlTextInput) form.getInputByName("msgSqlMap(BLOB_TYPE)");
+		assertEquals("TEST_BLOB", blobType.asText());
+
+		createTablesOnStartup = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_TABLES_ON_STARTUP)");
+		assertEquals("TEST_VALUE", createTablesOnStartup.asText());
+
+		/*
+		 * Restore the "Message SQL" property values:
+		 */
+		blobType.setValueAttribute(savedBlobType);
+		createTablesOnStartup.setValueAttribute(savedCreateTablesOnStartup);
+
+		/*
+		 * Switch to the "User SQL" tab and verify the changes:
+		 */
+		userSqlPage = clickLink(msgSqlPage, HREF_USER_SQL_PAGE);
+		form = userSqlPage.getFormByName("jms");
+
+		getUser = (HtmlTextInput) form.getInputByName("stateSqlMap(GET_USER)");
+		assertEquals("SOME SELECT STATEMENTS", getUser.asText());
+
+		/*
+		 * Restore the "User SQL" property value:
+		 */
+		getUser.setValueAttribute(savedGetUser);
+
+		/*
+		 * Return to the "Settings" tab and save the restored values:
+		 */
+		jmsPage = clickLink(userSqlPage, HREF_SETTINGS_PAGE);
+		form = jmsPage.getFormByName("jms");
+		clickButton(form, SAVE_BUTTON);
+
+		/*
+		 * Sleep for a few seconds for the changes to take effect:
+		 */
+		Thread.sleep(hotDeployWaitTime * 3);
+	}
+
+	/**
+	 * Test the action to select a different data source from the "Settings"
+	 * page. This test verifies when a postgres data source is selected, the
+	 * proper SQL properties are loaded from the properties file. However the
+	 * changes will not be saved. So even though there's no postgres database
+	 * existed on the system, the test won't cause any exception.
+	 * 
+	 * @throws Exception
+	 */
+	public void testChangeDataSource() throws Exception {
+		String postgresDataSourceName = "postgresDS";
+		String postgresConnectionUrl = "jdbc:postgresql://localhost:5432/myPostgreDB";
+		String postgresDriverClass = "org.postgresql.Driver";
+
+		/*
+		 * Create a postgres data source and wait for it to get deployed:
+		 */
+		createDataSource(postgresDataSourceName, postgresConnectionUrl,
+				postgresDriverClass);
+		Thread.sleep(hotDeployWaitTime * 2);
+
+		/*
+		 * Load the persistenceSql.properties into memory:
+		 */
+		Properties sqlProps = loadProperties(persistSqlFile);
+
+		/*
+		 * Get the jms page & form:
+		 */
+		HtmlPage jmsPage = (HtmlPage) webClient.getPage(jmsUrl);
+		HtmlForm form = jmsPage.getFormByName("jms");
+
+		/*
+		 * Select the new postgres data source from the drop down list:
+		 */
+		HtmlSelect dataSourceName = (HtmlSelect) form
+				.getSelectByName("dataSourceName");
+		List dataSourceOptions = dataSourceName.getOptions();
+		HtmlOption option;
+		for (int i = 0; i < dataSourceOptions.size(); i++) {
+			option = (HtmlOption) dataSourceOptions.get(i);
+			if (postgresDataSourceName.equals(option.getValueAttribute())) {
+				jmsPage = (HtmlPage) option.setSelected(true);
+				break;
+			}
+		}
+
+		/*
+		 * Switch to the "Message SQL" tab and verify the SQL properties for
+		 * postgres DB are loaded correctly. Only the property values that're
+		 * unique to postgres DB are checked:
+		 */
+		HtmlPage msgSqlPage = clickLink(jmsPage, HREF_MSG_SQL_PAGE);
+		form = msgSqlPage.getFormByName("jms");
+
+		String expectedBlobType = sqlProps.getProperty("postgre.msg.BLOB_TYPE");
+		HtmlTextInput blobType = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(BLOB_TYPE)");
+		assertEquals(expectedBlobType, blobType.asText());
+
+		String expectedSelectMaxTx = sqlProps
+				.getProperty("postgre.msg.SELECT_MAX_TX");
+		HtmlTextInput selectMaxTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(SELECT_MAX_TX)");
+		assertEquals(expectedSelectMaxTx, selectMaxTx.asText());
+
+		String expectedDeleteMarkedMsgsWithTx = sqlProps
+				.getProperty("postgre.msg.DELETE_MARKED_MESSAGES_WITH_TX");
+		HtmlTextInput deleteMarkedMsgsWithTx = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(DELETE_MARKED_MESSAGES_WITH_TX)");
+		assertEquals(expectedDeleteMarkedMsgsWithTx, deleteMarkedMsgsWithTx
+				.asText());
+
+		String expectedCreateMessageTable = sqlProps
+				.getProperty("postgre.msg.CREATE_MESSAGE_TABLE");
+		HtmlTextInput createMessageTable = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_MESSAGE_TABLE)");
+		assertEquals(expectedCreateMessageTable, createMessageTable.asText());
+
+		String expectedCreateTxTable = sqlProps
+				.getProperty("postgre.msg.CREATE_TX_TABLE");
+		HtmlTextInput createTxTable = (HtmlTextInput) form
+				.getInputByName("msgSqlMap(CREATE_TX_TABLE)");
+		assertEquals(expectedCreateTxTable, createTxTable.asText());
+
+		/*
+		 * Remove the postgres data source and wait for it to get undeployed:
+		 */
+		removeDataSource(postgresDataSourceName);
+		Thread.sleep(hotDeployWaitTime * 2);
+	}
+}
\ No newline at end of file

Added: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsQueueTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsQueueTest.java	                        (rev 0)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsQueueTest.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -0,0 +1,720 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.admin.console.webtest;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
+import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+/**
+ * Integration tests for managing JBoss Messaging's destination queue.
+ * 
+ * @author <a href="chi.lin at unisys.com">Chi Lin </a>
+ * @version $Revision: 59929 $
+ */
+public class JmsQueueTest extends JmsDestinationTestCase {
+
+	private static Log log = LogFactory.getLog(JmsQueueTest.class);
+
+	private final static String DESTINATION_QUEUE = "queue";
+
+	private final static String TEST_QUEUE = "testQueue1";
+
+	private final static String TEST_QUEUE_JNDI_NAME = "queue/" + TEST_QUEUE;
+
+	public JmsQueueTest(String arg0) throws Exception {
+		super(arg0);
+
+		/*
+		 * Remove the test queue if it already exists:
+		 */
+		removeDestination(DESTINATION_QUEUE, TEST_QUEUE, true);
+	}
+
+	/**
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/**
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Listens for a TextMessage from the test queue Asynchronously.
+	 */
+	class ReceiveMessageFromQueueAsync {
+		InitialContext ctx;
+
+		QueueConnectionFactory cf;
+
+		QueueConnection connection;
+
+		QueueSession session;
+
+		Queue destination;
+
+		QueueReceiver receiver;
+
+		public void run() throws NamingException, JMSException {
+			ctx = getInitialContext();
+			cf = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+			destination = (Queue) ctx.lookup(TEST_QUEUE_JNDI_NAME);
+
+			connection = cf.createQueueConnection();
+			session = connection.createQueueSession(false,
+					Session.AUTO_ACKNOWLEDGE);
+			receiver = session.createReceiver(destination);
+			receiver.setMessageListener(new MyMessageListener());
+
+			// Waiting for a message:
+			connection.start();
+		}
+
+		class MyMessageListener implements MessageListener {
+
+			public void onMessage(Message msg) {
+				try {
+					TextMessage message = (TextMessage) msg;
+					// Message received, we're done.
+					connection.close();
+				} catch (JMSException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+	}
+
+	/**
+	 * Sends a TextMessage, a MapMessage, and a ByteMessage to the test queue.
+	 * 
+	 * @throws NamingException
+	 * @throws JMSException
+	 */
+	private void sendMessagesToQueue() throws NamingException, JMSException {
+		InitialContext ctx;
+		QueueConnectionFactory cf;
+		QueueConnection connection;
+		QueueSession session;
+		Queue destination;
+		QueueSender sender;
+
+		ctx = getInitialContext();
+		cf = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+		destination = (Queue) ctx.lookup(TEST_QUEUE_JNDI_NAME);
+
+		connection = cf.createQueueConnection();
+		session = connection
+				.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+		sender = session.createSender(destination);
+
+		// send a TextMessage:
+		TextMessage message = session.createTextMessage();
+		message.setText("Hello World!");
+		sender.send(message);
+
+		// send a MapMessage:
+		MapMessage mMsg = session.createMapMessage();
+		mMsg.setBoolean("myBoolean", true);
+		mMsg.setInt("myInt", 11);
+		sender.send(mMsg);
+
+		// send a ByteMessage:
+		BytesMessage bMsg = session.createBytesMessage();
+		bMsg.writeBoolean(true);
+		bMsg.writeChar('a');
+		bMsg.writeInt(88);
+		sender.send(bMsg);
+
+		connection.close();
+	}
+
+	/**
+	 * Verify the provided page contains the expected input fields of the "More"
+	 * page of a queue. The value of the input fields are not checked.
+	 * 
+	 * @param page
+	 *            The page to be verified
+	 * @throws Exception
+	 */
+	private void verifyMorePage(HtmlPage page) throws Exception {
+		/*
+		 * Get the destTable and verify it is not empty:
+		 */
+		final HtmlTable table = (HtmlTable) page
+				.getHtmlElementById("destTable");
+		final List rows = table.getRows();
+		assertFalse(TABLE_EMPTY, rows.isEmpty());
+
+		/*
+		 * Verify correct labels exist in the table:
+		 */
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("destination.view.messageCount"), table.getCellAt(
+				0, 0).asText());
+
+		/*
+		 * Verify the data column of each row is not null:
+		 */
+		HtmlTableRow row = null;
+		for (int i = 0; i < rows.size(); i++) {
+			row = (HtmlTableRow) rows.get(i);
+			assertNotNull("Null data in table, row = " + i, row.getCell(1));
+		}
+	}
+
+	/**
+	 * Test creating a destination queue with a bad name.
+	 * 
+	 * @throws Exception
+	 */
+	private void createQueueWithBadName() throws Exception {
+		/*
+		 * Build an attributes map with a bad name attribute:
+		 */
+		Map attMap = new HashMap();
+		attMap.put("name", "bad!Queue");
+
+		/*
+		 * Create the queue and verify the returned error message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_QUEUE, attMap);
+		String expectedMsg = msgProps.getProperty("destination.create.failure");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+	}
+
+	/**
+	 * Test creating a destination queue without providing the required
+	 * information (the name).
+	 * 
+	 * @throws Exception
+	 */
+	private void createQueueWithMissingRequiredData() throws Exception {
+		/*
+		 * Create a queue with an empty attribute map and verify the returned
+		 * error message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_QUEUE, new HashMap());
+		String expectedMsg = msgProps.getProperty("destination.view.name")
+				+ " is required";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+	}
+
+	/**
+	 * Test creating a destination queue providing the minimum required data.
+	 * The queue created by this test will be used by other test cases in this
+	 * suite.
+	 * 
+	 * @throws Exception
+	 */
+	private void createQueue() throws Exception {
+		/*
+		 * Find out the number of existing queues:
+		 */
+		int prevQueueNo = getNumberOfDestinations(DESTINATION_QUEUE);
+		log.debug("prevQueueNo = " + prevQueueNo);
+
+		/*
+		 * Build a map containing minimum attributes needed to create the queue:
+		 */
+		Map attMap = new HashMap();
+		attMap.put("name", TEST_QUEUE);
+
+		/*
+		 * Create the queue and verify the success message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_QUEUE, attMap);
+		String expectedMsg = msgProps.getProperty("destination.create.success");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+
+		/*
+		 * Wait for a few seconds then refresh the list (for a maximum of 3
+		 * times) and verify the number of queues is incremented by 1:
+		 */
+		boolean queueCreated = false;
+		for (int i = 0; i < 3; i++) {
+			Thread.sleep(hotDeployWaitTime);
+			listPage = refreshPage(listPage);
+			int queueNo = getNumberOfDestinations(listPage);
+			log.debug("queueNo = " + queueNo);
+			if (queueNo == prevQueueNo + 1) {
+				queueCreated = true;
+				break;
+			}
+		}
+		assertTrue("Queue not created", queueCreated);
+
+		/*
+		 * Make sure we can get the newly created queue:
+		 */
+		HtmlForm form = getDestinationEntryFromList(listPage, TEST_QUEUE);
+		assertNotNull("Can't find the newly created queue", form);
+	}
+
+	/**
+	 * Test creating a queue using a name that already exists.
+	 * 
+	 * @throws Exception
+	 */
+	private void createQueueWithDuplicateName() throws Exception {
+		/*
+		 * Build an attributes map containing duplicate queue name:
+		 */
+		Map attMap = new HashMap();
+		attMap.put("name", TEST_QUEUE);
+
+		/*
+		 * Create the queue and verify the returned error message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_QUEUE, attMap);
+		String expectedMsg = msgProps.getProperty("destination.create.failure");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+	}
+
+	/**
+	 * Test the action to view a queue.
+	 * 
+	 * @throws Exception
+	 */
+	private void viewQueue() throws Exception {
+		/*
+		 * Click the "View" button of the test queue and verify the correct page
+		 * was obtained:
+		 */
+		HtmlPage destPage = getDestinationDetailPage(DESTINATION_QUEUE,
+				TEST_QUEUE);
+		verifySettingsPage(destPage);
+
+		/*
+		 * Click the "More" tab and verify the page:
+		 */
+		HtmlPage morePage = clickLink(destPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+	}
+
+	/**
+	 * Test various actions related to managing the messages in the destination
+	 * queue.
+	 * 
+	 * @throws Exception
+	 */
+	private void viewDataActions() throws Exception {
+		/*
+		 * Send 3 messages to the test queue:
+		 */
+		sendMessagesToQueue();
+
+		/*
+		 * Get the "View Data" page of the test queue and verify there's one
+		 * message statistics entry and the message count is 3:
+		 */
+		HtmlPage dataPage = getViewDataPage(DESTINATION_QUEUE, TEST_QUEUE);
+		// verifyMessageStatisticsPage(dataPage, DESTINATION_QUEUE, TEST_QUEUE,
+		// 1,
+		// 1, 3);
+
+		/*
+		 * Click the "Reset Message Counter" button and verify the message count
+		 * becomes 0:
+		 */
+		HtmlForm form = dataPage.getFormByName("destinationIdentifier");
+		// dataPage = clickButton(form, RESET_MSG_COUNTER_BUTTON);
+		// verifyMessageStatisticsPage(dataPage, DESTINATION_QUEUE, TEST_QUEUE,
+		// 1,
+		// 1, 0);
+
+		/*
+		 * Switch to the "Messages" tab and verify the page heading:
+		 */
+		// dataPage = clickLink(dataPage, HREF_MESSAGES_PAGE);
+		String expectedMsg = "Destination Messages: " + DESTINATION_QUEUE + "/"
+				+ TEST_QUEUE;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Verify the three types of messages we just sent were reported
+		 * correctly:
+		 */
+		expectedMsg = "javax.jms.TextMessage";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+		expectedMsg = "javax.jms.MapMessage";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+		expectedMsg = "javax.jms.BytesMessage";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Click the "Remove All Messages" button and verify the result:
+		 */
+		form = dataPage.getFormByName("destinationIdentifier");
+		dataPage = clickButton(form, REMOVE_ALL_MESSAGES_BUTTON);
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.queueMessages.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Start a receiver, then switch to the "Receivers" tab and verify the
+		 * page heading:
+		 */
+		ReceiveMessageFromQueueAsync receiver = new ReceiveMessageFromQueueAsync();
+		receiver.run();
+		dataPage = clickLink(dataPage, HREF_RECEIVERS_PAGE);
+		expectedMsg = "Receivers: " + DESTINATION_QUEUE + "/" + TEST_QUEUE;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Verify the "Receivers" page reports one receiver:
+		 */
+		HtmlTable table = (HtmlTable) dataPage
+				.getHtmlElementById("receiversTable");
+		assertEquals(1, table.getBodies().size());
+
+		/*
+		 * Switch to the "Message Counter History" tab and verify the page
+		 * heading. Note that since the message counter history report comes
+		 * directly from the MBean method, no further validation is performed
+		 * here until the message counter history implementation is changed:
+		 */
+		dataPage = clickLink(dataPage, HREF_MSG_COUNTER_HISTORY_PAGE);
+		expectedMsg = "Message Counter History: " + DESTINATION_QUEUE + "/"
+				+ TEST_QUEUE;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Click the "Reset Message Counter History" button and verify it
+		 * returns to the same page:
+		 */
+		form = dataPage.getFormByName("destinationIdentifier");
+		dataPage = clickButton(form, RESET_MSG_COUNTER_HISTORY_BUTTON);
+		expectedMsg = "Message Counter History: " + DESTINATION_QUEUE + "/"
+				+ TEST_QUEUE;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+	}
+
+	/**
+	 * Test the action to change some queue attributes and cancel the request.
+	 * 
+	 * @throws Exception
+	 */
+	private void cancelQueueAttributeChanges() throws Exception {
+		/*
+		 * Get the "View" page of the test queue:
+		 */
+		HtmlPage page = getDestinationDetailPage(DESTINATION_QUEUE, TEST_QUEUE);
+
+		/*
+		 * Save old value and assign new one to some selected attributes:
+		 */
+		HtmlForm form = page.getFormByName("destination");
+		HtmlTextInput downCacheSize = (HtmlTextInput) form
+				.getInputByName("downCacheSize");
+		String savedDownCacheSize = downCacheSize.asText();
+		downCacheSize.setValueAttribute("3000");
+
+		HtmlTextInput fullSize = (HtmlTextInput) form
+				.getInputByName("fullSize");
+		String savedFullSize = fullSize.asText();
+		fullSize.setValueAttribute("60000");
+
+		HtmlTextInput pageSize = (HtmlTextInput) form
+				.getInputByName("pageSize");
+		String savedPageSize = pageSize.asText();
+		pageSize.setValueAttribute("3000");
+
+		/*
+		 * Click the "Cancel" button and verify the list page is displayed:
+		 */
+		HtmlPage newPage = clickButton(form, CANCEL_BUTTON);
+		String expectedMsg = msgProps
+				.getProperty("destination.list.destinations.page.header");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(newPage, expectedMsg));
+
+		/*
+		 * Wait for a couple of seconds then view the queue to verify the
+		 * previous settings were retained:
+		 */
+		Thread.sleep(hotDeployWaitTime);
+		page = getDestinationDetailPage(DESTINATION_QUEUE, TEST_QUEUE);
+		form = page.getFormByName("destination");
+
+		downCacheSize = (HtmlTextInput) form.getInputByName("downCacheSize");
+		assertEquals(savedDownCacheSize, downCacheSize.asText());
+
+		fullSize = (HtmlTextInput) form.getInputByName("fullSize");
+		assertEquals(savedFullSize, fullSize.asText());
+
+		pageSize = (HtmlTextInput) form.getInputByName("pageSize");
+		assertEquals(savedPageSize, pageSize.asText());
+	}
+
+	/**
+	 * Test updating a destination queue with invalid data.
+	 * 
+	 * @throws Exception
+	 */
+	private void updateQueueWithInvalidData() throws Exception {
+		/*
+		 * Get the "View" page of the test queue:
+		 */
+		HtmlPage destPage = getDestinationDetailPage(DESTINATION_QUEUE,
+				TEST_QUEUE);
+		HtmlForm destForm = destPage.getFormByName("destination");
+
+		/*
+		 * Enter text into integer fields:
+		 */
+		String badInt = "badInt";
+		HtmlTextInput downCacheSize = (HtmlTextInput) destForm
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute(badInt);
+
+		HtmlTextInput fullSize = (HtmlTextInput) destForm
+				.getInputByName("fullSize");
+		fullSize.setValueAttribute(badInt);
+
+		HtmlTextInput pageSize = (HtmlTextInput) destForm
+				.getInputByName("pageSize");
+		pageSize.setValueAttribute(badInt);
+
+		/*
+		 * Switching tab will trigger data validation too. So instead of saving
+		 * the changes, we'll simply click the "More" tab and verify the
+		 * returned error message:
+		 */
+		destPage = clickLink(destPage, HREF_MORE_PAGE);
+		String pageText = destPage.asText();
+		String expectedMsg = msgProps
+				.getProperty("destination.view.downCacheSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("destination.view.fullSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("destination.view.pageSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		/*
+		 * Set pageSize smaller than downCacheSize and click the "More" tab to
+		 * verify an error is reported:
+		 */
+		destForm = destPage.getFormByName("destination");
+
+		downCacheSize = (HtmlTextInput) destForm
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute("3000");
+
+		fullSize = (HtmlTextInput) destForm.getInputByName("fullSize");
+		fullSize.setValueAttribute("75000");
+
+		pageSize = (HtmlTextInput) destForm.getInputByName("pageSize");
+		pageSize.setValueAttribute("2000");
+
+		destPage = clickLink(destPage, HREF_MORE_PAGE);
+		pageText = destPage.asText();
+		expectedMsg = msgProps
+				.getProperty("destination.error.pageSizeTooSmall");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		/*
+		 * Fix the data then click the "More" tab again. It should work this
+		 * time:
+		 */
+		destForm = destPage.getFormByName("destination");
+
+		downCacheSize = (HtmlTextInput) destForm
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute("3000");
+
+		fullSize = (HtmlTextInput) destForm.getInputByName("fullSize");
+		fullSize.setValueAttribute("60000");
+
+		pageSize = (HtmlTextInput) destForm.getInputByName("pageSize");
+		pageSize.setValueAttribute("4000");
+
+		HtmlPage morePage = clickLink(destPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+	}
+
+	/**
+	 * Test the action to update the attributes of a queue.
+	 * 
+	 * @throws Exception
+	 */
+	private void updateQueueAttributes() throws Exception {
+		/*
+		 * Get the "View" page of the test queue:
+		 */
+		HtmlPage page = getDestinationDetailPage(DESTINATION_QUEUE, TEST_QUEUE);
+
+		/*
+		 * Assign new values to the attributes:
+		 */
+		HtmlForm form = page.getFormByName("destination");
+
+		HtmlTextInput jndiName = (HtmlTextInput) form
+				.getInputByName("jndiName");
+		jndiName.setValueAttribute("newJndiName");
+
+		HtmlTextInput downCacheSize = (HtmlTextInput) form
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute("3000");
+
+		HtmlTextInput fullSize = (HtmlTextInput) form
+				.getInputByName("fullSize");
+		fullSize.setValueAttribute("60000");
+
+		HtmlTextInput pageSize = (HtmlTextInput) form
+				.getInputByName("pageSize");
+		pageSize.setValueAttribute("3000");
+
+		List textAreas = form.getTextAreasByName("securityRoles");
+		HtmlTextArea securityRoles = (HtmlTextArea) textAreas.get(0);
+		String prop1 = "admin:read:write:create";
+		String prop2 = "guest:read:write";
+		securityRoles.setText(prop1 + NL + prop2);
+
+		/*
+		 * Click the "Save" button and verify an update successful message was
+		 * returned:
+		 */
+		page = clickButton(form, SAVE_BUTTON);
+		String expectedMsg = msgProps.getProperty("destination.update.success");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(page, expectedMsg));
+
+		/*
+		 * Wait for a couple of seconds then get the test queue and verify the
+		 * changes:
+		 */
+		Thread.sleep(hotDeployWaitTime * 2);
+		page = getDestinationDetailPage(DESTINATION_QUEUE, TEST_QUEUE);
+		form = page.getFormByName("destination");
+
+		jndiName = (HtmlTextInput) form.getInputByName("jndiName");
+		assertEquals("newJndiName", jndiName.asText());
+
+		downCacheSize = (HtmlTextInput) form.getInputByName("downCacheSize");
+		assertEquals("3000", downCacheSize.asText());
+
+		fullSize = (HtmlTextInput) form.getInputByName("fullSize");
+		assertEquals("60000", fullSize.asText());
+
+		pageSize = (HtmlTextInput) form.getInputByName("pageSize");
+		assertEquals("3000", pageSize.asText());
+
+		textAreas = form.getTextAreasByName("securityRoles");
+		securityRoles = (HtmlTextArea) textAreas.get(0);
+		assertEquals(prop1 + " " + prop2, securityRoles.asText());
+	}
+
+	/**
+	 * Test actions to remove a destination queue.
+	 * 
+	 * @throws Exception
+	 */
+	private void removeQueue() throws Exception {
+		/*
+		 * Remember the number of existing queues:
+		 */
+		int prevQueueNo = getNumberOfDestinations(DESTINATION_QUEUE);
+		log.debug("prevQueueNo = " + prevQueueNo);
+
+		/*
+		 * Remove the test queue but cancel the request. Make sure the number of
+		 * queues doesn't change:
+		 */
+		removeDestination(DESTINATION_QUEUE, TEST_QUEUE, false);
+		int queueNo = getNumberOfDestinations(DESTINATION_QUEUE);
+		assertEquals("Number of queues should be the same", prevQueueNo,
+				queueNo);
+
+		/*
+		 * Remove the test queue again and ok the request. The number of queues
+		 * should be decremented by 1:
+		 */
+		removeDestination(DESTINATION_QUEUE, TEST_QUEUE, true);
+		queueNo = getNumberOfDestinations(DESTINATION_QUEUE);
+		assertEquals("Number of queues should be decremented by 1",
+				prevQueueNo - 1, queueNo);
+
+		/*
+		 * Make sure the test queue is no longer available:
+		 */
+		HtmlPage listPage = getDestinationListPage(DESTINATION_QUEUE);
+		HtmlForm form = getDestinationEntryFromList(listPage, TEST_QUEUE);
+		assertNull("Test queue should not be avaialable", form);
+	}
+
+	/**
+	 * Perform a list of tests in sequence.
+	 * 
+	 * @throws Exception
+	 */
+	public void testQueueOperations() throws Exception {
+		createQueueWithBadName();
+		createQueueWithMissingRequiredData();
+		createQueue();
+		createQueueWithDuplicateName();
+		viewQueue();
+		viewDataActions();
+		cancelQueueAttributeChanges();
+		updateQueueWithInvalidData();
+		updateQueueAttributes();
+		removeQueue();
+	}
+}
\ No newline at end of file

Added: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsTopicTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsTopicTest.java	                        (rev 0)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JmsTopicTest.java	2007-01-27 00:45:07 UTC (rev 60037)
@@ -0,0 +1,825 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.admin.console.webtest;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
+import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+/**
+ * Integration tests for managing JBoss Messaging's destination topic.
+ * 
+ * @author <a href="chi.lin at unisys.com">Chi Lin </a>
+ * @version $Revision: 59929 $
+ */
+public class JmsTopicTest extends JmsDestinationTestCase {
+
+	private static Log log = LogFactory.getLog(JBossmqTopicTest.class);
+
+	private final static String DESTINATION_TOPIC = "topic";
+
+	private final static String TEST_TOPIC = "testTopic1";
+
+	private final static String TEST_TOPIC_JNDI_NAME = "topic/" + TEST_TOPIC;
+
+	private final static String SUBSCRIPTION_ID1 = "sub1";
+
+	public JmsTopicTest(String arg0) throws Exception {
+		super(arg0);
+
+		/*
+		 * Remove the test topic if it already exists:
+		 */
+		removeDestination(DESTINATION_TOPIC, TEST_TOPIC, true);
+	}
+
+	/**
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/**
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Start a non-durable subscriber on a new thread to receive a TextMessage
+	 * from the test topic
+	 */
+	class Subscriber extends Thread {
+		public void run() {
+			InitialContext ctx;
+			TopicConnectionFactory cf;
+			TopicConnection connection;
+			TopicSession session;
+			Topic destination;
+			TopicSubscriber subscriber;
+			TextMessage message;
+
+			try {
+				ctx = getInitialContext();
+				cf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
+				destination = (Topic) ctx.lookup(TEST_TOPIC_JNDI_NAME);
+
+				connection = cf.createTopicConnection();
+				session = connection.createTopicSession(false,
+						Session.AUTO_ACKNOWLEDGE);
+				subscriber = session.createSubscriber(destination);
+
+				// Waiting for a message:
+				connection.start();
+				message = (TextMessage) subscriber.receive();
+				// Message received, we're done:
+				connection.close();
+			} catch (NamingException e) {
+				e.printStackTrace();
+			} catch (JMSException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	/**
+	 * Start a durable subscriber on a new thread to receive a TextMessage from
+	 * the test topic
+	 */
+	class DurableSubscriber extends Thread {
+		public void run() {
+			InitialContext ctx;
+			TopicConnectionFactory cf;
+			TopicConnection connection;
+			TopicSession session;
+			Topic destination;
+			TopicSubscriber subscriber;
+			TextMessage message;
+
+			try {
+				ctx = getInitialContext();
+				cf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
+				destination = (Topic) ctx.lookup(TEST_TOPIC_JNDI_NAME);
+
+				connection = cf.createTopicConnection("guest", "guest");
+				session = connection.createTopicSession(false,
+						Session.AUTO_ACKNOWLEDGE);
+				subscriber = session.createDurableSubscriber(destination,
+						SUBSCRIPTION_ID1);
+
+				// Waiting for a message:
+				connection.start();
+				message = (TextMessage) subscriber.receive();
+
+				// Message received. Sleep for a while allowing the main test to
+				// prodeed, then remove the subscriber:
+				Thread.sleep(hotDeployWaitTime * 2);
+				session.unsubscribe("sub1");
+
+				connection.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	/**
+	 * Sends a TextMessage to the test topic.
+	 * 
+	 * @throws NamingException
+	 * @throws JMSException
+	 */
+	private void sendMessageToTopic() throws NamingException, JMSException {
+		InitialContext ctx;
+		TopicConnectionFactory cf;
+		TopicConnection connection;
+		TopicSession session;
+		Topic destination;
+		TopicPublisher publisher;
+		TextMessage message;
+
+		ctx = getInitialContext();
+		cf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
+		destination = (Topic) ctx.lookup(TEST_TOPIC_JNDI_NAME);
+
+		connection = cf.createTopicConnection();
+		session = connection
+				.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+		publisher = session.createPublisher(destination);
+
+		// sends persistent messages with a priority of 7 and a Time To Live
+		// value of one minute:
+		publisher.setDeliveryMode(DeliveryMode.PERSISTENT);
+		publisher.setPriority(7);
+		publisher.setTimeToLive(600000);
+
+		message = session.createTextMessage();
+		message.setText("Hello World!");
+
+		// Sending message:
+		publisher.publish(message);
+
+		connection.close();
+	}
+
+	/**
+	 * Verify the provided page contains the expected input fields of the "More"
+	 * page of a topic. The value of the input fields are not checked.
+	 * 
+	 * @param page
+	 *            The page to be verified
+	 * @throws Exception
+	 */
+	private void verifyMorePage(HtmlPage page) throws Exception {
+		/*
+		 * Get the destTable and verify it is not empty:
+		 */
+		final HtmlTable table = (HtmlTable) page
+				.getHtmlElementById("destTable");
+		final List rows = table.getRows();
+		assertFalse(TABLE_EMPTY, rows.isEmpty());
+
+		/*
+		 * Verify correct labels exist in the table:
+		 */
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("destination.view.durableSubCount"), table
+				.getCellAt(0, 0).asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("destination.view.nonDurableSubCount"), table
+				.getCellAt(1, 0).asText());
+		assertEquals(TABLE_CELL_MISMATCH, msgProps
+				.getProperty("destination.view.allSubCount"), table.getCellAt(
+				2, 0).asText());
+
+		/*
+		 * Verify the data column of each row is not null:
+		 */
+		HtmlTableRow row = null;
+		for (int i = 0; i < rows.size(); i++) {
+			row = (HtmlTableRow) rows.get(i);
+			assertNotNull("Null data in table, row = " + i, row.getCell(1));
+		}
+	}
+
+	/**
+	 * Verify the number of specified subscription entries on the page matches
+	 * the expected number.
+	 * 
+	 * @param page
+	 *            The HtmlPage containing the subscription table to be verified
+	 * @param tableName
+	 *            The name of the subscription table to be verified
+	 * @param expEntries
+	 *            Number of expected entries on the specified table
+	 * @throws Exception
+	 */
+	private void verifySubscription(HtmlPage page, String tableName,
+			int expEntries) throws Exception {
+		/*
+		 * Get the specified table and verify the number of <tbody> entries on
+		 * the table equals to our expectation. Note that table.getRowCount() or
+		 * table.getBodies doesn't give us the right info, so
+		 * getHtmlElementsByTagName() is used:
+		 */
+		HtmlTable table = (HtmlTable) page.getHtmlElementById(tableName);
+		List bodies = table.getHtmlElementsByTagName("tbody");
+		assertEquals(expEntries, bodies.size());
+	}
+
+	/**
+	 * Test creating a destination topic with a bad name.
+	 * 
+	 * @throws Exception
+	 */
+	private void createTopicWithBadName() throws Exception {
+		/*
+		 * Build an attributes map with a bad name attribute:
+		 */
+		Map attMap = new HashMap();
+		attMap.put("name", "bad:::Topic");
+
+		/*
+		 * Create the topic and verify the returned error message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_TOPIC, attMap);
+		String expectedMsg = msgProps.getProperty("destination.create.failure");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+	}
+
+	/**
+	 * Test creating a destination topic without providing the required
+	 * information (the name).
+	 * 
+	 * @throws Exception
+	 */
+	private void createTopicWithMissingRequiredData() throws Exception {
+		/*
+		 * Create a topic with an empty attribute map and verify the returned
+		 * error message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_TOPIC, new HashMap());
+		String expectedMsg = msgProps.getProperty("destination.view.name")
+				+ " is required";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+	}
+
+	/**
+	 * Test creating a destination topic providing the minimum required data.
+	 * The topic created by this test will be used by other test cases in this
+	 * suite.
+	 * 
+	 * @throws Exception
+	 */
+	private void createTopic() throws Exception {
+		/*
+		 * Find out the number of existing topics:
+		 */
+		int prevTopicNo = getNumberOfDestinations(DESTINATION_TOPIC);
+		log.debug("prevTopicNo = " + prevTopicNo);
+
+		/*
+		 * Build a map containing minimum attributes needed to create the topic:
+		 */
+		Map attMap = new HashMap();
+		attMap.put("name", TEST_TOPIC);
+
+		/*
+		 * Create the topic and verify the success message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_TOPIC, attMap);
+		String expectedMsg = msgProps.getProperty("destination.create.success");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+
+		/*
+		 * Wait for a few seconds then refresh the list (for a maximum of 3
+		 * times) and verify the number of topics is incremented by 1:
+		 */
+		boolean topicCreated = false;
+		for (int i = 0; i < 3; i++) {
+			Thread.sleep(hotDeployWaitTime);
+			listPage = refreshPage(listPage);
+			int topicNo = getNumberOfDestinations(listPage);
+			log.debug("topicNo = " + topicNo);
+			if (topicNo == prevTopicNo + 1) {
+				topicCreated = true;
+				break;
+			}
+		}
+		assertTrue("Topic not created", topicCreated);
+
+		/*
+		 * Make sure we can get the newly created topic:
+		 */
+		HtmlForm form = getDestinationEntryFromList(listPage, TEST_TOPIC);
+		assertNotNull("Can't find the newly created topic", form);
+	}
+
+	/**
+	 * Test creating a topic using a name that already exists.
+	 * 
+	 * @throws Exception
+	 */
+	private void createTopicWithDuplicateName() throws Exception {
+		/*
+		 * Build an attributes map containing duplicate topic name:
+		 */
+		Map attMap = new HashMap();
+		attMap.put("name", TEST_TOPIC);
+
+		/*
+		 * Create the topic and verify the returned error message:
+		 */
+		HtmlPage listPage = createDestination(DESTINATION_TOPIC, attMap);
+		String expectedMsg = msgProps.getProperty("destination.create.failure");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(listPage, expectedMsg));
+	}
+
+	/**
+	 * Test the action to view a topic.
+	 * 
+	 * @throws Exception
+	 */
+	private void viewTopic() throws Exception {
+		/*
+		 * Click the "View" button of the test topic and verify the correct page
+		 * was obtained:
+		 */
+		HtmlPage destPage = getDestinationDetailPage(DESTINATION_TOPIC,
+				TEST_TOPIC);
+		verifySettingsPage(destPage);
+
+		/*
+		 * Click the "More" tab and verify the page:
+		 */
+		HtmlPage morePage = clickLink(destPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+	}
+
+	/**
+	 * Test various actions related to managing the messages in the destination
+	 * topic.
+	 * 
+	 * @throws Exception
+	 */
+	private void viewDataActions() throws Exception {
+		/*
+		 * Click the "View Data" button of the test topic and verify we landed
+		 * at the "Message Statistics" page and there're currently no message
+		 * statistics to report:
+		 */
+		HtmlPage dataPage = getViewDataPage(DESTINATION_TOPIC, TEST_TOPIC);
+		String expectedMsg = "Message Statistics: " + DESTINATION_TOPIC + "/"
+				+ TEST_TOPIC;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.messageStatistics.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Verify there're nothing to report on other tabs either:
+		 */
+		dataPage = clickLink(dataPage, HREF_SUBSCRIPTIONS_PAGE);
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.durableSubscriptions.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.nonDurableSubscriptions.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		dataPage = clickLink(dataPage, HREF_MSG_COUNTER_HISTORY_PAGE);
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.messageHistory.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Start two non-durable and one durable subscribers. Verify the message
+		 * statistics page contains three entries and all of the entries'
+		 * message count is set to 0:
+		 */
+		Subscriber subscriber1 = new Subscriber();
+		subscriber1.start();
+		Subscriber subscriber2 = new Subscriber();
+		subscriber2.start();
+		DurableSubscriber durableSubscriber1 = new DurableSubscriber();
+		durableSubscriber1.start();
+		Thread.sleep(hotDeployWaitTime * 2);
+		dataPage = getViewDataPage(DESTINATION_TOPIC, TEST_TOPIC);
+		verifyMessageStatisticsPage(dataPage, DESTINATION_TOPIC, TEST_TOPIC, 3,
+				1, 0);
+		verifyMessageStatisticsPage(dataPage, DESTINATION_TOPIC, TEST_TOPIC, 3,
+				2, 0);
+		verifyMessageStatisticsPage(dataPage, DESTINATION_TOPIC, TEST_TOPIC, 3,
+				3, 0);
+
+		/*
+		 * Switch to the "Subscriptions" tab and verify the page heading:
+		 */
+		dataPage = clickLink(dataPage, HREF_SUBSCRIPTIONS_PAGE);
+		expectedMsg = "Subscriptions: " + DESTINATION_TOPIC + "/" + TEST_TOPIC;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Verify there're one durable subscriptions and two non-durable
+		 * subscriptions on the page:
+		 */
+		verifySubscription(dataPage, "durableTable", 1);
+		verifySubscription(dataPage, "nonDurableTable", 2);
+
+		/*
+		 * Click the "View messages" button of the first non-durable
+		 * subscription and verify there're no messages to report:
+		 */
+		HtmlTable table = (HtmlTable) dataPage
+				.getHtmlElementById("nonDurableTable");
+		List forms = table.getHtmlElementsByTagName("form");
+		HtmlForm form = (HtmlForm) forms.get(0);
+		HtmlPage msgPage = clickButton(form, VIEW_MESSAGES_BUTTON);
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.topicMessages.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(msgPage, expectedMsg));
+
+		/*
+		 * Switch to the "Message Counter History" tab and verify the page
+		 * heading. Note that since the message counter history report comes
+		 * directly from the MBean method, no further validation is performed
+		 * here until the implementation changes are finalized:
+		 */
+		dataPage = clickLink(dataPage, HREF_MSG_COUNTER_HISTORY_PAGE);
+		expectedMsg = "Message Counter History: " + DESTINATION_TOPIC + "/"
+				+ TEST_TOPIC;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Click the "Reset Message Counter History" button and verify it
+		 * returns to the same page:
+		 */
+		form = dataPage.getFormByName("destinationIdentifier");
+		dataPage = clickButton(form, RESET_MSG_COUNTER_HISTORY_BUTTON);
+		expectedMsg = "Message Counter History: " + DESTINATION_TOPIC + "/"
+				+ TEST_TOPIC;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Send a message to the test topic and verify there's only one entry
+		 * reported on the "Message Statistics" tab (both of the non-durable
+		 * subscriptions went away), and the message count is 1:
+		 */
+		sendMessageToTopic();
+		Thread.sleep(hotDeployWaitTime);
+		dataPage = getViewDataPage(DESTINATION_TOPIC, TEST_TOPIC);
+		verifyMessageStatisticsPage(dataPage, DESTINATION_TOPIC, TEST_TOPIC, 1,
+				1, 1);
+
+		/*
+		 * Switch to the "Subscriptions" tab and verify there're one durable
+		 * subscription and no non-durable subscription:
+		 */
+		dataPage = clickLink(dataPage, HREF_SUBSCRIPTIONS_PAGE);
+		verifySubscription(dataPage, "durableTable", 1);
+		expectedMsg = msgProps
+				.getProperty("destination.msg.view.nonDurableSubscriptions.empty");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(dataPage, expectedMsg));
+
+		/*
+		 * Click the "View Messages" button and verify the page heading.
+		 */
+		table = (HtmlTable) dataPage.getHtmlElementById("durableTable");
+		forms = table.getHtmlElementsByTagName("form");
+		form = (HtmlForm) forms.get(0);
+		msgPage = clickButton(form, VIEW_MESSAGES_BUTTON);
+		expectedMsg = "Destination Messages: " + DESTINATION_TOPIC + "/"
+				+ TEST_TOPIC;
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(msgPage, expectedMsg));
+
+		// TODO: The listMessages() operation of the destination mbean used to
+		// report the messages received by a durable subscriber, thus we should
+		// be able to view the message here. However while this test was
+		// developed, the destination mbean does not function as expected
+		// anymore, thus the page content is not verified here until further
+		// investination.
+	}
+
+	/**
+	 * Test the action to change some topic attributes and cancel the request.
+	 * 
+	 * @throws Exception
+	 */
+	private void cancelTopicAttributeChanges() throws Exception {
+		/*
+		 * Get the "View" page of the test topic:
+		 */
+		HtmlPage page = getDestinationDetailPage(DESTINATION_TOPIC, TEST_TOPIC);
+
+		/*
+		 * Save old value and assign new one to some selected attributes:
+		 */
+		HtmlForm form = page.getFormByName("destination");
+		HtmlTextInput downCacheSize = (HtmlTextInput) form
+				.getInputByName("downCacheSize");
+		String savedDownCacheSize = downCacheSize.asText();
+		downCacheSize.setValueAttribute("1000");
+
+		HtmlTextInput fullSize = (HtmlTextInput) form
+				.getInputByName("fullSize");
+		String savedFullSize = fullSize.asText();
+		fullSize.setValueAttribute("50000");
+
+		HtmlTextInput pageSize = (HtmlTextInput) form
+				.getInputByName("pageSize");
+		String savedPageSize = pageSize.asText();
+		pageSize.setValueAttribute("1000");
+
+		/*
+		 * Click the "Cancel" button and verify the list page is displayed:
+		 */
+		HtmlPage newPage = clickButton(form, CANCEL_BUTTON);
+		String expectedMsg = msgProps
+				.getProperty("destination.list.destinations.page.header");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(newPage, expectedMsg));
+
+		/*
+		 * Wait for a couple of seconds then view the topic to verify the
+		 * previous settings were retained:
+		 */
+		Thread.sleep(hotDeployWaitTime);
+		page = getDestinationDetailPage(DESTINATION_TOPIC, TEST_TOPIC);
+		form = page.getFormByName("destination");
+
+		downCacheSize = (HtmlTextInput) form.getInputByName("downCacheSize");
+		assertEquals(savedDownCacheSize, downCacheSize.asText());
+
+		fullSize = (HtmlTextInput) form.getInputByName("fullSize");
+		assertEquals(savedFullSize, fullSize.asText());
+
+		pageSize = (HtmlTextInput) form.getInputByName("pageSize");
+		assertEquals(savedPageSize, pageSize.asText());
+	}
+
+	/**
+	 * Test updating a destination topic with invalid data.
+	 * 
+	 * @throws Exception
+	 */
+	private void updateTopicWithInvalidData() throws Exception {
+		/*
+		 * Get the "View" page of the test topic:
+		 */
+		HtmlPage destPage = getDestinationDetailPage(DESTINATION_TOPIC,
+				TEST_TOPIC);
+		HtmlForm destForm = destPage.getFormByName("destination");
+
+		/*
+		 * Enter text into integer fields:
+		 */
+		String badInt = "badInt";
+		HtmlTextInput downCacheSize = (HtmlTextInput) destForm
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute(badInt);
+
+		HtmlTextInput fullSize = (HtmlTextInput) destForm
+				.getInputByName("fullSize");
+		fullSize.setValueAttribute(badInt);
+
+		HtmlTextInput pageSize = (HtmlTextInput) destForm
+				.getInputByName("pageSize");
+		pageSize.setValueAttribute(badInt);
+
+		/*
+		 * Switching tab will trigger data validation too. So instead of saving
+		 * the changes, we'll simply click the "More" tab and verify the
+		 * returned error message:
+		 */
+		destPage = clickLink(destPage, HREF_MORE_PAGE);
+		String pageText = destPage.asText();
+		String expectedMsg = msgProps
+				.getProperty("destination.view.downCacheSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("destination.view.fullSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		expectedMsg = msgProps.getProperty("destination.view.pageSize")
+				+ " must be an integer";
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		/*
+		 * Set pageSize smaller than downCacheSize and click the "More" tab to
+		 * verify an error is reported:
+		 */
+		destForm = destPage.getFormByName("destination");
+
+		downCacheSize = (HtmlTextInput) destForm
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute("2000");
+
+		fullSize = (HtmlTextInput) destForm.getInputByName("fullSize");
+		fullSize.setValueAttribute("60000");
+
+		pageSize = (HtmlTextInput) destForm.getInputByName("pageSize");
+		pageSize.setValueAttribute("1000");
+
+		destPage = clickLink(destPage, HREF_MORE_PAGE);
+		pageText = destPage.asText();
+		expectedMsg = msgProps
+				.getProperty("destination.error.pageSizeTooSmall");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+		/*
+		 * Fix the data then click the "More" tab again. It should work this
+		 * time:
+		 */
+		destForm = destPage.getFormByName("destination");
+
+		downCacheSize = (HtmlTextInput) destForm
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute("2000");
+
+		fullSize = (HtmlTextInput) destForm.getInputByName("fullSize");
+		fullSize.setValueAttribute("60000");
+
+		pageSize = (HtmlTextInput) destForm.getInputByName("pageSize");
+		pageSize.setValueAttribute("3000");
+
+		HtmlPage morePage = clickLink(destPage, HREF_MORE_PAGE);
+		verifyMorePage(morePage);
+	}
+
+	/**
+	 * Test the action to update the attributes of a topic.
+	 * 
+	 * @throws Exception
+	 */
+	private void updateTopicAttributes() throws Exception {
+		/*
+		 * Get the "View" page of the test topic:
+		 */
+		HtmlPage page = getDestinationDetailPage(DESTINATION_TOPIC, TEST_TOPIC);
+
+		/*
+		 * Assign new values to the attributes:
+		 */
+		HtmlForm form = page.getFormByName("destination");
+
+		HtmlTextInput jndiName = (HtmlTextInput) form
+				.getInputByName("jndiName");
+		jndiName.setValueAttribute("newJndiName");
+
+		HtmlTextInput downCacheSize = (HtmlTextInput) form
+				.getInputByName("downCacheSize");
+		downCacheSize.setValueAttribute("1000");
+
+		HtmlTextInput fullSize = (HtmlTextInput) form
+				.getInputByName("fullSize");
+		fullSize.setValueAttribute("50000");
+
+		HtmlTextInput pageSize = (HtmlTextInput) form
+				.getInputByName("pageSize");
+		pageSize.setValueAttribute("1000");
+
+		List textAreas = form.getTextAreasByName("securityRoles");
+		HtmlTextArea securityRoles = (HtmlTextArea) textAreas.get(0);
+		String prop1 = "admin:read:write:create";
+		String prop2 = "test:read:write";
+		String prop3 = "guest:read";
+		securityRoles.setText(prop1 + NL + prop2 + NL + prop3);
+
+		/*
+		 * Click the "Save" button and verify an update successful message was
+		 * returned:
+		 */
+		page = clickButton(form, SAVE_BUTTON);
+		String expectedMsg = msgProps.getProperty("destination.update.success");
+		assertTrue(EXP_MSG_NOT_FOUND, findMessage(page, expectedMsg));
+
+		/*
+		 * Wait for a couple of seconds then get the test topic and verify the
+		 * changes:
+		 */
+		Thread.sleep(hotDeployWaitTime * 2);
+		page = getDestinationDetailPage(DESTINATION_TOPIC, TEST_TOPIC);
+		form = page.getFormByName("destination");
+
+		jndiName = (HtmlTextInput) form.getInputByName("jndiName");
+		assertEquals("newJndiName", jndiName.asText());
+
+		downCacheSize = (HtmlTextInput) form.getInputByName("downCacheSize");
+		assertEquals("1000", downCacheSize.asText());
+
+		fullSize = (HtmlTextInput) form.getInputByName("fullSize");
+		assertEquals("50000", fullSize.asText());
+
+		pageSize = (HtmlTextInput) form.getInputByName("pageSize");
+		assertEquals("1000", pageSize.asText());
+
+		textAreas = form.getTextAreasByName("securityRoles");
+		securityRoles = (HtmlTextArea) textAreas.get(0);
+		assertEquals(prop1 + " " + prop2 + " " + prop3, securityRoles.asText());
+	}
+
+	/**
+	 * Test actions to remove a destination topic.
+	 * 
+	 * @throws Exception
+	 */
+	private void removeTopic() throws Exception {
+		/*
+		 * Remember the number of existing topics:
+		 */
+		int prevTopicNo = getNumberOfDestinations(DESTINATION_TOPIC);
+		log.debug("prevTopicNo = " + prevTopicNo);
+
+		/*
+		 * Remove the test topic but cancel the request. Make sure the number of
+		 * topics doesn't change:
+		 */
+		removeDestination(DESTINATION_TOPIC, TEST_TOPIC, false);
+		int topicNo = getNumberOfDestinations(DESTINATION_TOPIC);
+		assertEquals("Number of topics should be the same", prevTopicNo,
+				topicNo);
+
+		/*
+		 * Remove the test topic again and ok the request. The number of topics
+		 * should be decremented by 1:
+		 */
+		removeDestination(DESTINATION_TOPIC, TEST_TOPIC, true);
+		topicNo = getNumberOfDestinations(DESTINATION_TOPIC);
+		assertEquals("Number of topics should be decremented by 1",
+				prevTopicNo - 1, topicNo);
+
+		/*
+		 * Make sure the test topic is no longer available:
+		 */
+		HtmlPage listPage = getDestinationListPage(DESTINATION_TOPIC);
+		HtmlForm form = getDestinationEntryFromList(listPage, TEST_TOPIC);
+		assertNull("Test topic should not be avaialable", form);
+	}
+
+	/**
+	 * Perform a list of tests in sequence.
+	 * 
+	 * @throws Exception
+	 */
+	public void testTopicOperations() throws Exception {
+		createTopicWithBadName();
+		createTopicWithMissingRequiredData();
+		createTopic();
+		createTopicWithDuplicateName();
+		viewTopic();
+		viewDataActions();
+		cancelTopicAttributeChanges();
+		updateTopicWithInvalidData();
+		updateTopicAttributes();
+		removeTopic();
+	}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list