/** 
 * 
 * Copyright 2004 Hiram Chirino
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/
package org.activemq.jndi;
import java.io.File;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;

import junit.framework.TestCase;

import org.activemq.ActiveMQConnectionFactory;
/**
 * Test that the admin objects can be stored and looked up in JNDI providers.
 * 
 * @version $Revision: 1.1.1.1 $
 */
public class AdminObjectTest extends TestCase {
	Context fsContext;
	protected void setUp() {
		try {
			File tempDir = File.createTempFile("fsjndi", ".dir");
			tempDir.delete();
			tempDir = tempDir.getCanonicalFile();
			tempDir.mkdirs();
			Hashtable env = new Hashtable();
			env.put(Context.INITIAL_CONTEXT_FACTORY,
					"com.sun.jndi.fscontext.RefFSContextFactory");
			env.put(Context.PROVIDER_URL, tempDir.toURL().toExternalForm());
			fsContext = new InitialContext(env);
		} catch (Exception e) {
            e.printStackTrace();
		}
	}
	protected void tearDown() throws Exception {
		if (fsContext != null)
			fsContext.close();
	}
	public void testConnectionFactory() throws NamingException, Exception {
		
		if( fsContext == null ){
			return;
        }
		
		ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
		fsContext.rebind("ConnectionFactory", cf);
		Object lookup = fsContext.lookup("ConnectionFactory");
		assertTrue(lookup != null);
		assertTrue(lookup instanceof ActiveMQConnectionFactory);
	}
}