1 17 18 package org.apache.geronimo.directory; 19 20 import junit.framework.TestCase; 21 import org.apache.geronimo.system.serverinfo.BasicServerInfo; 22 import org.apache.geronimo.system.serverinfo.ServerInfo; 23 24 import javax.naming.Context ; 25 import javax.naming.NameClassPair ; 26 import javax.naming.NamingEnumeration ; 27 import javax.naming.directory.DirContext ; 28 import javax.naming.directory.InitialDirContext ; 29 import java.net.URL ; 30 import java.util.HashSet ; 31 import java.util.Hashtable ; 32 33 public class RunningTest extends TestCase { 34 35 private static final String PRINCIPAL = "uid=admin,ou=system"; 36 private static final String CREDENTIALS = "secret"; 37 private ClassLoader cl = this.getClass().getClassLoader(); 38 39 private DirectoryGBean directory; 40 41 public void testRunning() throws Exception { 42 43 Hashtable env = new Hashtable (); 44 env.put(Context.PROVIDER_URL, "ldap://localhost:9389"); 45 String ldapContextFactory = System.getProperty("initial.context.factory"); 46 if (ldapContextFactory == null) ldapContextFactory = "com.sun.jndi.ldap.LdapCtxFactory"; 47 env.put(Context.INITIAL_CONTEXT_FACTORY, 48 ldapContextFactory); 49 env.put( Context.SECURITY_PRINCIPAL, PRINCIPAL); 51 env.put( Context.SECURITY_CREDENTIALS, CREDENTIALS); 52 DirContext ctx = new InitialDirContext (env); 53 54 HashSet set = new HashSet (); 58 59 NamingEnumeration list = ctx.list("ou=system"); 60 61 while (list.hasMore()) { 62 NameClassPair ncp = (NameClassPair ) list.next(); 63 set.add(ncp.getName()); 64 } 65 66 assertTrue(set.contains("uid=admin")); 67 assertTrue( set.contains( "ou=users" ) ); 68 assertTrue( set.contains( "ou=groups" ) ); 69 assertTrue( set.contains( "ou=configuration" ) ); 70 assertTrue( set.contains( "prefNodeName=sysPrefRoot" ) ); 71 72 } 73 74 protected void setUp() throws Exception { 75 76 URL configURL = cl.getResource("directory.xml"); 77 if (configURL == null) { 78 throw new Exception ("Can't find config file on classpath"); 79 } 80 String path = configURL.getPath(); 81 path = path.substring(0, path.lastIndexOf("/")); 82 ServerInfo serverInfo = new BasicServerInfo(path); 83 directory = new DirectoryGBean(cl, null, true, "directory.xml", serverInfo); 84 directory.setEnableNetworking(true); 85 directory.setPort(9389); 86 directory.setProviderURL("ou=system"); 87 directory.setSecurityAuthentication("simple"); 88 directory.setSecurityCredentials(CREDENTIALS); 89 directory.setSecurityPrincipal(PRINCIPAL); 90 directory.doStart(); 91 92 93 } 94 95 protected void tearDown() throws Exception { 96 directory.doStop(); 97 } 98 99 } 100 | Popular Tags |