01: /*
02: * Copyright 2006-2007 The Scriptella Project Team.
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: package scriptella.driver.ldap;
17:
18: import scriptella.AbstractTestCase;
19: import scriptella.configuration.MockConnectionEl;
20: import scriptella.spi.ConnectionParameters;
21: import scriptella.spi.MockDriverContext;
22:
23: import javax.naming.Context;
24: import javax.naming.directory.SearchControls;
25: import java.util.HashMap;
26: import java.util.Hashtable;
27: import java.util.Map;
28:
29: /**
30: * Tests for {@link LdapConnection}.
31: *
32: * @author Fyodor Kupolov
33: * @version 1.0
34: */
35: public class LdapConnectionTest extends AbstractTestCase {
36: private boolean ctxInitialized;
37:
38: /**
39: * Tests if LDAP connection correctly initialized.
40: */
41: public void test() {
42: Map<String, String> params = new HashMap<String, String>();
43: String dn = "dc=scriptella";
44: params.put(LdapConnection.SEARCH_BASEDN_KEY, dn);
45: params.put(LdapConnection.SEARCH_SCOPE_KEY, "subtree");
46: params.put(LdapConnection.FILE_MAXLENGTH_KEY, "100");
47: final String url = "ldap://127.0.0.1:389/";
48: ConnectionParameters cp = new ConnectionParameters(
49: new MockConnectionEl(params, url),
50: new MockDriverContext());
51: ctxInitialized = false;
52: LdapConnection con = new LdapConnection(cp) {
53: @Override
54: protected void initializeContext(
55: Hashtable<String, Object> env) {
56: ctxInitialized = true;
57: //Simple checks if environment has been correctly set up
58: assertEquals(url, env.get(Context.PROVIDER_URL));
59: assertNotNull(env.get(Context.INITIAL_CONTEXT_FACTORY));
60:
61: }
62: };
63: assertEquals(dn, con.getBaseDn());
64: assertEquals(SearchControls.SUBTREE_SCOPE, con
65: .getSearchControls().getSearchScope());
66: assertEquals(100, (long) con.getMaxFileLength());
67: assertTrue(ctxInitialized);
68: }
69: }
|