01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.test.jndi;
18:
19: import java.io.File;
20: import java.util.Hashtable;
21: import javax.naming.Context;
22: import javax.naming.InitialContext;
23:
24: import junit.framework.TestCase;
25: import org.compass.core.Compass;
26: import org.compass.core.config.CompassConfiguration;
27:
28: /**
29: * @author kimchy
30: */
31: public class JNDITests extends TestCase {
32:
33: public void testJNDI() throws Exception {
34: File testJndiDir = new File("target/jndi");
35: testJndiDir.mkdirs();
36: String jndiPath = testJndiDir.toURL().toExternalForm();
37: CompassConfiguration conf = new CompassConfiguration()
38: .configure("/org/compass/core/test/jndi/compass.cfg.xml");
39: Compass sessionFactory = conf.buildCompass();
40:
41: Hashtable env = new Hashtable(11);
42: env.put(Context.INITIAL_CONTEXT_FACTORY,
43: "com.sun.jndi.fscontext.RefFSContextFactory");
44: env.put(Context.PROVIDER_URL, jndiPath);
45: Context initCtx = new InitialContext(env);
46: Compass jndiFactory = (Compass) initCtx
47: .lookup("compass/CompassFactory");
48: assertNotNull(jndiFactory);
49:
50: sessionFactory.close();
51: }
52:
53: }
|