Author: trustin
Date: Sun Aug 7 23:34:23 2005
New Revision: 230760
URL: http://svn.apache.org/viewcvs?rev=230760&view=rev
Log:
Added a test case for adding/removing partitions using configuration.
Added:
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/
directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/ContextPartitionConfigurationTest.java (with props)
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java?rev=230760&r1=230759&r2=230760&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/DefaultContextPartitionNexus.java Sun Aug 7 23:34:23 2005
@@ -356,14 +356,14 @@
indexedAttrs.add( Oid.UPDN );
mcfg.setIndexedAttributes( indexedAttrs );
- String key = partition.getSuffix( true ).toString();
+ String key = config.getSuffix();
if( partitions.containsKey( key ) )
{
throw new ConfigurationException( "Duplicate partition suffix: " + key );
}
partition.init( factoryCfg, mcfg );
- partitions.put( key, partition );
+ partitions.put( partition.getSuffix( true ).toString(), partition );
Attribute namingContexts = rootDSE.get( NAMINGCTXS_ATTR );
namingContexts.add( partition.getSuffix( false ).toString() );
Added: directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/ContextPartitionConfigurationTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/ContextPartitionConfigurationTest.java?rev=230760&view=auto
==============================================================================
--- directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/ContextPartitionConfigurationTest.java (added)
+++ directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/ContextPartitionConfigurationTest.java Sun Aug 7 23:34:23 2005
@@ -0,0 +1,88 @@
+
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.ldap.server.configuration;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+
+import junit.framework.Assert;
+
+import org.apache.ldap.server.AbstractAdminTestCase;
+import org.apache.ldap.server.jndi.CoreContextFactory;
+import org.apache.ldap.server.partition.impl.btree.jdbm.JdbmContextPartition;
+
+
+/**
+ * Confirms the removal of the comparator serialization bug filed here in JIRA:
+ * DIREVE-54.
+ *
+ * @author Apache Directory Project
+ * @version $Rev$
+ */
+public class ContextPartitionConfigurationTest extends AbstractAdminTestCase
+{
+ public ContextPartitionConfigurationTest()
+ {
+ }
+
+ public void testAddAndRemove() throws Exception
+ {
+ MutableContextPartitionConfiguration partitionCfg =
+ new MutableContextPartitionConfiguration();
+ partitionCfg.setName( "removable" );
+ partitionCfg.setSuffix( "ou=removable" );
+ Attributes ctxEntry = new BasicAttributes();
+ ctxEntry.put( "objectClass", "top" );
+ ctxEntry.put( "ou", "removable" );
+ partitionCfg.setContextEntry( ctxEntry );
+ partitionCfg.setContextPartition( new JdbmContextPartition() );
+
+ // Test AddContextPartition
+ AddContextPartitionConfiguration addCfg =
+ new AddContextPartitionConfiguration( partitionCfg );
+
+ Hashtable env = new Hashtable();
+ env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+ env.putAll( addCfg.toJndiEnvironment() );
+
+ Context ctx = new InitialContext( env );
+ Assert.assertNotNull( ctx.lookup( "ou=removable" ) );
+
+ // Test removeContextPartition
+ RemoveContextPartitionConfiguration removeCfg =
+ new RemoveContextPartitionConfiguration( "ou=removable" );
+ env.putAll( removeCfg.toJndiEnvironment() );
+
+ ctx = new InitialContext( env );
+ try
+ {
+ ctx.lookup( "ou=removable" );
+ Assert.fail( "NameNotFoundException should be thrown." );
+ }
+ catch( NameNotFoundException e )
+ {
+ // Partition is removed.
+ }
+ }
+}
Propchange: directory/apacheds/trunk/core/src/test/org/apache/ldap/server/configuration/ContextPartitionConfigurationTest.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision