1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.configuration;
18
19
20 import java.util.Hashtable;
21
22 import javax.naming.Context;
23 import javax.naming.InitialContext;
24 import javax.naming.NameNotFoundException;
25 import javax.naming.directory.Attributes;
26 import javax.naming.directory.BasicAttributes;
27
28 import junit.framework.Assert;
29
30 import org.apache.ldap.server.AbstractAdminTestCase;
31 import org.apache.ldap.server.jndi.CoreContextFactory;
32 import org.apache.ldap.server.partition.impl.btree.jdbm.JdbmContextPartition;
33
34
35 /***
36 * Tests {@link AddContextPartitionConfiguration} and
37 * {@link RemoveContextPartitionConfiguration} works correctly.
38 *
39 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40 * @version $Rev: 264732 $
41 */
42 public class ContextPartitionConfigurationTest extends AbstractAdminTestCase
43 {
44 public ContextPartitionConfigurationTest()
45 {
46 }
47
48 public void testAddAndRemove() throws Exception
49 {
50 MutableContextPartitionConfiguration partitionCfg =
51 new MutableContextPartitionConfiguration();
52 partitionCfg.setName( "removable" );
53 partitionCfg.setSuffix( "ou=removable" );
54 Attributes ctxEntry = new BasicAttributes( true );
55 ctxEntry.put( "objectClass", "top" );
56 ctxEntry.put( "ou", "removable" );
57 partitionCfg.setContextEntry( ctxEntry );
58 partitionCfg.setContextPartition( new JdbmContextPartition() );
59
60
61 AddContextPartitionConfiguration addCfg =
62 new AddContextPartitionConfiguration( partitionCfg );
63
64 Hashtable env = new Hashtable();
65 env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
66 env.putAll( addCfg.toJndiEnvironment() );
67
68 Context ctx = new InitialContext( env );
69 Assert.assertNotNull( ctx.lookup( "ou=removable" ) );
70
71
72 RemoveContextPartitionConfiguration removeCfg =
73 new RemoveContextPartitionConfiguration( "ou=removable" );
74 env.putAll( removeCfg.toJndiEnvironment() );
75
76 ctx = new InitialContext( env );
77 try
78 {
79 ctx.lookup( "ou=removable" );
80 Assert.fail( "NameNotFoundException should be thrown." );
81 }
82 catch( NameNotFoundException e )
83 {
84
85 }
86 }
87 }