Source code: org/activemq/advisories/TempDestinationAdvisorTest.java
1 /**
2 *
3 * Copyright 2004 Protique Ltd
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
19 package org.activemq.advisories;
20
21 import javax.jms.Connection;
22 import javax.jms.Session;
23 import javax.jms.TemporaryQueue;
24
25 import junit.framework.TestCase;
26
27 import org.activemq.ActiveMQConnectionFactory;
28 import org.activemq.message.ProducerInfo;
29
30 import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
31 /**
32 * A helper class for listening for MessageProducer advisories
33 */
34
35
36
37 /**
38 *
39 * ProducerAdvisorTest
40 */
41 public class TempDestinationAdvisorTest extends TestCase{
42
43 private ActiveMQConnectionFactory fac;
44 private Connection connection;
45 private SynchronizedBoolean started;
46
47
48 protected void setUp() throws Exception{
49 started = new SynchronizedBoolean(false);
50 fac = new ActiveMQConnectionFactory("vm://localhost");
51 connection = fac.createConnection();
52 connection.start();
53 }
54
55 protected void tearDown() throws Exception{
56 connection.close();
57 }
58 public void testAdvisories() throws Exception{
59 Connection testCon = fac.createConnection();
60 testCon.start();
61 Session s = testCon.createSession(false,Session.AUTO_ACKNOWLEDGE);
62 TemporaryQueue dest = s.createTemporaryQueue();
63 TempDestinationAdvisor test = new TempDestinationAdvisor(connection,dest);
64 test.start();
65 assertTrue("Destination should be active",test.isActive(dest));
66 dest.delete();
67
68 assertFalse("Destination should no longer be active",test.isActive(dest));
69 test.stop();
70
71 testCon = fac.createConnection();
72 testCon.start();
73 s = testCon.createSession(false,Session.AUTO_ACKNOWLEDGE);
74 dest = s.createTemporaryQueue();
75
76 test = new TempDestinationAdvisor(connection,dest);
77 test.start();
78
79 assertTrue(test.isActive(dest));
80 testCon.close();
81
82 assertFalse(test.isActive(dest));
83 test.stop();
84 }
85
86 public void onEvent(ProducerAdvisoryEvent event) {
87 ProducerInfo info = event.getInfo();
88 started.set(info.isStarted());
89 synchronized(started){
90 started.notify();
91 }
92
93 }
94
95 }