KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URL JavaDoc;
25 import java.net.InetAddress JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import javax.naming.InitialContext JavaDoc;
29
30 import junit.framework.Test;
31
32 import org.jboss.test.JBossTestCase;
33
34 /**
35  * Tests of the JNDIBindingServiceMgr
36  *
37  * @author Scott.Stark@jboss.org
38  * @version $Revision: 37406 $
39  */

40 public class JNDIBindingUnitTestCase extends JBossTestCase
41 {
42    public JNDIBindingUnitTestCase(String JavaDoc name)
43    {
44       super(name);
45    }
46
47    /** Tests of accessing the various types of java:comp entries
48     *
49     * @exception Exception Description of Exception
50     */

51    public void testBindings() throws Exception JavaDoc
52    {
53       InitialContext JavaDoc ctx = getInitialContext();
54       // Test the URL binding
55
URL JavaDoc jbossHome = (URL JavaDoc) ctx.lookup("urls/jboss-home");
56       assertTrue("urls/jboss-home == URL(http://www.jboss.org)",
57          jbossHome.toString().equals("http://www.jboss.org"));
58
59       // Test the InetAddress binding
60
InetAddress JavaDoc localhost = (InetAddress JavaDoc) ctx.lookup("hosts/localhost");
61       InetAddress JavaDoc localhost2 = InetAddress.getByName("127.0.0.1");
62       assertTrue("hosts/localhost InetAddress(127.0.0.1)",
63          localhost.getHostAddress().equals(localhost2.getHostAddress()));
64
65       // Test the InetAddress binding
66
Properties JavaDoc props = (Properties JavaDoc) ctx.lookup("maps/testProps");
67       assertTrue("Properties(key1) == value1", props.getProperty("key1").equals("value1"));
68       assertTrue("Properties(key2) == value2", props.getProperty("key2").equals("value2"));
69    }
70
71    public static Test suite() throws Exception JavaDoc
72    {
73       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
74       URL JavaDoc service = loader.getResource("naming/services/bindings-service.xml");
75       return getDeploySetup(JNDIBindingUnitTestCase.class, service.toString());
76    }
77
78 }
79
Popular Tags