[jboss-cvs] JBossAS SVN: r60036 - 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:39:47 EST 2007


Author: chilin
Date: 2007-01-26 19:39:47 -0500 (Fri, 26 Jan 2007)
New Revision: 60036

Added:
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java
Removed:
   projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTestCase.java
Log:
c:/temp/message.txt

Deleted: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTestCase.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTestCase.java	2007-01-26 23:48:07 UTC (rev 60035)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTestCase.java	2007-01-27 00:39:47 UTC (rev 60036)
@@ -1,507 +0,0 @@
-/*
- * 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$
- */
-public abstract class DestinationTestCase extends AdminConsoleTestCase {
-
-	private static Log log = LogFactory.getLog(DestinationTestCase.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_MSG_STATISTICS_PAGE = "javascript:void(setDispatchAndSubmit('viewMessageStatistics'))";
-
-	protected final static String HREF_MESSAGES_PAGE = "javascript:void(setDispatchAndSubmit('viewMessages'))";
-
-	protected final static String HREF_RECEIVERS_PAGE = "javascript:void(setDispatchAndSubmit('viewReceivers'))";
-
-	protected final static String HREF_SUBSCRIPTIONS_PAGE = "javascript:void(setDispatchAndSubmit('viewSubscriptions'))";
-
-	protected final static String HREF_MSG_COUNTER_HISTORY_PAGE = "javascript:void(setDispatchAndSubmit('viewMessageHistory'))";
-
-	/*
-	 * Define submit buttons unique to the destination pages
-	 */
-	protected final static String VIEW_DATA_BUTTON = "View Data";
-
-	protected final static String RESET_MSG_COUNTER_BUTTON = "Reset Message Counter";
-
-	protected final static String REMOVE_ALL_MESSAGES_BUTTON = "Remove All Messages";
-	
-	protected final static String VIEW_MESSAGES_BUTTON = "View Messages";
-
-	protected final static String RESET_MSG_COUNTER_HISTORY_BUTTON = "Reset Message Counter History";
-
-	protected final Properties msgProps;
-
-	public DestinationTestCase(String arg0) throws Exception {
-		super(arg0);
-
-		/*
-		 * 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();
-	}
-
-	/**
-	 * 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 verifyJBossmqSettingsPage(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");
-		HtmlCheckBoxInput inMemory = (HtmlCheckBoxInput) form
-				.getInputByName("inMemory");
-		HtmlTextInput reDeliveryDelay = (HtmlTextInput) form
-				.getInputByName("reDeliveryDelay");
-		HtmlTextInput reDeliveryLimit = (HtmlTextInput) form
-				.getInputByName("reDeliveryLimit");
-		HtmlTextInput maxDepth = (HtmlTextInput) form
-				.getInputByName("maxDepth");
-		HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) form
-				.getInputByName("msgCounterHistoryDayLimit");
-		HtmlTextInput receiversImplName = (HtmlTextInput) form
-				.getInputByName("receiversImplName");
-		HtmlTextInput destinationManagerName = (HtmlTextInput) form
-				.getInputByName("destinationManagerName");
-		HtmlTextInput securityManagerName = (HtmlTextInput) form
-				.getInputByName("securityManagerName");
-		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

Copied: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java (from rev 60035, projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTestCase.java)
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java	                        (rev 0)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqDestinationTestCase.java	2007-01-27 00:39:47 UTC (rev 60036)
@@ -0,0 +1,507 @@
+/*
+ * 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$
+ */
+public abstract class DestinationTestCase extends AdminConsoleTestCase {
+
+	private static Log log = LogFactory.getLog(DestinationTestCase.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_MSG_STATISTICS_PAGE = "javascript:void(setDispatchAndSubmit('viewMessageStatistics'))";
+
+	protected final static String HREF_MESSAGES_PAGE = "javascript:void(setDispatchAndSubmit('viewMessages'))";
+
+	protected final static String HREF_RECEIVERS_PAGE = "javascript:void(setDispatchAndSubmit('viewReceivers'))";
+
+	protected final static String HREF_SUBSCRIPTIONS_PAGE = "javascript:void(setDispatchAndSubmit('viewSubscriptions'))";
+
+	protected final static String HREF_MSG_COUNTER_HISTORY_PAGE = "javascript:void(setDispatchAndSubmit('viewMessageHistory'))";
+
+	/*
+	 * Define submit buttons unique to the destination pages
+	 */
+	protected final static String VIEW_DATA_BUTTON = "View Data";
+
+	protected final static String RESET_MSG_COUNTER_BUTTON = "Reset Message Counter";
+
+	protected final static String REMOVE_ALL_MESSAGES_BUTTON = "Remove All Messages";
+	
+	protected final static String VIEW_MESSAGES_BUTTON = "View Messages";
+
+	protected final static String RESET_MSG_COUNTER_HISTORY_BUTTON = "Reset Message Counter History";
+
+	protected final Properties msgProps;
+
+	public DestinationTestCase(String arg0) throws Exception {
+		super(arg0);
+
+		/*
+		 * 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();
+	}
+
+	/**
+	 * 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 verifyJBossmqSettingsPage(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");
+		HtmlCheckBoxInput inMemory = (HtmlCheckBoxInput) form
+				.getInputByName("inMemory");
+		HtmlTextInput reDeliveryDelay = (HtmlTextInput) form
+				.getInputByName("reDeliveryDelay");
+		HtmlTextInput reDeliveryLimit = (HtmlTextInput) form
+				.getInputByName("reDeliveryLimit");
+		HtmlTextInput maxDepth = (HtmlTextInput) form
+				.getInputByName("maxDepth");
+		HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) form
+				.getInputByName("msgCounterHistoryDayLimit");
+		HtmlTextInput receiversImplName = (HtmlTextInput) form
+				.getInputByName("receiversImplName");
+		HtmlTextInput destinationManagerName = (HtmlTextInput) form
+				.getInputByName("destinationManagerName");
+		HtmlTextInput securityManagerName = (HtmlTextInput) form
+				.getInputByName("securityManagerName");
+		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




More information about the jboss-cvs-commits mailing list