KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > properties > NamingPropertiesTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.geronimo.system.properties;
18
19 import javax.naming.InitialContext JavaDoc;
20 import javax.naming.NamingException JavaDoc;
21
22 import junit.framework.TestCase;
23
24 /**
25  */

26 public class NamingPropertiesTest extends TestCase {
27     private static final String JavaDoc NAMING_FACTORY_INITIAL = "com.sun.jndi.rmi.registry.RegistryContextFactory";
28     private static final String JavaDoc FACTORY_URL_PKGS = "org.apache.geronimo.naming";
29     private static final String JavaDoc PROVIDER_URL = "rmi://localhost:1099";
30
31     public void testNamingFactoryInitial() throws Exception JavaDoc {
32
33         assertNull(this.getClass().getClassLoader().getResource("jndi.properties"));
34
35         try {
36             new InitialContext JavaDoc();
37             System.out.println("Something is wrong, initial context can be constructed");
38 // fail();
39
} catch (NamingException JavaDoc ne) {
40             //expected
41
}
42         assertNull(System.getProperty(NamingProperties.JAVA_NAMING_FACTORY_INITIAL));
43         assertNull(System.getProperty(NamingProperties.JAVA_NAMING_FACTORY_URL_PKGS));
44         assertNull(System.getProperty(NamingProperties.JAVA_NAMING_PROVIDER_URL));
45         NamingProperties namingProperties = new NamingProperties(NAMING_FACTORY_INITIAL, FACTORY_URL_PKGS, PROVIDER_URL);
46         assertEquals(System.getProperty(NamingProperties.JAVA_NAMING_FACTORY_INITIAL), NAMING_FACTORY_INITIAL);
47         assertEquals(System.getProperty(NamingProperties.JAVA_NAMING_FACTORY_URL_PKGS), FACTORY_URL_PKGS);
48         assertEquals(System.getProperty(NamingProperties.JAVA_NAMING_PROVIDER_URL), PROVIDER_URL);
49
50         assertEquals(namingProperties.getNamingFactoryInitial(), NAMING_FACTORY_INITIAL);
51         assertEquals(namingProperties.getNamingFactoryUrlPkgs(), FACTORY_URL_PKGS);
52         assertEquals(namingProperties.getNamingProviderUrl(), PROVIDER_URL);
53
54         try {
55             // the above assumes we're running on a Sun JVM. If we can't load the class first,
56
// we'll skip the attempt at creating the InitialContext. We've already verified that the
57
// system properties have been set to the correct values, so this last bit is largely a formality.
58
Class.forName("NAME_FACTORY_INITIAL");
59             new InitialContext JavaDoc();
60         } catch (ClassNotFoundException JavaDoc e) {
61         }
62     }
63 }
64
Popular Tags