fix test case after changes in https://issues.apache.org/jira/browse/AMQ-4237 broke the test's MBean lookup

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1428458 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-01-03 16:33:17 +00:00
parent 1a57728305
commit 4096f9109a
1 changed files with 25 additions and 26 deletions

View File

@ -43,60 +43,60 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SecurityJMXTest extends TestCase {
private static final Logger LOG = LoggerFactory.getLogger(SimpleAuthenticationPluginTest.class);
private BrokerService broker;
public void setUp() throws Exception {
broker = createBroker();
broker.waitUntilStarted();
Thread.sleep(1000);
}
private static final Logger LOG = LoggerFactory.getLogger(SimpleAuthenticationPluginTest.class);
private BrokerService broker;
public void tearDown() throws Exception {
broker.stop();
}
@Override
public void setUp() throws Exception {
broker = createBroker();
broker.waitUntilStarted();
}
@Override
public void tearDown() throws Exception {
broker.stop();
}
public void testMoveMessages() throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(url, null);
connector.connect();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=TEST.Q");
QueueViewMBean queueMbean = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," +
"destinationType=Queue,destinationName=TEST.Q");
QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
String msgId = queueMbean.sendTextMessage("test", "system", "manager");
queueMbean.moveMessageTo(msgId, "TEST1.Q");
}
public void testBrowseExpiredMessages() throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(url, null);
connector.connect();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=TEST.Q");
QueueViewMBean queueMbean = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost," +
"destinationType=Queue,destinationName=TEST.Q");
QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("JMSExpiration", Long.toString(System.currentTimeMillis() + 2000));
headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
String msgId = queueMbean.sendTextMessage(headers, "test", "system", "manager");
queueMbean.sendTextMessage(headers, "test", "system", "manager");
// allow message to expire on the queue
TimeUnit.SECONDS.sleep(4);
Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
c.start();
// browser consumer will force expriation check on addConsumer
QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());
// verify dlq got the message, no security exception as brokers context is now used
browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
protected BrokerService createBroker() throws Exception {
return createBroker("org/apache/activemq/security/simple-auth-broker.xml");
}
@ -105,5 +105,4 @@ public class SecurityJMXTest extends TestCase {
LOG.info("Loading broker configuration from the classpath with URI: " + uri);
return BrokerFactory.createBroker(new URI("xbean:" + uri));
}
}