01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.system.properties;
17:
18: import javax.naming.InitialContext;
19: import javax.naming.NamingException;
20:
21: import junit.framework.TestCase;
22:
23: /**
24: */
25: public class NamingPropertiesTest extends TestCase {
26: private static final String NAMING_FACTORY_INITIAL = "com.sun.jndi.rmi.registry.RegistryContextFactory";
27: private static final String FACTORY_URL_PKGS = "org.apache.geronimo.naming";
28: private static final String PROVIDER_URL = "rmi://localhost:1099";
29:
30: public void testNamingFactoryInitial() throws Exception {
31:
32: assertNull(this .getClass().getClassLoader().getResource(
33: "jndi.properties"));
34:
35: try {
36: new InitialContext();
37: System.out
38: .println("Something is wrong, initial context can be constructed");
39: // fail();
40: } catch (NamingException ne) {
41: //expected
42: }
43: assertNull(System
44: .getProperty(NamingProperties.JAVA_NAMING_FACTORY_INITIAL));
45: assertNull(System
46: .getProperty(NamingProperties.JAVA_NAMING_FACTORY_URL_PKGS));
47: assertNull(System
48: .getProperty(NamingProperties.JAVA_NAMING_PROVIDER_URL));
49: NamingProperties namingProperties = new NamingProperties(
50: NAMING_FACTORY_INITIAL, FACTORY_URL_PKGS, PROVIDER_URL);
51: assertEquals(
52: System
53: .getProperty(NamingProperties.JAVA_NAMING_FACTORY_INITIAL),
54: NAMING_FACTORY_INITIAL);
55: assertEquals(
56: System
57: .getProperty(NamingProperties.JAVA_NAMING_FACTORY_URL_PKGS),
58: FACTORY_URL_PKGS);
59: assertEquals(
60: System
61: .getProperty(NamingProperties.JAVA_NAMING_PROVIDER_URL),
62: PROVIDER_URL);
63:
64: assertEquals(namingProperties.getNamingFactoryInitial(),
65: NAMING_FACTORY_INITIAL);
66: assertEquals(namingProperties.getNamingFactoryUrlPkgs(),
67: FACTORY_URL_PKGS);
68: assertEquals(namingProperties.getNamingProviderUrl(),
69: PROVIDER_URL);
70:
71: try {
72: // the above assumes we're running on a Sun JVM. If we can't load the class first,
73: // we'll skip the attempt at creating the InitialContext. We've already verified that the
74: // system properties have been set to the correct values, so this last bit is largely a formality.
75: Class.forName("NAME_FACTORY_INITIAL");
76: new InitialContext();
77: } catch (ClassNotFoundException e) {
78: }
79: }
80: }
|