1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.configuration;
21
22
23 import junit.framework.Assert;
24 import org.apache.directory.server.core.DirectoryService;
25 import org.apache.directory.server.core.entry.DefaultServerEntry;
26 import org.apache.directory.server.core.entry.ServerEntry;
27 import org.apache.directory.server.core.integ.CiRunner;
28 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
29 import org.apache.directory.server.core.jndi.CoreContextFactory;
30 import org.apache.directory.server.core.partition.Partition;
31 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
32 import org.apache.directory.shared.ldap.name.LdapDN;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35
36 import javax.naming.Context;
37 import javax.naming.InitialContext;
38 import javax.naming.NameNotFoundException;
39 import java.util.Hashtable;
40
41
42
43
44
45
46
47
48 @RunWith ( CiRunner.class )
49 public class PartitionConfigurationIT
50 {
51 public static DirectoryService service;
52
53
54 @Test
55 public void testAddAndRemove() throws Exception
56 {
57 Partition partition = new JdbmPartition();
58 partition.setId( "removable" );
59 partition.setSuffix( "ou=removable" );
60
61
62 service.addPartition( partition );
63
64 LdapDN suffixDn = new LdapDN( "ou=removable" );
65 suffixDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
66 ServerEntry ctxEntry = new DefaultServerEntry( service.getRegistries(), suffixDn );
67 ctxEntry.put( "objectClass", "top" );
68 ctxEntry.get( "objectClass" ).add( "organizationalUnit" );
69 ctxEntry.put( "ou", "removable" );
70 partition.add( new AddOperationContext( service.getAdminSession(), ctxEntry ) );
71
72 Hashtable<String,Object> env = new Hashtable<String,Object>();
73 env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
74 env.put( DirectoryService.JNDI_KEY, service );
75 env.put( Context.SECURITY_CREDENTIALS, "secret" );
76 env.put( Context.SECURITY_AUTHENTICATION, "simple" );
77 env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
78 Context ctx = new InitialContext( env );
79 Assert.assertNotNull( ctx.lookup( "ou=removable" ) );
80
81
82 service.removePartition( partition );
83 ctx = new InitialContext( env );
84 try
85 {
86 ctx.lookup( "ou=removable" );
87 Assert.fail( "NameNotFoundException should be thrown." );
88 }
89 catch ( NameNotFoundException e )
90 {
91
92 }
93 }
94 }