Source code: org/activemq/BrokerAdminCommandsTest.java
1 /**
2 *
3 * Copyright 2004 Hiram Chirino
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.activemq;
19
20 import javax.jms.Connection;
21 import javax.jms.DeliveryMode;
22 import javax.jms.JMSException;
23 import javax.jms.Message;
24 import javax.jms.MessageConsumer;
25 import javax.jms.MessageProducer;
26 import javax.jms.Queue;
27 import javax.jms.Session;
28 import javax.jms.TextMessage;
29
30 import junit.framework.TestCase;
31
32 import org.activemq.message.ActiveMQDestination;
33
34 /**
35 * @version $Revision: 1.1.1.1 $
36 */
37 public class BrokerAdminCommandsTest extends TestCase {
38
39 private Connection connection;
40
41 protected void setUp() throws Exception {
42 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
43 connection = factory.createConnection();
44 connection.start();
45 }
46
47 /**
48 * @see junit.framework.TestCase#tearDown()
49 */
50 protected void tearDown() throws Exception {
51 connection.close();
52 }
53
54
55 /**
56 * @throws JMSException
57 */
58 public void testDestroyDestination() throws JMSException {
59
60 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
61
62 Queue queue = session.createQueue("testQueue");
63
64 // Send the message.
65 MessageProducer producer = session.createProducer(queue);
66 producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
67 producer.send(session.createTextMessage("First"));
68 producer.setDeliveryMode(DeliveryMode.PERSISTENT);
69 producer.send(session.createTextMessage("Second"));
70 session.close();
71
72 // This should remove all the messages that were sent to the destination.
73 ((ActiveMQConnection)connection).destroyDestination((ActiveMQDestination)queue);
74
75 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
76
77 producer = session.createProducer(queue);
78 producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
79 producer.send(session.createTextMessage("Last"));
80
81 // Test the assertions.
82 MessageConsumer startedConsumer = session.createConsumer(queue);
83 Message m = startedConsumer.receive(1000);
84 assertNotNull(m);
85
86 assertEquals( "Last", ((TextMessage)m).getText() );
87 }
88
89 }