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.common.exception.LdapNameNotFoundException;
21 import org.apache.ldap.server.AbstractCoreTest;
22
23 import javax.naming.NamingException;
24 import javax.naming.directory.*;
25
26
27 /***
28 * Tests the destroyContext methods of the provider.
29 *
30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31 * @version $Rev: 165059 $
32 */
33 public class DestroyContextTest extends AbstractCoreTest
34 {
35 protected void setUp() throws Exception
36 {
37 super.setUp();
38
39
40
41
42 Attributes attributes = new BasicAttributes();
43 Attribute attribute = new BasicAttribute( "objectClass" );
44 attribute.add( "top" );
45 attribute.add( "organizationalUnit" );
46 attributes.put( attribute );
47 attributes.put( "ou", "testing00" );
48 DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes );
49 assertNotNull( ctx );
50
51 ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
52 assertNotNull( ctx );
53
54 attributes = ctx.getAttributes( "" );
55 assertNotNull( attributes );
56 assertEquals( "testing00", attributes.get( "ou" ).get() );
57 attribute = attributes.get( "objectClass" );
58 assertNotNull( attribute );
59 assertTrue( attribute.contains( "top" ) );
60 assertTrue( attribute.contains( "organizationalUnit" ) );
61
62
63
64
65 attributes = new BasicAttributes();
66 attribute = new BasicAttribute( "objectClass" );
67 attribute.add( "top" );
68 attribute.add( "organizationalUnit" );
69 attributes.put( attribute );
70 attributes.put( "ou", "testing01" );
71 ctx = sysRoot.createSubcontext( "ou=testing01", attributes );
72 assertNotNull( ctx );
73
74 ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
75 assertNotNull( ctx );
76
77 attributes = ctx.getAttributes( "" );
78 assertNotNull( attributes );
79 assertEquals( "testing01", attributes.get( "ou" ).get() );
80 attribute = attributes.get( "objectClass" );
81 assertNotNull( attribute );
82 assertTrue( attribute.contains( "top" ) );
83 assertTrue( attribute.contains( "organizationalUnit" ) );
84
85
86
87
88 attributes = new BasicAttributes();
89 attribute = new BasicAttribute( "objectClass" );
90 attribute.add( "top" );
91 attribute.add( "organizationalUnit" );
92 attributes.put( attribute );
93 attributes.put( "ou", "testing02" );
94 ctx = sysRoot.createSubcontext( "ou=testing02", attributes );
95 assertNotNull( ctx );
96
97 ctx = ( DirContext ) sysRoot.lookup( "ou=testing02" );
98 assertNotNull( ctx );
99
100 attributes = ctx.getAttributes( "" );
101 assertNotNull( attributes );
102 assertEquals( "testing02", attributes.get( "ou" ).get() );
103 attribute = attributes.get( "objectClass" );
104 assertNotNull( attribute );
105 assertTrue( attribute.contains( "top" ) );
106 assertTrue( attribute.contains( "organizationalUnit" ) );
107
108
109
110
111 ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
112
113 attributes = new BasicAttributes();
114 attribute = new BasicAttribute( "objectClass" );
115 attribute.add( "top" );
116 attribute.add( "organizationalUnit" );
117 attributes.put( attribute );
118 attributes.put( "ou", "subtest" );
119 ctx = ctx.createSubcontext( "ou=subtest", attributes );
120 assertNotNull( ctx );
121
122 ctx = ( DirContext ) sysRoot.lookup( "ou=subtest,ou=testing01" );
123 assertNotNull( ctx );
124
125 attributes = ctx.getAttributes( "" );
126 assertNotNull( attributes );
127 assertEquals( "subtest", attributes.get( "ou" ).get() );
128 attribute = attributes.get( "objectClass" );
129 assertNotNull( attribute );
130 assertTrue( attribute.contains( "top" ) );
131 assertTrue( attribute.contains( "organizationalUnit" ) );
132 }
133
134
135 /***
136 * Tests the creation and subsequent read of a new JNDI context under the
137 * system context root.
138 *
139 * @throws NamingException if there are failures
140 */
141 public void testDestroyContext() throws NamingException
142 {
143
144
145
146 sysRoot.destroySubcontext( "ou=testing00");
147
148 try
149 {
150 sysRoot.lookup( "ou=testing00" );
151 fail( "ou=testing00, ou=system should not exist" );
152 }
153 catch( NamingException e )
154 {
155 assertTrue( e instanceof LdapNameNotFoundException );
156 }
157
158
159
160
161 sysRoot.destroySubcontext( "ou=subtest,ou=testing01");
162
163 try
164 {
165 sysRoot.lookup( "ou=subtest,ou=testing01" );
166 fail( "ou=subtest,ou=testing01,ou=system should not exist" );
167 }
168 catch( NamingException e )
169 {
170 assertTrue( e instanceof LdapNameNotFoundException );
171 }
172
173
174
175
176 sysRoot.destroySubcontext( "ou=testing01");
177
178 try
179 {
180 sysRoot.lookup( "ou=testing01" );
181 fail( "ou=testing01, ou=system should not exist" );
182 }
183 catch( NamingException e )
184 {
185 assertTrue( e instanceof LdapNameNotFoundException );
186 }
187
188
189
190
191
192 sysRoot.destroySubcontext( "ou=testing02");
193
194 try
195 {
196 sysRoot.lookup( "ou=testing02" );
197 fail( "ou=testing02, ou=system should not exist" );
198 }
199 catch( NamingException e )
200 {
201 assertTrue( e instanceof LdapNameNotFoundException );
202 }
203 }
204
205
206 }