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.openejb.client;
17:
18: import java.util.Hashtable;
19:
20: import javax.naming.Context;
21:
22: import org.junit.Test;
23:
24: /**
25: * @version $Rev: 636282 $ $Date: 2008-03-12 04:21:21 -0700 $
26: */
27: public class JNDIContextTest {
28:
29: @Test
30: public void testGetInitialContext() throws Exception {
31: JNDIContext jndiContext = new JNDIContext();
32: Hashtable<String, String> env = new Hashtable<String, String>();
33:
34: assertEquals(jndiContext, "ejbd://localhost:4201");
35:
36: assertEquals(jndiContext, "http://localhost");
37:
38: assertEquals(jndiContext, "anything://localhost:4201");
39:
40: assertEquals(jndiContext, "//localhost:4201");
41:
42: assertEquals(jndiContext, "localhost", "ejbd://localhost:4201");
43:
44: assertEquals(jndiContext, "localhost:4201",
45: "ejbd://localhost:4201");
46:
47: assertEquals(jndiContext, "", "ejbd://localhost:4201");
48:
49: assertEquals(jndiContext, "ejbd://127.0.0.1:4201");
50:
51: assertEquals(jndiContext, "http://127.0.0.1");
52:
53: assertEquals(jndiContext, "anything://127.0.0.1:4201");
54:
55: assertEquals(jndiContext, "//127.0.0.1:4201");
56:
57: assertEquals(jndiContext, "127.0.0.1", "ejbd://127.0.0.1:4201");
58:
59: assertEquals(jndiContext, "127.0.0.1:4201",
60: "ejbd://127.0.0.1:4201");
61:
62: }
63:
64: private void assertEquals(JNDIContext jndiContext,
65: String providerUrl) throws Exception {
66: assertEquals(jndiContext, providerUrl, providerUrl);
67: }
68:
69: private void assertEquals(JNDIContext jndiContext,
70: String providerUrl, String expectedProviderUrl)
71: throws Exception {
72: Hashtable<String, String> env = new Hashtable<String, String>();
73: env.put(Context.PROVIDER_URL, providerUrl);
74: JNDIContext ctx = (JNDIContext) jndiContext
75: .getInitialContext(env);
76: String actualProviderUrl = ctx.addMissingParts(providerUrl);
77: assert expectedProviderUrl.equals(actualProviderUrl) : "Expected "
78: + expectedProviderUrl + " but was " + actualProviderUrl;
79: }
80: }
|