1   /*
2    * Copyright (c) 2004 Solarsis Group LLC.
3    *
4    * Licensed under the Open Software License, Version 2.1 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://opensource.org/licenses/osl-2.1.php
9    *
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 org.apache.ldap.server.jndi;
17  
18  
19  import org.apache.ldap.server.AbstractAdminTestCase;
20  
21  import javax.naming.directory.*;
22  
23  
24  /***
25   * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
26   * @version $Rev$
27   */
28  public class ExtensibleObjectTest extends AbstractAdminTestCase
29  {
30      public void testExtensibleObjectModify() throws Exception
31      {
32          Attributes attributes = new BasicAttributes( true );
33          Attribute attribute = new BasicAttribute( "objectClass" );
34          attribute.add( "top" );
35          attribute.add( "organizationalUnit" );
36          attributes.put( attribute );
37          attributes.put( "ou", "testing00" );
38          DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
39          assertNotNull( ctx );
40  
41          ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
42          assertNotNull( ctx );
43  
44          attributes = ctx.getAttributes( "" );
45          assertNotNull( attributes );
46          assertEquals( "testing00", attributes.get( "ou" ).get() );
47          attribute = attributes.get( "objectClass" );
48          assertNotNull( attribute );
49          assertTrue( attribute.contains( "top" ) );
50          assertTrue( attribute.contains( "organizationalUnit" ) );
51          
52          Attributes newattribs = new BasicAttributes( true );
53          Attribute freeform = new BasicAttribute( "freeform" );
54          freeform.add( "testing" );
55          newattribs.put( freeform );
56          Attribute objectClass = new BasicAttribute( "objectClass" );
57          objectClass.add( "top" );
58          objectClass.add( "extensibleObject" );
59          objectClass.add( "organizationalUnit" );
60          newattribs.put( objectClass );
61          ctx.modifyAttributes( "", DirContext.REPLACE_ATTRIBUTE, newattribs );
62  
63          attributes = ctx.getAttributes( "" );
64          assertNotNull( attributes );
65          assertEquals( "testing00", attributes.get( "ou" ).get() );
66          attribute = attributes.get( "objectClass" );
67          assertNotNull( attribute );
68          assertTrue( attribute.contains( "top" ) );
69          assertTrue( attribute.contains( "organizationalUnit" ) );
70          assertTrue( attribute.contains( "extensibleObject" ) );
71          attribute = attributes.get( "freeform" );
72          assertTrue( attribute.contains( "testing" ) );
73      }
74  
75      public void testExtensibleObjectAdd() throws Exception
76      {
77          Attributes attributes = new BasicAttributes( true );
78          Attribute attribute = new BasicAttribute( "objectClass" );
79          attribute.add( "top" );
80          attribute.add( "extensibleObject" );
81          attribute.add( "organizationalUnit" );
82          attributes.put( attribute );
83          attributes.put( "ou", "testing00" );
84          attributes.put( "freeform", "testing" );
85          DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
86          assertNotNull( ctx );
87  
88          ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
89          assertNotNull( ctx );
90  
91          attributes = ctx.getAttributes( "" );
92          assertNotNull( attributes );
93          assertEquals( "testing00", attributes.get( "ou" ).get() );
94          attribute = attributes.get( "objectClass" );
95          assertNotNull( attribute );
96          assertTrue( attribute.contains( "top" ) );
97          assertTrue( attribute.contains( "extensibleObject" ) );
98          assertTrue( attribute.contains( "organizationalUnit" ) );
99          attribute = attributes.get( "freeform" );
100         assertTrue( attribute.contains( "testing" ) );
101     }
102 }