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.core.prefs;
21  
22  
23  import javax.naming.NamingException;
24  
25  import org.apache.directory.server.constants.ServerDNConstants;
26  import org.apache.directory.server.core.prefs.PreferencesUtils;
27  import org.apache.directory.shared.ldap.name.LdapDN;
28  
29  import junit.framework.TestCase;
30  
31  
32  /**
33   * Test caseses for preference utility methods.
34   *
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   * @version $Rev: 603104 $
37   */
38  public class PreferencesUtilsTest extends TestCase
39  {
40      /**
41       * Tests to confirm the toSysDn() method can translate an absolute
42       * preference node path into an LDAP distinguished name.
43       *
44       * @throws NamingException if there are problems transforming the name
45       */
46      public void testToSysDn() throws NamingException
47      {
48          // simple test
49          String expectedDN = "prefNodeName=kerberos,prefNodeName=apache,prefNodeName=org," +
50                  ServerDNConstants.SYSPREFROOT_SYSTEM_DN;
51          
52          String test = "/org/apache/kerberos/";
53  
54          LdapDN dn = ( LdapDN ) PreferencesUtils.toSysDn( test );
55  
56          assertEquals( expectedDN, dn.getUpName() );
57  
58          // simple test without trailing '/'
59  
60          test = "/org/apache/kerberos";
61  
62          dn = ( LdapDN ) PreferencesUtils.toSysDn( test );
63  
64          assertEquals( expectedDN, dn.getUpName() );
65  
66          // basis condition tests
67  
68          test = "/";
69  
70          dn = ( LdapDN ) PreferencesUtils.toSysDn( test );
71  
72          assertEquals( ServerDNConstants.SYSPREFROOT_SYSTEM_DN, dn.getUpName() );
73  
74          // endpoint tests
75  
76          test = "//////";
77  
78          dn = ( LdapDN ) PreferencesUtils.toSysDn( test );
79  
80          assertEquals( ServerDNConstants.SYSPREFROOT_SYSTEM_DN, dn.getUpName() );
81  
82      }
83  }