001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.jndi.tests.javax.naming;
019:
020: import java.io.IOException;
021: import java.util.Enumeration;
022: import java.util.Hashtable;
023:
024: import javax.naming.Context;
025: import javax.naming.InitialContext;
026: import javax.naming.NamingException;
027:
028: import junit.framework.TestCase;
029: import org.apache.harmony.jndi.tests.javax.naming.util.Log;
030:
031: public class InitialContextEnvTest extends TestCase {
032: private static final Log log = new Log(InitialContextEnvTest.class);
033:
034: @Override
035: protected void tearDown() throws Exception {
036: super .tearDown();
037: Log.close();
038: }
039:
040: public void testConstructor_env() throws NamingException,
041: IOException {
042: log.setMethod("testConstructor_env");
043: /*
044: * set properties for environment parameter
045: */
046: Hashtable<String, String> env = new Hashtable<String, String>();
047: env.put(Context.INITIAL_CONTEXT_FACTORY,
048: "dazzle.jndi.testing.spi.DazzleContextFactory");
049: // C type
050: env.put("java.naming.factory.control",
051: "java.naming.factory.control.env");
052: env.put("java.naming.factory.object",
053: "java.naming.factory.object.env");
054: env.put("java.naming.factory.state",
055: "java.naming.factory.state.env");
056: env.put("java.naming.factory.url.pkgs",
057: "java.naming.factory.url.pkgs.env");
058: // F
059: env.put("java.naming.provider.url",
060: "java.naming.provider.url.env");
061: env.put("java.naming.authoritative",
062: "java.naming.authoritative.env");
063: env.put("java.naming.batchsize", "java.naming.batchsize.app1");
064: env.put("java.naming.dns.url", "java.naming.dns.url.env");
065: env.put("java.naming.language", "java.naming.language.env");
066: env.put("java.naming.referral", "java.naming.referral.env");
067: env.put("java.naming.security.authentication",
068: "java.naming.security.authentication.env");
069: env.put("java.naming.security.credentials",
070: "java.naming.security.credentials.env");
071: env.put("java.naming.security.principal",
072: "java.naming.security.principal.env");
073: env.put("java.naming.security.protocol",
074: "java.naming.security.protocol.env");
075:
076: // other
077: env.put("dazzle.jndi.testing.spi.env",
078: "dazzle.jndi.testing.spi.env.env");
079: // junk
080: env.put("env.type", "env.type.env");
081:
082: /*
083: * Set System properties
084: */
085: System
086: .setProperty(Context.INITIAL_CONTEXT_FACTORY,
087: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
088: // C
089: System.setProperty("java.naming.factory.control",
090: "java.naming.factory.control.sys");
091: System.setProperty("java.naming.factory.object",
092: "java.naming.factory.object.sys");
093: System.setProperty("java.naming.factory.state",
094: "java.naming.factory.state.sys");
095: System.setProperty("java.naming.factory.url.pkgs",
096: "java.naming.factory.url.pkgs.sys");
097: // F
098: System.setProperty("java.naming.provider.url",
099: "java.naming.provider.url.sys");
100: System.setProperty("java.naming.authoritative",
101: "java.naming.authoritative.sys");
102: System.setProperty("java.naming.batchsize",
103: "java.naming.batchsize.app1");
104: System.setProperty("java.naming.dns.url",
105: "java.naming.dns.url.sys");
106: System.setProperty("java.naming.language",
107: "java.naming.language.sys");
108: System.setProperty("java.naming.referral",
109: "java.naming.referral.sys");
110: System.setProperty("java.naming.security.authentication",
111: "java.naming.security.authentication.sys");
112: System.setProperty("java.naming.security.credentials",
113: "java.naming.security.credentials.sys");
114: System.setProperty("java.naming.security.principal",
115: "java.naming.security.principal.sys");
116: System.setProperty("java.naming.security.protocol",
117: "java.naming.security.protocol.sys");
118:
119: // other
120: System.setProperty("dazzle.jndi.testing.spi.sys",
121: "dazzle.jndi.testing.spi.sys.sys");
122: // junk
123: System.setProperty("sys.type", "sys.type.sys");
124:
125: InitialContext context = new InitialContext(env);
126:
127: Hashtable<?, ?> props = context.getEnvironment();
128: // printHashtable(props);
129: Hashtable<?, ?> expected = InitialContextLibTest
130: .readAllProps(env);
131: assertEquals(expected, props);
132: }
133:
134: public void testConstructor_env_Ctype() throws NamingException,
135: IOException {
136: log.setMethod("testConstructor_env_Ctype");
137: /*
138: * set properties for environment parameter
139: */
140: Hashtable<String, String> env = new Hashtable<String, String>();
141: env.put(Context.INITIAL_CONTEXT_FACTORY,
142: "dazzle.jndi.testing.spi.DazzleContextFactory");
143: // C type
144: env.put("java.naming.factory.control",
145: "java.naming.factory.control.env");
146: // env.put("java.naming.factory.object",
147: // "java.naming.factory.object.env");
148: // env.put("java.naming.factory.state",
149: // "java.naming.factory.state.env");
150: env.put("java.naming.factory.url.pkgs",
151: "java.naming.factory.url.pkgs.env");
152: // F
153: env.put("java.naming.provider.url",
154: "java.naming.provider.url.env");
155: env.put("java.naming.authoritative",
156: "java.naming.authoritative.env");
157: env.put("java.naming.batchsize", "java.naming.batchsize.app1");
158: env.put("java.naming.dns.url", "java.naming.dns.url.env");
159: env.put("java.naming.language", "java.naming.language.env");
160: env.put("java.naming.referral", "java.naming.referral.env");
161: env.put("java.naming.security.authentication",
162: "java.naming.security.authentication.env");
163: env.put("java.naming.security.credentials",
164: "java.naming.security.credentials.env");
165: env.put("java.naming.security.principal",
166: "java.naming.security.principal.env");
167: env.put("java.naming.security.protocol",
168: "java.naming.security.protocol.env");
169:
170: // other
171: env.put("dazzle.jndi.testing.spi.env",
172: "dazzle.jndi.testing.spi.env.env");
173: // junk
174: env.put("env.type", "env.type.env");
175:
176: /*
177: * Set System properties
178: */
179: System
180: .setProperty(Context.INITIAL_CONTEXT_FACTORY,
181: "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
182: // C
183: System.setProperty("java.naming.factory.control",
184: "java.naming.factory.control.sys");
185: System.setProperty("java.naming.factory.object",
186: "java.naming.factory.object.sys");
187: System.setProperty("java.naming.factory.state",
188: "java.naming.factory.state.sys");
189: System.setProperty("java.naming.factory.url.pkgs",
190: "java.naming.factory.url.pkgs.sys");
191: // F
192: System.setProperty("java.naming.provider.url",
193: "java.naming.provider.url.sys");
194: System.setProperty("java.naming.authoritative",
195: "java.naming.authoritative.sys");
196: System.setProperty("java.naming.batchsize",
197: "java.naming.batchsize.app1");
198: System.setProperty("java.naming.dns.url",
199: "java.naming.dns.url.sys");
200: System.setProperty("java.naming.language",
201: "java.naming.language.sys");
202: System.setProperty("java.naming.referral",
203: "java.naming.referral.sys");
204: System.setProperty("java.naming.security.authentication",
205: "java.naming.security.authentication.sys");
206: System.setProperty("java.naming.security.credentials",
207: "java.naming.security.credentials.sys");
208: System.setProperty("java.naming.security.principal",
209: "java.naming.security.principal.sys");
210: System.setProperty("java.naming.security.protocol",
211: "java.naming.security.protocol.sys");
212:
213: // other
214: System.setProperty("dazzle.jndi.testing.spi.sys",
215: "dazzle.jndi.testing.spi.sys.sys");
216: // junk
217: System.setProperty("sys.type", "sys.type.sys");
218:
219: InitialContext context = new InitialContext(env);
220:
221: Hashtable<?, ?> props = context.getEnvironment();
222: // printHashtable(props);
223: Hashtable<?, ?> expected = InitialContextLibTest
224: .readAllProps(env);
225: assertEquals(expected, props);
226: }
227:
228: void printHashtable(Hashtable<?, ?> env) {
229: // TO DO: Need to remove
230: Enumeration<?> keys = env.keys();
231: while (keys.hasMoreElements()) {
232: Object key = keys.nextElement();
233: log.log(key + "=" + env.get(key));
234: }
235: }
236: }
|