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.normalization;
21  
22  
23  import org.apache.directory.server.core.DirectoryService;
24  import org.apache.directory.server.core.integ.CiRunner;
25  import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.assertTrue;
28  import static org.junit.Assert.assertNotNull;
29  import org.junit.Test;
30  import org.junit.runner.RunWith;
31  
32  import javax.naming.directory.Attribute;
33  import javax.naming.directory.Attributes;
34  import javax.naming.directory.BasicAttributes;
35  import javax.naming.ldap.LdapContext;
36  
37  
38  
39  /**
40   * Test cases for the normalization service.
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   * @version $Rev: 691077 $
44   */
45  @RunWith ( CiRunner.class )
46  public final class NormalizationServiceIT
47  {
48      public static DirectoryService service;
49  
50  
51      @Test
52      public void testDireve308Example() throws Exception
53      {
54          /*
55  
56          Use @Ldif to load this data but for now we can do it with code.
57  
58  dn: ou=direct report view,ou=system
59  objectClass: organizationalUnit
60  ou: direct report view
61  
62  dn: ou=corporate category\, operations,ou=direct report view,ou=system
63  objectClass: organizationalUnit
64  ou: corporate category\, operations
65  
66           */
67  
68          LdapContext sysRoot = getSystemContext( service );
69  
70          Attributes attrs = new BasicAttributes( "objectClass", "organizationalUnit", true );
71          attrs.put( "ou", "direct report view" );
72          sysRoot.createSubcontext( "ou=direct report view", attrs );
73  
74          attrs = new BasicAttributes( "objectClass", "organizationalUnit", true );
75          attrs.put( "ou", "corporate category\\, operations" );
76          sysRoot.createSubcontext( "ou=corporate category\\, operations,ou=direct report view", attrs );
77  
78          attrs = sysRoot.getAttributes( "ou=corporate category\\, operations,ou=direct report view" );
79          assertNotNull( attrs );
80          Attribute ou = attrs.get( "ou" );
81          assertEquals( "corporate category, operations", ou.get() );
82          Attribute oc = attrs.get( "objectClass" );
83          assertTrue( oc.contains( "top" ) );
84          assertTrue( oc.contains( "organizationalUnit" ) );
85      }
86  }