KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > naming > test > PooledInvokerUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.naming.test;
23
24 import java.util.Properties JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NameAlreadyBoundException JavaDoc;
28 import javax.naming.NameClassPair JavaDoc;
29 import javax.naming.NameNotFoundException JavaDoc;
30 import javax.naming.NamingEnumeration JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32
33 import junit.framework.Test;
34 import org.jboss.test.JBossTestCase;
35
36 /** Simple unit tests for the jndi service using the pooled invoker as the
37  * transport detached invoker.
38  * @author Scott.Stark@jboss.org
39  * @version $Revision: 37406 $
40  */

41 public class PooledInvokerUnitTestCase extends JBossTestCase
42 {
43    /**
44     * Constructor for the SimpleUnitTestCase object
45     *
46     * @param name Test name
47     */

48    public PooledInvokerUnitTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52
53    /**
54     * Tests that the second time you create a subcontext you get an exception.
55     *
56     * @exception Exception Description of Exception
57     */

58    public void testCreateSubcontext() throws Exception JavaDoc
59    {
60       getLog().debug("+++ testCreateSubcontext");
61       Properties JavaDoc env = new Properties JavaDoc();
62       env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
63       env.setProperty(Context.PROVIDER_URL, "jnp://localhost:10999/");
64       env.setProperty("jnp.disableDiscovery", "true");
65       InitialContext JavaDoc ctx = new InitialContext JavaDoc(env);
66       ctx.createSubcontext("foo");
67       try
68       {
69          ctx.createSubcontext("foo");
70          fail("Second createSubcontext(foo) did NOT fail");
71       }
72       catch (NameAlreadyBoundException JavaDoc e)
73       {
74          getLog().debug("Second createSubcontext(foo) failed as expected");
75       }
76       ctx.createSubcontext("foo/bar");
77       ctx.unbind("foo/bar");
78       ctx.unbind("foo");
79    }
80
81    /** Lookup a name to test basic connectivity and lookup of a known name
82     *
83     * @throws Exception
84     */

85    public void testLookup() throws Exception JavaDoc
86    {
87       getLog().debug("+++ testLookup");
88       Properties JavaDoc env = new Properties JavaDoc();
89       env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
90       env.setProperty(Context.PROVIDER_URL, "jnp://localhost:10999/");
91       env.setProperty("jnp.disableDiscovery", "true");
92       InitialContext JavaDoc ctx = new InitialContext JavaDoc(env);
93       Object JavaDoc obj = ctx.lookup("");
94       getLog().debug("lookup('') = "+obj);
95    }
96
97    public void testListing() throws Exception JavaDoc
98    {
99       log.debug("+++ testListing");
100       InitialContext JavaDoc ctx = getInitialContext();
101       NamingEnumeration JavaDoc names = ctx.list("");
102       int count = 0;
103       while( names.hasMore() )
104       {
105          NameClassPair JavaDoc ncp = (NameClassPair JavaDoc) names.next();
106          log.info(ncp);
107          count ++;
108       }
109       log.info("list count = "+count);
110       assertTrue("list count > 0 ", count > 0);
111       ctx.close();
112    }
113
114    /** Lookup a name to test basic connectivity and lookup of a known name
115     *
116     * @throws Exception
117     */

118    public void testLookupFailures() throws Exception JavaDoc
119    {
120       log.debug("+++ testLookupFailures");
121       // Look a name that does not exist
122
Properties JavaDoc env = new Properties JavaDoc();
123       env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
124       env.setProperty(Context.PROVIDER_URL, "jnp://localhost:10999/");
125       env.setProperty("jnp.disableDiscovery", "true");
126       InitialContext JavaDoc ctx = new InitialContext JavaDoc(env);
127       try
128       {
129          Object JavaDoc obj = ctx.lookup("__bad_name__");
130          fail("lookup(__bad_name__) should have thrown an exception, obj="+obj);
131       }
132       catch(NameNotFoundException JavaDoc e)
133       {
134          log.debug("lookup(__bad_name__) failed as expected", e);
135       }
136
137       // Do a lookup on an server port that does not exist
138
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
139       env.setProperty(Context.PROVIDER_URL, "jnp://localhost:65535/");
140       env.setProperty("jnp.disableDiscovery", "true");
141       log.debug("Creating InitialContext with env="+env);
142       try
143       {
144          ctx = new InitialContext JavaDoc(env);
145          Object JavaDoc obj = ctx.lookup("");
146          fail("lookup('') should have thrown an exception, obj="+obj);
147       }
148       catch(NamingException JavaDoc e)
149       {
150          log.debug("lookup('') failed as expected", e);
151       }
152    }
153
154    public static Test suite() throws Exception JavaDoc
155    {
156       return getDeploySetup(PooledInvokerUnitTestCase.class, "naming-pooled.sar");
157    }
158
159 }
160
Popular Tags