1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.jndi;
18
19
20 import org.apache.ldap.server.AbstractAdminTestCase;
21
22 import javax.naming.directory.*;
23
24
25 /***
26 * Tests the use of extensible objects.
27 *
28 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
29 * @version $Rev$
30 */
31 public class ExtensibleObjectTest extends AbstractAdminTestCase
32 {
33 public void testExtensibleObjectModify() throws Exception
34 {
35 Attributes attributes = new BasicAttributes( true );
36 Attribute attribute = new BasicAttribute( "objectClass" );
37 attribute.add( "top" );
38 attribute.add( "organizationalUnit" );
39 attributes.put( attribute );
40 attributes.put( "ou", "testing00" );
41 DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
42 assertNotNull( ctx );
43
44 ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
45 assertNotNull( ctx );
46
47 attributes = ctx.getAttributes( "" );
48 assertNotNull( attributes );
49 assertEquals( "testing00", attributes.get( "ou" ).get() );
50 attribute = attributes.get( "objectClass" );
51 assertNotNull( attribute );
52 assertTrue( attribute.contains( "top" ) );
53 assertTrue( attribute.contains( "organizationalUnit" ) );
54
55 Attributes newattribs = new BasicAttributes( true );
56 Attribute freeform = new BasicAttribute( "freeform" );
57 freeform.add( "testing" );
58 newattribs.put( freeform );
59 Attribute objectClass = new BasicAttribute( "objectClass" );
60 objectClass.add( "top" );
61 objectClass.add( "extensibleObject" );
62 objectClass.add( "organizationalUnit" );
63 newattribs.put( objectClass );
64 ctx.modifyAttributes( "", DirContext.REPLACE_ATTRIBUTE, newattribs );
65
66 attributes = ctx.getAttributes( "" );
67 assertNotNull( attributes );
68 assertEquals( "testing00", attributes.get( "ou" ).get() );
69 attribute = attributes.get( "objectClass" );
70 assertNotNull( attribute );
71 assertTrue( attribute.contains( "top" ) );
72 assertTrue( attribute.contains( "organizationalUnit" ) );
73 assertTrue( attribute.contains( "extensibleObject" ) );
74 attribute = attributes.get( "freeform" );
75 assertTrue( attribute.contains( "testing" ) );
76 }
77
78 public void testExtensibleObjectAdd() throws Exception
79 {
80 Attributes attributes = new BasicAttributes( true );
81 Attribute attribute = new BasicAttribute( "objectClass" );
82 attribute.add( "top" );
83 attribute.add( "extensibleObject" );
84 attribute.add( "organizationalUnit" );
85 attributes.put( attribute );
86 attributes.put( "ou", "testing00" );
87 attributes.put( "freeform", "testing" );
88 DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
89 assertNotNull( ctx );
90
91 ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
92 assertNotNull( ctx );
93
94 attributes = ctx.getAttributes( "" );
95 assertNotNull( attributes );
96 assertEquals( "testing00", attributes.get( "ou" ).get() );
97 attribute = attributes.get( "objectClass" );
98 assertNotNull( attribute );
99 assertTrue( attribute.contains( "top" ) );
100 assertTrue( attribute.contains( "extensibleObject" ) );
101 assertTrue( attribute.contains( "organizationalUnit" ) );
102 attribute = attributes.get( "freeform" );
103 assertTrue( attribute.contains( "testing" ) );
104 }
105 }