1   /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.ldap;
17  
18  import junit.framework.TestCase;
19  
20  import org.apache.directory.server.core.jndi.CoreContextFactory;
21  
22  import java.util.Hashtable;
23  
24  
25  /**
26   * @author Luke Taylor
27   * @version $Id: AbstractLdapServerTestCase.java 1968 2007-08-28 15:26:59Z luke_t $
28   */
29  public abstract class AbstractLdapServerTestCase extends TestCase {
30      //~ Static fields/initializers =====================================================================================
31  
32      private static final String ROOT_DN = "dc=acegisecurity,dc=org";
33      protected static final String MANAGER_USER = "cn=manager," + ROOT_DN;
34      protected static final String MANAGER_PASSWORD = "acegisecurity";
35  
36      // External server config
37  //    private static final String PROVIDER_URL = "ldap://gorille:389/"+ROOT_DN;
38  //    private static final String CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
39  //    private static final Hashtable EXTRA_ENV = new Hashtable();
40  
41      // Embedded (non-networked) server config
42      private static final LdapTestServer SERVER = new LdapTestServer();
43      private static final String PROVIDER_URL = ROOT_DN;
44      private static final String CONTEXT_FACTORY = CoreContextFactory.class.getName();
45      private static final Hashtable EXTRA_ENV = SERVER.getConfiguration().toJndiEnvironment();
46  
47      //~ Instance fields ================================================================================================
48  
49      private DefaultInitialDirContextFactory idf;
50  
51      //~ Constructors ===================================================================================================
52  
53      protected AbstractLdapServerTestCase() {
54      }
55  
56      protected AbstractLdapServerTestCase(String string) {
57          super(string);
58      }
59  
60      //~ Methods ========================================================================================================
61  
62      protected DefaultInitialDirContextFactory getInitialCtxFactory() {
63          return idf;
64      }
65  
66      protected void onSetUp() {
67      }
68  
69      public final void setUp() {
70          idf = new DefaultInitialDirContextFactory(PROVIDER_URL);
71          idf.setInitialContextFactory(CONTEXT_FACTORY);
72          idf.setExtraEnvVars(EXTRA_ENV);
73  
74          onSetUp();
75      }
76  }