[jboss-cvs] JBossAS SVN: r59926 - 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
Mon Jan 22 15:27:17 EST 2007
Author: chilin
Date: 2007-01-22 15:27:17 -0500 (Mon, 22 Jan 2007)
New Revision: 59926
Added:
projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java
Removed:
projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTopicTest.java
Log:
c:/temp/message.txt
Deleted: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTopicTest.java
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTopicTest.java 2007-01-22 20:26:46 UTC (rev 59925)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTopicTest.java 2007-01-22 20:27:17 UTC (rev 59926)
@@ -1,859 +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.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 of the jboss admin console's Topic handling capabilities.
- *
- * @author <a href="chi.lin at unisys.com">Chi Lin </a>
- * @version $Revision$
- */
-public class DestinationTopicTest extends DestinationTestCase {
-
- private static Log log = LogFactory.getLog(DestinationTopicTest.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 DestinationTopicTest(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.durableMsgCount"), table
- .getCellAt(0, 0).asText());
- assertEquals(TABLE_CELL_MISMATCH, msgProps
- .getProperty("destination.view.nonDurableMsgCount"), table
- .getCellAt(1, 0).asText());
- assertEquals(TABLE_CELL_MISMATCH, msgProps
- .getProperty("destination.view.durableSubCount"), table
- .getCellAt(2, 0).asText());
- assertEquals(TABLE_CELL_MISMATCH, msgProps
- .getProperty("destination.view.nonDurableSubCount"), table
- .getCellAt(3, 0).asText());
- assertEquals(TABLE_CELL_MISMATCH, msgProps
- .getProperty("destination.view.allMsgCount"), table.getCellAt(
- 4, 0).asText());
- assertEquals(TABLE_CELL_MISMATCH, msgProps
- .getProperty("destination.view.allSubCount"), 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 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 reDeliveryLimit = (HtmlTextInput) form
- .getInputByName("reDeliveryLimit");
- String savedReDeliveryLimit = reDeliveryLimit.asText();
- reDeliveryLimit.setValueAttribute("9");
-
- HtmlTextInput maxDepth = (HtmlTextInput) form
- .getInputByName("maxDepth");
- String savedMaxDepth = maxDepth.asText();
- maxDepth.setValueAttribute("9");
-
- HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) form
- .getInputByName("msgCounterHistoryDayLimit");
- String savedMsgCounterHistoryDayLimit = msgCounterHistoryDayLimit
- .asText();
- msgCounterHistoryDayLimit.setValueAttribute("9");
-
- /*
- * 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");
-
- reDeliveryLimit = (HtmlTextInput) form
- .getInputByName("reDeliveryLimit");
- assertEquals(savedReDeliveryLimit, reDeliveryLimit.asText());
-
- maxDepth = (HtmlTextInput) form.getInputByName("maxDepth");
- assertEquals(savedMaxDepth, maxDepth.asText());
-
- msgCounterHistoryDayLimit = (HtmlTextInput) form
- .getInputByName("msgCounterHistoryDayLimit");
- assertEquals(savedMsgCounterHistoryDayLimit, msgCounterHistoryDayLimit
- .asText());
- }
-
- /**
- * Test updating a destination topic with wrong type of 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 invalid data (e.g. put text into integer fields):
- */
- String badInt = "badInt";
- HtmlTextInput reDeliveryDelay = (HtmlTextInput) destForm
- .getInputByName("reDeliveryDelay");
- reDeliveryDelay.setValueAttribute(badInt);
-
- HtmlTextInput reDeliveryLimit = (HtmlTextInput) destForm
- .getInputByName("reDeliveryLimit");
- reDeliveryLimit.setValueAttribute(badInt);
-
- HtmlTextInput maxDepth = (HtmlTextInput) destForm
- .getInputByName("maxDepth");
- maxDepth.setValueAttribute(badInt);
-
- HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) destForm
- .getInputByName("msgCounterHistoryDayLimit");
- msgCounterHistoryDayLimit.setValueAttribute(badInt);
-
- HtmlTextInput receiversImplName = (HtmlTextInput) destForm
- .getInputByName("receiversImplName");
- receiversImplName.setValueAttribute("no.such.class");
-
- /*
- * 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();
-
- // Because the special characters must be escaped, the following
- // message is hard-coded.
- String expectedMsg = "Redelivery delay \\(milliseconds\\): must be a long";
- assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
-
- expectedMsg = msgProps.getProperty("destination.view.reDeliveryLimit")
- + " must be an integer";
- assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
-
- expectedMsg = msgProps.getProperty("destination.view.maxDepth")
- + " must be an integer";
- assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
-
- expectedMsg = msgProps
- .getProperty("destination.view.msgCounterHistoryDayLimit")
- + " must be an integer";
- assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
-
- expectedMsg = msgProps.getProperty("destination.view.receiversImpl")
- + " must be a valid class name";
- 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");
-
- reDeliveryDelay = (HtmlTextInput) destForm
- .getInputByName("reDeliveryDelay");
- reDeliveryDelay.setValueAttribute("5000");
-
- reDeliveryLimit = (HtmlTextInput) destForm
- .getInputByName("reDeliveryLimit");
- reDeliveryLimit.setValueAttribute("9");
-
- maxDepth = (HtmlTextInput) destForm.getInputByName("maxDepth");
- maxDepth.setValueAttribute("9");
-
- msgCounterHistoryDayLimit = (HtmlTextInput) destForm
- .getInputByName("msgCounterHistoryDayLimit");
- msgCounterHistoryDayLimit.setValueAttribute("9");
-
- receiversImplName = (HtmlTextInput) destForm
- .getInputByName("receiversImplName");
- receiversImplName.setValueAttribute("");
-
- 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");
-
- HtmlCheckBoxInput inMemory = (HtmlCheckBoxInput) form
- .getInputByName("inMemory");
- inMemory.setChecked(true);
-
- HtmlTextInput reDeliveryDelay = (HtmlTextInput) form
- .getInputByName("reDeliveryDelay");
- reDeliveryDelay.setValueAttribute("4000");
-
- HtmlTextInput reDeliveryLimit = (HtmlTextInput) form
- .getInputByName("reDeliveryLimit");
- reDeliveryLimit.setValueAttribute("9");
-
- HtmlTextInput maxDepth = (HtmlTextInput) form
- .getInputByName("maxDepth");
- maxDepth.setValueAttribute("9");
-
- HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) form
- .getInputByName("msgCounterHistoryDayLimit");
- msgCounterHistoryDayLimit.setValueAttribute("9");
-
- 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 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());
-
- inMemory = (HtmlCheckBoxInput) form.getInputByName("inMemory");
- assertTrue(ITEM_NOT_CHECKED, inMemory.isChecked());
-
- reDeliveryDelay = (HtmlTextInput) form
- .getInputByName("reDeliveryDelay");
- assertEquals("4000", reDeliveryDelay.asText());
-
- reDeliveryLimit = (HtmlTextInput) form
- .getInputByName("reDeliveryLimit");
- assertEquals("9", reDeliveryLimit.asText());
-
- maxDepth = (HtmlTextInput) form.getInputByName("maxDepth");
- assertEquals("9", maxDepth.asText());
-
- msgCounterHistoryDayLimit = (HtmlTextInput) form
- .getInputByName("msgCounterHistoryDayLimit");
- assertEquals("9", msgCounterHistoryDayLimit.asText());
-
- textAreas = form.getTextAreasByName("securityRoles");
- securityRoles = (HtmlTextArea) textAreas.get(0);
- assertEquals(prop1 + " " + prop2, 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
Copied: projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java (from rev 59925, projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/DestinationTopicTest.java)
===================================================================
--- projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java (rev 0)
+++ projects/admin-console/trunk/src/webtest/org/jboss/admin/console/webtest/JBossmqTopicTest.java 2007-01-22 20:27:17 UTC (rev 59926)
@@ -0,0 +1,859 @@
+/*
+ * 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 of the jboss admin console's Topic handling capabilities.
+ *
+ * @author <a href="chi.lin at unisys.com">Chi Lin </a>
+ * @version $Revision$
+ */
+public class DestinationTopicTest extends DestinationTestCase {
+
+ private static Log log = LogFactory.getLog(DestinationTopicTest.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 DestinationTopicTest(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.durableMsgCount"), table
+ .getCellAt(0, 0).asText());
+ assertEquals(TABLE_CELL_MISMATCH, msgProps
+ .getProperty("destination.view.nonDurableMsgCount"), table
+ .getCellAt(1, 0).asText());
+ assertEquals(TABLE_CELL_MISMATCH, msgProps
+ .getProperty("destination.view.durableSubCount"), table
+ .getCellAt(2, 0).asText());
+ assertEquals(TABLE_CELL_MISMATCH, msgProps
+ .getProperty("destination.view.nonDurableSubCount"), table
+ .getCellAt(3, 0).asText());
+ assertEquals(TABLE_CELL_MISMATCH, msgProps
+ .getProperty("destination.view.allMsgCount"), table.getCellAt(
+ 4, 0).asText());
+ assertEquals(TABLE_CELL_MISMATCH, msgProps
+ .getProperty("destination.view.allSubCount"), 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 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 reDeliveryLimit = (HtmlTextInput) form
+ .getInputByName("reDeliveryLimit");
+ String savedReDeliveryLimit = reDeliveryLimit.asText();
+ reDeliveryLimit.setValueAttribute("9");
+
+ HtmlTextInput maxDepth = (HtmlTextInput) form
+ .getInputByName("maxDepth");
+ String savedMaxDepth = maxDepth.asText();
+ maxDepth.setValueAttribute("9");
+
+ HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) form
+ .getInputByName("msgCounterHistoryDayLimit");
+ String savedMsgCounterHistoryDayLimit = msgCounterHistoryDayLimit
+ .asText();
+ msgCounterHistoryDayLimit.setValueAttribute("9");
+
+ /*
+ * 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");
+
+ reDeliveryLimit = (HtmlTextInput) form
+ .getInputByName("reDeliveryLimit");
+ assertEquals(savedReDeliveryLimit, reDeliveryLimit.asText());
+
+ maxDepth = (HtmlTextInput) form.getInputByName("maxDepth");
+ assertEquals(savedMaxDepth, maxDepth.asText());
+
+ msgCounterHistoryDayLimit = (HtmlTextInput) form
+ .getInputByName("msgCounterHistoryDayLimit");
+ assertEquals(savedMsgCounterHistoryDayLimit, msgCounterHistoryDayLimit
+ .asText());
+ }
+
+ /**
+ * Test updating a destination topic with wrong type of 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 invalid data (e.g. put text into integer fields):
+ */
+ String badInt = "badInt";
+ HtmlTextInput reDeliveryDelay = (HtmlTextInput) destForm
+ .getInputByName("reDeliveryDelay");
+ reDeliveryDelay.setValueAttribute(badInt);
+
+ HtmlTextInput reDeliveryLimit = (HtmlTextInput) destForm
+ .getInputByName("reDeliveryLimit");
+ reDeliveryLimit.setValueAttribute(badInt);
+
+ HtmlTextInput maxDepth = (HtmlTextInput) destForm
+ .getInputByName("maxDepth");
+ maxDepth.setValueAttribute(badInt);
+
+ HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) destForm
+ .getInputByName("msgCounterHistoryDayLimit");
+ msgCounterHistoryDayLimit.setValueAttribute(badInt);
+
+ HtmlTextInput receiversImplName = (HtmlTextInput) destForm
+ .getInputByName("receiversImplName");
+ receiversImplName.setValueAttribute("no.such.class");
+
+ /*
+ * 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();
+
+ // Because the special characters must be escaped, the following
+ // message is hard-coded.
+ String expectedMsg = "Redelivery delay \\(milliseconds\\): must be a long";
+ assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+ expectedMsg = msgProps.getProperty("destination.view.reDeliveryLimit")
+ + " must be an integer";
+ assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+ expectedMsg = msgProps.getProperty("destination.view.maxDepth")
+ + " must be an integer";
+ assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+ expectedMsg = msgProps
+ .getProperty("destination.view.msgCounterHistoryDayLimit")
+ + " must be an integer";
+ assertTrue(EXP_MSG_NOT_FOUND, findMessage(pageText, expectedMsg));
+
+ expectedMsg = msgProps.getProperty("destination.view.receiversImpl")
+ + " must be a valid class name";
+ 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");
+
+ reDeliveryDelay = (HtmlTextInput) destForm
+ .getInputByName("reDeliveryDelay");
+ reDeliveryDelay.setValueAttribute("5000");
+
+ reDeliveryLimit = (HtmlTextInput) destForm
+ .getInputByName("reDeliveryLimit");
+ reDeliveryLimit.setValueAttribute("9");
+
+ maxDepth = (HtmlTextInput) destForm.getInputByName("maxDepth");
+ maxDepth.setValueAttribute("9");
+
+ msgCounterHistoryDayLimit = (HtmlTextInput) destForm
+ .getInputByName("msgCounterHistoryDayLimit");
+ msgCounterHistoryDayLimit.setValueAttribute("9");
+
+ receiversImplName = (HtmlTextInput) destForm
+ .getInputByName("receiversImplName");
+ receiversImplName.setValueAttribute("");
+
+ 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");
+
+ HtmlCheckBoxInput inMemory = (HtmlCheckBoxInput) form
+ .getInputByName("inMemory");
+ inMemory.setChecked(true);
+
+ HtmlTextInput reDeliveryDelay = (HtmlTextInput) form
+ .getInputByName("reDeliveryDelay");
+ reDeliveryDelay.setValueAttribute("4000");
+
+ HtmlTextInput reDeliveryLimit = (HtmlTextInput) form
+ .getInputByName("reDeliveryLimit");
+ reDeliveryLimit.setValueAttribute("9");
+
+ HtmlTextInput maxDepth = (HtmlTextInput) form
+ .getInputByName("maxDepth");
+ maxDepth.setValueAttribute("9");
+
+ HtmlTextInput msgCounterHistoryDayLimit = (HtmlTextInput) form
+ .getInputByName("msgCounterHistoryDayLimit");
+ msgCounterHistoryDayLimit.setValueAttribute("9");
+
+ 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 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());
+
+ inMemory = (HtmlCheckBoxInput) form.getInputByName("inMemory");
+ assertTrue(ITEM_NOT_CHECKED, inMemory.isChecked());
+
+ reDeliveryDelay = (HtmlTextInput) form
+ .getInputByName("reDeliveryDelay");
+ assertEquals("4000", reDeliveryDelay.asText());
+
+ reDeliveryLimit = (HtmlTextInput) form
+ .getInputByName("reDeliveryLimit");
+ assertEquals("9", reDeliveryLimit.asText());
+
+ maxDepth = (HtmlTextInput) form.getInputByName("maxDepth");
+ assertEquals("9", maxDepth.asText());
+
+ msgCounterHistoryDayLimit = (HtmlTextInput) form
+ .getInputByName("msgCounterHistoryDayLimit");
+ assertEquals("9", msgCounterHistoryDayLimit.asText());
+
+ textAreas = form.getTextAreasByName("securityRoles");
+ securityRoles = (HtmlTextArea) textAreas.get(0);
+ assertEquals(prop1 + " " + prop2, 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