1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.ldap;
21  
22  
23  import org.junit.Test;
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertNull;
26  import static org.junit.Assert.assertTrue;
27  
28  import org.apache.directory.server.ldap.ExtendedOperationHandler;
29  import org.apache.directory.server.ldap.LdapService;
30  import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
31  import org.apache.directory.server.ldap.handlers.bind.plain.PlainMechanismHandler;
32  import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
33  import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
34  
35  import java.util.List;
36  import java.util.ArrayList;
37  import java.util.Map;
38  import java.util.HashMap;
39  
40  
41  /**
42   * Test to confirm correct behavoir for settings on LdapService bean.
43   *
44   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45   * @version $$Rev$$
46   */
47  public class LdapServerSettingsTest
48  {
49      @Test
50      public void testAddExtendedOperationHandler() throws Exception
51      {
52          LdapService server = new LdapService();
53          StartTlsHandler handler = new StartTlsHandler();
54          server.addExtendedOperationHandler( handler );
55          assertEquals( handler, server.getExtendedOperationHandler( handler.getOid() ) );
56          server.removeExtendedOperationHandler( handler.getOid() );
57          assertNull( server.getExtendedOperationHandler( handler.getOid() ) );
58      }
59  
60  
61      @Test
62      public void testSetExtendedOperationHandlers()
63      {
64          LdapService server = new LdapService();
65          StartTlsHandler handler = new StartTlsHandler();
66          List<ExtendedOperationHandler> handlers = new ArrayList<ExtendedOperationHandler>();
67          handlers.add( handler );
68          server.setExtendedOperationHandlers( handlers );
69          assertEquals( handler, server.getExtendedOperationHandler( handler.getOid() ) );
70          server.removeExtendedOperationHandler( handler.getOid() );
71          assertNull( server.getExtendedOperationHandler( handler.getOid() ) );
72      }
73  
74  
75      @Test
76      public void testSetSaslMechanismHandlers()
77      {
78          LdapService server = new LdapService();
79          Map<String, MechanismHandler> handlers = new HashMap<String,MechanismHandler>();
80          MechanismHandler handler = new PlainMechanismHandler();
81          handlers.put( SupportedSaslMechanisms.PLAIN, handler );
82          server.setSaslMechanismHandlers( handlers );
83          assertEquals( handler, server.getMechanismHandler( SupportedSaslMechanisms.PLAIN ) );
84          assertTrue( server.getSupportedMechanisms().contains( SupportedSaslMechanisms.PLAIN ) );
85          server.removeSaslMechanismHandler( SupportedSaslMechanisms.PLAIN );
86          assertNull( server.getMechanismHandler( SupportedSaslMechanisms.PLAIN ) );
87      }
88  }