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.partition;
21
22
23 import java.util.HashMap;
24
25 import org.apache.directory.server.core.DefaultDirectoryService;
26 import org.apache.directory.server.core.DirectoryService;
27 import org.apache.directory.server.core.integ.CiRunner;
28 import org.apache.directory.server.core.integ.DirectoryServiceFactory;
29 import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
30 import org.apache.directory.server.core.integ.annotations.Factory;
31 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
32
33 import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
34
35 import static org.junit.Assert.assertTrue;
36 import static org.junit.Assert.assertNotNull;
37 import static org.junit.Assert.fail;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 import javax.naming.directory.Attribute;
44 import javax.naming.directory.Attributes;
45 import javax.naming.directory.BasicAttributes;
46 import javax.naming.ldap.LdapContext;
47
48
49
50
51
52
53
54
55
56 @RunWith ( CiRunner.class )
57 @Factory ( PartitionIT.Factory.class )
58 @ApplyLdifs (
59 {
60 "dn: dc=foo,dc=com\n" +
61 "objectClass: top\n" +
62 "objectClass: domain\n" +
63 "dc: foo\n\n" +
64
65 "dn: dc=bar,dc=com\n" +
66 "objectClass: top\n" +
67 "objectClass: domain\n" +
68 "dc: bar\n\n"
69 }
70 )
71 public final class PartitionIT
72 {
73 private static final Logger LOG = LoggerFactory.getLogger( PartitionIT.class );
74 public static DirectoryService service;
75
76
77
78
79
80
81 public static class Factory implements DirectoryServiceFactory
82 {
83 public DirectoryService newInstance() throws Exception
84 {
85 DirectoryService service = new DefaultDirectoryService();
86 service.getChangeLog().setEnabled( true );
87
88 Partition foo = new JdbmPartition();
89 foo.setId( "foo" );
90 foo.setSuffix( "dc=foo,dc=com" );
91 service.addPartition( foo );
92
93 Partition bar = new JdbmPartition();
94 bar.setId( "bar" );
95 bar.setSuffix( "dc=bar,dc=com" );
96 service.addPartition( bar );
97
98 return service;
99 }
100 }
101
102
103
104
105
106
107
108 @Test
109 public void testDIRSERVER_1118() throws Exception
110 {
111
112
113
114 HashMap<String, Partition> partitionMap = new HashMap<String, Partition>();
115
116 for ( Partition partition : service.getPartitions() )
117 {
118 LOG.debug( "partition id = {}", partition.getId() );
119 partitionMap.put( partition.getId(), partition );
120 }
121
122 assertNotNull( partitionMap.containsKey( "foo" ) );
123 assertNotNull( partitionMap.containsKey( "bar" ) );
124
125
126
127
128
129 LdapContext rootDSE = getRootContext( service );
130 Attribute namingContexts = rootDSE.getAttributes( "",
131 new String[] { "namingContexts" } ).get( "namingContexts" );
132 assertTrue( namingContexts.contains( "dc=foo,dc=com" ) );
133 assertTrue( namingContexts.contains( "dc=bar,dc=com" ) );
134 LOG.debug( "Found both dc=foo,dc=com and dc=bar,dc=com in namingContexts" );
135
136
137
138
139 addLookupDelete( "dc=foo,dc=com" );
140 addLookupDelete( "dc=bar,dc=com" );
141 }
142
143
144
145
146
147
148
149
150 public void addLookupDelete( String partitionSuffix ) throws Exception
151 {
152 LdapContext rootDSE = getRootContext( service );
153 Attributes attrs = new BasicAttributes( "objectClass", "organizationalUnit", true );
154 attrs.put( "ou", "people" );
155 String entryDn = "ou=people," + partitionSuffix;
156 rootDSE.createSubcontext( entryDn, attrs );
157 LOG.debug( "added entry {} to partition {}", entryDn, partitionSuffix );
158
159 Attributes reloaded = rootDSE.getAttributes( entryDn );
160 assertNotNull( reloaded );
161 assertTrue( reloaded.get( "ou" ).contains( "people" ) );
162 LOG.debug( "looked up entry {} from partition {}", entryDn, partitionSuffix );
163
164 rootDSE.destroySubcontext( entryDn );
165 try
166 {
167 rootDSE.getAttributes( entryDn );
168 fail( "should never get here" );
169 }
170 catch ( Exception e )
171 {
172 LOG.debug( "Successfully deleted entry {} from partition {}", entryDn, partitionSuffix );
173 }
174 }
175 }