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.yoko;
17:
18: import java.util.Properties;
19:
20: import org.apache.geronimo.corba.NameService;
21:
22: import junit.framework.TestCase;
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.apache.geronimo.system.serverinfo.ServerInfo;
26: import org.apache.geronimo.system.serverinfo.BasicServerInfo;
27: import org.omg.CORBA.ORB;
28: import org.omg.CosNaming.NameComponent;
29: import org.omg.CosNaming.NamingContextExt;
30: import org.omg.CosNaming.NamingContextExtHelper;
31:
32: /**
33: * @version $Revision: 452600 $ $Date: 2006-10-03 12:29:42 -0700 (Tue, 03 Oct 2006) $
34: */
35: public class NameServiceTest extends TestCase {
36: private static final Log log = LogFactory
37: .getLog(NameServiceTest.class);
38: private ORB orb;
39: private NameService nameService;
40:
41: protected void setUp() throws Exception {
42: // before we do anything make sure the sun orb is present
43: try {
44: getClass()
45: .getClassLoader()
46: .loadClass(
47: "org.apache.yoko.orb.CosNaming.tnaming.TransientNameService");
48: } catch (ClassNotFoundException e) {
49: log
50: .info("Yoko orb is not present in this vm, so this test can't run");
51: return;
52: }
53:
54: String tmpDir = System.getProperty("java.io.tmpdir");
55: ServerInfo serverInfo = new BasicServerInfo(tmpDir);
56:
57: ORBConfigAdapter adapter = new ORBConfigAdapter();
58: // make sure all system properties are initialized.
59: adapter.doStart();
60: nameService = new NameService(serverInfo, adapter, "localhost",
61: 8050);
62: nameService.doStart();
63:
64: // create the ORB
65: Properties properties = new Properties();
66: String[] initArgs = { "-ORBInitRef",
67: "NameService=" + nameService.getURI() };
68: orb = ORB.init(initArgs, properties);
69: }
70:
71: protected void tearDown() throws Exception {
72: if (nameService == null) {
73: return;
74: }
75: orb.destroy();
76: nameService.doStop();
77: }
78:
79: public void testOrb() throws Exception {
80: if (nameService == null) {
81: return;
82: }
83:
84: NamingContextExt ctx = NamingContextExtHelper.narrow(orb
85: .resolve_initial_references("NameService"));
86: NamingContextExt rootNamingContext = ctx;
87: NameComponent name[] = ctx.to_name("foo/bar/baz");
88: for (int i = 0; i < name.length; i++) {
89: NameComponent nameComponent = name[i];
90: ctx = NamingContextExtHelper
91: .narrow(ctx
92: .bind_new_context(new NameComponent[] { nameComponent }));
93: }
94: ctx.rebind(ctx.to_name("plan"), rootNamingContext);
95: }
96: }
|