Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 65542 invoked from network); 25 Jan 2005 05:48:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 25 Jan 2005 05:48:01 -0000 Received: (qmail 73723 invoked by uid 500); 25 Jan 2005 05:48:00 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 73683 invoked by uid 500); 25 Jan 2005 05:48:00 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: directory-dev@incubator.apache.org Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 73669 invoked by uid 99); 25 Jan 2005 05:48:00 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 24 Jan 2005 21:47:59 -0800 Received: (qmail 65486 invoked by uid 65534); 25 Jan 2005 05:47:58 -0000 Date: 25 Jan 2005 05:47:58 -0000 Message-ID: <20050125054758.65479.qmail@minotaur.apache.org> From: psteitz@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: r126349 - /incubator/directory/naming/trunk/naming-core/src/test/org/apache/naming/NamingFactoryTest.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: psteitz Date: Mon Jan 24 21:47:55 2005 New Revision: 126349 URL: http://svn.apache.org/viewcvs?view=rev&rev=126349 Log: Initial Commit Added: incubator/directory/naming/trunk/naming-core/src/test/org/apache/naming/NamingFactoryTest.java Added: incubator/directory/naming/trunk/naming-core/src/test/org/apache/naming/NamingFactoryTest.java Url: http://svn.apache.org/viewcvs/incubator/directory/naming/trunk/naming-core/src/test/org/apache/naming/NamingFactoryTest.java?view=auto&rev=126349 ============================================================================== --- (empty file) +++ incubator/directory/naming/trunk/naming-core/src/test/org/apache/naming/NamingFactoryTest.java Mon Jan 24 21:47:55 2005 @@ -0,0 +1,83 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * 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.apache.naming; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + + +/** + * Unit tests for NamingFactory. + * + * @version $Revision: 123481 $ $Date: 2003/11/30 05:36:07 $ + */ +public class NamingFactoryTest extends TestCase { + + public NamingFactoryTest(String name) { + super(name); + System.setProperty(Context.INITIAL_CONTEXT_FACTORY, + "org.apache.naming.NamingContextFactory"); + } + + public static void main(String[] args) { + TestRunner.run(suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite(NamingFactoryTest.class); + suite.setName("Naming Factory Tests"); + return suite; + } + + public void testGlobal() throws Exception { + Context initialContext = new InitialContext(new Hashtable()); + initialContext.bind("foo", "bar"); + assertNotNull("global context stored", + ContextBindings.getContext(NamingContextFactory.DEFAULT_NAME)); + Context ctx2 = new InitialContext(new Hashtable()); + assertEquals("global context retrieved","bar", initialContext.lookup("foo")); + ctx2.unbind("foo"); + ContextBindings.unbindContext(NamingContextFactory.DEFAULT_NAME); + } + + public void testNamed() throws Exception { + Hashtable env = new Hashtable(); + env.put(NamingContextFactory.NAME, "app1"); + Context initialContext = new InitialContext(env); + initialContext.bind("foo", "bar"); + assertNotNull("named context stored", + ContextBindings.getContext("app1")); + Context ctx2 = new InitialContext(env); + assertEquals("named context retrieved","bar", initialContext.lookup("foo")); + env.put(NamingContextFactory.NAME, "app2"); + Context ctx3 = new InitialContext(env); + try { + ctx3.lookup("foo"); + fail("Expecting NamingException"); + } catch (NamingException ex) { } + initialContext.unbind("foo"); + ContextBindings.unbindContext("app1"); + ContextBindings.unbindContext("app2"); + } +}