Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/transport/DiscoveryAgentTestSupport.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  package org.activemq.transport;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import javax.jms.JMSException;
24  
25  import org.activecluster.ClusterException;
26  
27  import junit.framework.TestCase;
28  
29  /**
30   * @version $Revision: 1.1.1.1 $
31   */
32  public abstract class DiscoveryAgentTestSupport extends TestCase implements DiscoveryListener {
33      protected boolean waitForever = false;
34  
35      protected DiscoveryAgent agent;
36      protected Map localDetails = new HashMap();
37      protected String type = "_activemq_testcase.";
38  
39      public void testDiscovery() throws Exception {
40          localDetails.put("cheese", "Cheddar");
41          localDetails.put("location", "London");
42  
43          agent.addDiscoveryListener(this);
44          agent.start();
45          agent.registerService(createName(), localDetails);
46  
47          if (waitForever) {
48              synchronized (this) {
49                  this.wait();
50              }
51          }
52  
53          agent.stop();
54      }
55  
56      protected String createName() {
57          return getName() + "@" + System.currentTimeMillis();
58      }
59  
60      protected void setUp() throws Exception {
61          super.setUp();
62          agent = createDiscoveryAgent();
63          if (System.getProperty("waitForever") != null) {
64              waitForever = true;
65          }
66      }
67  
68      protected abstract DiscoveryAgent createDiscoveryAgent() throws JMSException, ClusterException;
69  
70      public void addService(DiscoveryEvent event) {
71          System.out.println("Added service: " + event + " with details: " + event.getServiceDetails() + " name: " + event.getServiceName());
72      }
73  
74      public void removeService(DiscoveryEvent event) {
75          System.out.println("Removed service: " + event);
76      }
77  }