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

Quick Search    Search Deep

Source code: org/activemq/transport/FactoryFinderTest.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 junit.framework.TestCase;
21  
22  import org.activemq.transport.jrms.JRMSTransportChannelFactory;
23  import org.activemq.transport.jrms.JRMSTransportServerChannelFactory;
24  import org.activemq.transport.multicast.MulticastTransportChannelFactory;
25  import org.activemq.transport.multicast.MulticastTransportServerChannelFactory;
26  import org.activemq.transport.ssl.SslTransportChannelFactory;
27  import org.activemq.transport.ssl.SslTransportServerChannelFactory;
28  import org.activemq.transport.tcp.TcpTransportChannelFactory;
29  import org.activemq.transport.tcp.TcpTransportServerChannelFactory;
30  import org.activemq.transport.udp.UdpTransportChannelFactory;
31  import org.activemq.transport.udp.UdpTransportServerChannelFactory;
32  import org.activemq.transport.vm.VmTransportChannelFactory;
33  import org.activemq.transport.vm.VmTransportServerChannelFactory;
34  import org.activemq.util.FactoryFinder;
35  
36  /**
37   * @version $Revision: 1.2 $
38   */
39  public class FactoryFinderTest extends TestCase {
40      FactoryFinder clientFinder = new FactoryFinder("META-INF/services/org/activemq/transport/");
41      FactoryFinder serverFinder = new FactoryFinder("META-INF/services/org/activemq/transport/server/");
42  
43      public void testClientFactory() throws Exception {
44          assertClient("jrms", JRMSTransportChannelFactory.class);
45          assertClient("multicast", MulticastTransportChannelFactory.class);
46          assertClient("ssl", SslTransportChannelFactory.class);
47          assertClient("tcp", TcpTransportChannelFactory.class);
48          assertClient("udp", UdpTransportChannelFactory.class);
49          assertClient("vm", VmTransportChannelFactory.class);
50  //        assertClient("jxta", JxtaTransportChannelFactory.class);
51  //        assertClient("nio", EmberTransportChannelFactory.class);
52      }
53  
54      public void testServerFactory() throws Exception {
55          assertServer("jrms", JRMSTransportServerChannelFactory.class);
56          assertServer("multicast", MulticastTransportServerChannelFactory.class);
57          assertServer("ssl", SslTransportServerChannelFactory.class);
58          assertServer("tcp", TcpTransportServerChannelFactory.class);
59          assertServer("udp", UdpTransportServerChannelFactory.class);
60          assertServer("vm", VmTransportServerChannelFactory.class);
61  //        assertServer("jxta", JxtaTransportServerChannelFactory.class);
62  //        assertServer("nio", EmberTransportServerChannelFactory.class);
63      }
64  
65      protected void assertClient(String key, Class type) throws Exception {
66          assertFinder(key, type, clientFinder);
67      }
68  
69      protected void assertServer(String key, Class type) throws Exception {
70          assertFinder(key, type, serverFinder);
71      }
72  
73      protected void assertFinder(String key, Class type, FactoryFinder finder) throws Exception {
74          Object factory = finder.newInstance(key);
75          assertTrue("Returned non null object", factory != null);
76          assertTrue("Is an instance of: " + type, type.isInstance(factory));
77  
78          // lets do it one more time to test the cache returns the same value
79          factory = finder.newInstance(key);
80          assertTrue("Is an instance of: " + type, type.isInstance(factory));
81      }
82  }