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.codehaus.activemq.jndi; 19 import java.io.File; 20 import java.util.Hashtable; 21 22 import javax.naming.Context; 23 import javax.naming.InitialContext; 24 import javax.naming.NamingException; 25 import javax.naming.Reference; 26 import javax.naming.spi.ObjectFactory; 27 28 import junit.framework.TestCase; 29 30 import org.codehaus.activemq.ActiveMQConnectionFactory; 31 /*** 32 * Test that the admin objects can be stored and looked up in JNDI providers. 33 * 34 * @version $Revision: 1.2 $ 35 */ 36 public class AdminObjectTest extends TestCase { 37 Context fsContext; 38 protected void setUp() { 39 try { 40 File tempDir = File.createTempFile("fsjndi", ".dir"); 41 tempDir.delete(); 42 tempDir = tempDir.getCanonicalFile(); 43 tempDir.mkdirs(); 44 Hashtable env = new Hashtable(); 45 env.put(Context.INITIAL_CONTEXT_FACTORY, 46 "com.sun.jndi.fscontext.RefFSContextFactory"); 47 env.put(Context.PROVIDER_URL, tempDir.toURL().toExternalForm()); 48 fsContext = new InitialContext(env); 49 } catch (Exception e) { 50 e.printStackTrace(); 51 } 52 } 53 protected void tearDown() throws Exception { 54 if (fsContext != null) 55 fsContext.close(); 56 } 57 public void testConnectionFactory() throws NamingException, Exception { 58 59 if( fsContext == null ){ 60 return; 61 } 62 63 ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); 64 fsContext.rebind("ConnectionFactory", cf); 65 Object lookup = fsContext.lookup("ConnectionFactory"); 66 assertTrue(lookup != null); 67 assertTrue(lookup instanceof ActiveMQConnectionFactory); 68 } 69 }