From commits-return-18785-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Jul 07 22:57:36 2008 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 454 invoked from network); 7 Jul 2008 22:57:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Jul 2008 22:57:36 -0000 Received: (qmail 69940 invoked by uid 500); 7 Jul 2008 22:57:36 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 69907 invoked by uid 500); 7 Jul 2008 22:57:36 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 69898 invoked by uid 99); 7 Jul 2008 22:57:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2008 15:57:36 -0700 X-ASF-Spam-Status: No, hits=-1999.6 required=10.0 tests=ALL_TRUSTED,SUBJECT_FUZZY_TION X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2008 22:56:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4620F2388A26; Mon, 7 Jul 2008 15:56:45 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r674663 - in /directory/apacheds/branches/bigbang/core-integ/src/test: java/org/apache/directory/server/core/partition/ java/org/apache/directory/server/core/partition/PartitionIT.java resources/log4j.properties Date: Mon, 07 Jul 2008 22:56:45 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080707225645.4620F2388A26@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Mon Jul 7 15:56:44 2008 New Revision: 674663 URL: http://svn.apache.org/viewvc?rev=674663&view=rev Log: Test case for DIRSERVER-1118: multiple partitions with common base like dc=com Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java (with props) Modified: directory/apacheds/branches/bigbang/core-integ/src/test/resources/log4j.properties Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java?rev=674663&view=auto ============================================================================== --- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java (added) +++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java Mon Jul 7 15:56:44 2008 @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.server.core.partition; + + +import java.util.HashMap; + +import org.apache.directory.server.core.DefaultDirectoryService; +import org.apache.directory.server.core.DirectoryService; +import org.apache.directory.server.core.entry.DefaultServerEntry; +import org.apache.directory.server.core.entry.ServerEntry; +import org.apache.directory.server.core.integ.CiRunner; +import org.apache.directory.server.core.integ.DirectoryServiceFactory; +import org.apache.directory.server.core.integ.annotations.Factory; +import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; + +import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext; +import org.apache.directory.shared.ldap.message.AttributesImpl; +import org.apache.directory.shared.ldap.name.LdapDN; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.naming.ldap.LdapContext; + + + +/** + * Test cases for partition handling. + * + * @author Apache Directory Project + * @version $Rev$ + */ +@RunWith ( CiRunner.class ) +@Factory ( PartitionIT.Factory.class ) +public final class PartitionIT +{ + private static final Logger LOG = LoggerFactory.getLogger( PartitionIT.class ); + public static DirectoryService service; + + + /** + * Creates a DirectoryService configured with two separate dc=com based + * domains to test multiple partitions. + */ + public static class Factory implements DirectoryServiceFactory + { + public DirectoryService newInstance() throws NamingException + { + DirectoryService service = new DefaultDirectoryService(); + service.getChangeLog().setEnabled( true ); + + Partition foo = new JdbmPartition(); + foo.setId( "foo" ); + foo.setSuffix( "dc=foo,dc=com" ); + LdapDN contextDn = new LdapDN( "dc=foo,dc=com" ); + contextDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); + ServerEntry contextEntry = new DefaultServerEntry( service.getRegistries(), contextDn ); + contextEntry.add( "objectClass", "top", "domain" ); + contextEntry.add( "dc", "foo" ); + foo.setContextEntry( contextEntry ); + service.addPartition( foo ); + + Partition bar = new JdbmPartition(); + bar.setId( "bar" ); + bar.setSuffix( "dc=bar,dc=com" ); + contextDn = new LdapDN( "dc=bar,dc=com" ); + contextDn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() ); + contextEntry = new DefaultServerEntry( service.getRegistries(), contextDn ); + contextEntry.add( "objectClass", "top", "domain" ); + contextEntry.add( "dc", "bar" ); + bar.setContextEntry( contextEntry ); + service.addPartition( bar ); + + return service; + } + } + + + /** + * Test case to weed out issue in DIRSERVER-1118. + * + * @see https://issues.apache.org/jira/browse/DIRSERVER-1118 + */ + @Test + public void testDIRSERVER_1118() throws Exception + { + /* + * Confirm the presence of the partitions foo and bar through DS API + */ + HashMap partitionMap = new HashMap(); + + for ( Partition partition : service.getPartitions() ) + { + LOG.debug( "partition id = {}", partition.getId() ); + partitionMap.put( partition.getId(), partition ); + } + + assertNotNull( partitionMap.containsKey( "foo" ) ); + assertNotNull( partitionMap.containsKey( "bar" ) ); + + /* + * Confirm presence and publishing of foo and bar partitions as + * namingContexts as values innamingContexts attribute of the rootDSE + */ + LdapContext rootDSE = getRootContext( service ); + Attribute namingContexts = rootDSE.getAttributes( "", + new String[] { "namingContexts" } ).get( "namingContexts" ); + assertTrue( namingContexts.contains( "dc=foo,dc=com" ) ); + assertTrue( namingContexts.contains( "dc=bar,dc=com" ) ); + LOG.debug( "Found both dc=foo,dc=com and dc=bar,dc=com in namingContexts" ); + + /* + * Add, lookup, then delete entry in both foo and bar partitions + */ + addLookupDelete( "dc=foo,dc=com" ); + addLookupDelete( "dc=bar,dc=com" ); + } + + + /** + * Given the suffix DN of a partition this method will add an entry, look + * it up, then delete it making sure all checks out. + * + * @param partitionSuffix the DN of the partition suffix + */ + public void addLookupDelete( String partitionSuffix ) throws Exception + { + LdapContext rootDSE = getRootContext( service ); + Attributes attrs = new AttributesImpl( "objectClass", "organizationalUnit", true ); + attrs.put( "ou", "people" ); + String entryDn = "ou=people," + partitionSuffix; + rootDSE.createSubcontext( entryDn, attrs ); + LOG.debug( "added entry {} to partition {}", entryDn, partitionSuffix ); + + Attributes reloaded = rootDSE.getAttributes( entryDn ); + assertNotNull( reloaded ); + assertTrue( reloaded.get( "ou" ).contains( "people" ) ); + LOG.debug( "looked up entry {} from partition {}", entryDn, partitionSuffix ); + + rootDSE.destroySubcontext( entryDn ); + try + { + rootDSE.getAttributes( entryDn ); + fail( "should never get here" ); + } + catch ( Exception e ) + { + LOG.debug( "Successfully deleted entry {} from partition {}", entryDn, partitionSuffix ); + } + } +} Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: directory/apacheds/branches/bigbang/core-integ/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/resources/log4j.properties?rev=674663&r1=674662&r2=674663&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/core-integ/src/test/resources/log4j.properties (original) +++ directory/apacheds/branches/bigbang/core-integ/src/test/resources/log4j.properties Mon Jul 7 15:56:44 2008 @@ -20,3 +20,5 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n log4j.logger.org.apache.directory.server.core.integ=ERROR + +#log4j.logger.org.apache.directory.server.core.partition.PartitionIT=DEBUG