Source code: org/activemq/advisories/ConnectionAdvisorTest.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
23 import junit.framework.TestCase;
24
25 import org.activemq.ActiveMQConnectionFactory;
26 import org.activemq.message.ConnectionInfo;
27
28 import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
29 /**
30 * A helper class for listening for MessageConnection advisories
31 */
32
33
34
35 /**
36 *
37 * ConnectionAdvisorTest
38 */
39 public class ConnectionAdvisorTest extends TestCase implements ConnectionAdvisoryEventListener{
40
41 private ActiveMQConnectionFactory fac;
42 private Connection connection;
43 private SynchronizedBoolean started;
44
45
46 protected void setUp() throws Exception{
47 started = new SynchronizedBoolean(false);
48 fac = new ActiveMQConnectionFactory("vm://localhost");
49 connection = fac.createConnection();
50 connection.start();
51 }
52
53 protected void tearDown() throws Exception{
54 connection.close();
55 }
56 public void testAdvisories() throws Exception{
57 ConnectionAdvisor test = new ConnectionAdvisor(connection);
58 test.addListener(this);
59 test.start();
60 Connection testConnection = fac.createConnection();
61 testConnection.start();
62 synchronized(started){
63 if (!started.get()){
64 started.wait(5000);
65 }
66 }
67 assertTrue(started.get());
68
69 }
70
71 public void onEvent(ConnectionAdvisoryEvent event) {
72 System.out.println(event);
73 ConnectionInfo info = event.getInfo();
74 started.set(info.isStarted());
75 synchronized(started){
76 started.notify();
77 }
78
79 }
80
81 }