You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/12/10 10:32:26 UTC
svn commit: r1044252 -
/directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java
Author: pamarcelot
Date: Fri Dec 10 09:32:25 2010
New Revision: 1044252
URL: http://svn.apache.org/viewvc?rev=1044252&view=rev
Log:
Closed the left opened LdifReader instance(made the tests fail on Windows).
Modified:
directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java
Modified: directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java?rev=1044252&r1=1044251&r2=1044252&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java (original)
+++ directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java Fri Dec 10 09:32:25 2010
@@ -1,175 +1,176 @@
-/*
- * 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.config;
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.junit.tools.Concurrent;
-import org.apache.directory.junit.tools.ConcurrentJunitRunner;
-import org.apache.directory.server.config.beans.ConfigBean;
-import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
-import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.ldif.LdifEntry;
-import org.apache.directory.shared.ldap.ldif.LdifReader;
-import org.apache.directory.shared.ldap.name.DN;
-import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
-import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-
-/**
- * Test class for ConfigPartitionReader
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-@RunWith(ConcurrentJunitRunner.class)
-@Concurrent()
-public class ConfigWriterTest
-{
- private static SchemaManager schemaManager;
-
- private static File workDir = new File( System.getProperty( "java.io.tmpdir" ) + "/server-work" );
-
-
- @BeforeClass
- public static void readConfig() throws Exception
- {
- FileUtils.deleteDirectory( workDir );
- workDir.mkdir();
-
- String workingDirectory = workDir.getPath();
- // Extract the schema on disk (a brand new one) and load the registries
- File schemaRepository = new File( workingDirectory, "schema" );
-
- if ( schemaRepository.exists() )
- {
- FileUtils.deleteDirectory( schemaRepository );
- }
-
- SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
- extractor.extractOrCopy();
-
- SchemaLoader loader = new LdifSchemaLoader( schemaRepository );
- schemaManager = new DefaultSchemaManager( loader );
-
- // We have to load the schema now, otherwise we won't be able
- // to initialize the Partitions, as we won't be able to parse
- // and normalize their suffix DN
- schemaManager.loadAllEnabled();
-
- List<Throwable> errors = schemaManager.getErrors();
-
- if ( errors.size() != 0 )
- {
- throw new Exception( "Schema load failed : " + LdapExceptionUtils.printErrors( errors ) );
- }
- }
-
-
- @Test
- public void testConfigReader() throws Exception
- {
- // Extracting of the config file
- File configDir = new File( workDir, "configReader" ); // could be any directory, cause the config is now in a single file
- String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "config.ldif", true );
-
- // Creating of the config partition
- SingleFileLdifPartition configPartition = new SingleFileLdifPartition( configFile );
- configPartition.setId( "config" );
- configPartition.setSuffix( new DN( "ou=config" ) );
- configPartition.setSchemaManager( schemaManager );
- configPartition.initialize();
-
- // Reading the config partition
- ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition, workDir );
- ConfigBean configBean = cpReader.readConfig();
- assertNotNull( configBean );
-
- // Creating the config writer
- ConfigWriter configWriter = new ConfigWriter( schemaManager, configBean );
-
- // Reading the original config file
- LdifReader ldifReader = new LdifReader( configFile );
- List<LdifEntry> originalConfigEntries = new ArrayList<LdifEntry>();
- while ( ldifReader.hasNext() )
- {
- originalConfigEntries.add( ldifReader.next() );
- }
-
- // Getting the list of entries of generated config
- List<LdifEntry> generatedConfigEntries = configWriter.getConvertedLdifEntries();
-
- // Comparing the number of entries
- assertEquals( originalConfigEntries.size(), generatedConfigEntries.size() );
-
- // Comparing each entry in both lists (which have been sorted before)
- Comparator<LdifEntry> dnComparator = new Comparator<LdifEntry>()
- {
- public int compare( LdifEntry o1, LdifEntry o2 )
- {
- return o1.getDn().toString().compareToIgnoreCase( o2.getDn().toString() );
- }
- };
- Collections.sort( originalConfigEntries, dnComparator );
- Collections.sort( generatedConfigEntries, dnComparator );
- for ( int i = 0; i < originalConfigEntries.size(); i++ )
- {
- Entry originalConfigEntry = originalConfigEntries.get( i ).getEntry();
- Entry generatedConfigEntry = generatedConfigEntries.get( i ).getEntry();
-
- // Comparing DNs
- assertTrue( originalConfigEntry.getDn().getNormName().equals( generatedConfigEntry.getDn().getNormName() ) );
-
- // Comparing attributes
- Iterator<EntryAttribute> attributesIterator = originalConfigEntry.iterator();
- while ( attributesIterator.hasNext() )
- {
- EntryAttribute originalEntryAttribute = ( EntryAttribute ) attributesIterator.next();
- assertTrue( generatedConfigEntry.contains( originalEntryAttribute ) );
-
- EntryAttribute generatedEntryAttribute = generatedConfigEntry.get( originalEntryAttribute.getId() );
- assertTrue( originalEntryAttribute.equals( generatedEntryAttribute ) );
- }
- }
-
- // Destroying the config partition
- configPartition.destroy();
- }
-}
+/*
+ * 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.config;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.server.config.beans.ConfigBean;
+import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
+import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test class for ConfigPartitionReader
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ConfigWriterTest
+{
+ private static SchemaManager schemaManager;
+
+ private static File workDir = new File( System.getProperty( "java.io.tmpdir" ) + "/server-work" );
+
+
+ @BeforeClass
+ public static void readConfig() throws Exception
+ {
+ FileUtils.deleteDirectory( workDir );
+ workDir.mkdir();
+
+ String workingDirectory = workDir.getPath();
+ // Extract the schema on disk (a brand new one) and load the registries
+ File schemaRepository = new File( workingDirectory, "schema" );
+
+ if ( schemaRepository.exists() )
+ {
+ FileUtils.deleteDirectory( schemaRepository );
+ }
+
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy();
+
+ SchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ // We have to load the schema now, otherwise we won't be able
+ // to initialize the Partitions, as we won't be able to parse
+ // and normalize their suffix DN
+ schemaManager.loadAllEnabled();
+
+ List<Throwable> errors = schemaManager.getErrors();
+
+ if ( errors.size() != 0 )
+ {
+ throw new Exception( "Schema load failed : " + LdapExceptionUtils.printErrors( errors ) );
+ }
+ }
+
+
+ @Test
+ public void testConfigReader() throws Exception
+ {
+ // Extracting of the config file
+ File configDir = new File( workDir, "configReader" ); // could be any directory, cause the config is now in a single file
+ String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "config.ldif", true );
+
+ // Creating of the config partition
+ SingleFileLdifPartition configPartition = new SingleFileLdifPartition( configFile );
+ configPartition.setId( "config" );
+ configPartition.setSuffix( new DN( "ou=config" ) );
+ configPartition.setSchemaManager( schemaManager );
+ configPartition.initialize();
+
+ // Reading the config partition
+ ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition, workDir );
+ ConfigBean configBean = cpReader.readConfig();
+ assertNotNull( configBean );
+
+ // Creating the config writer
+ ConfigWriter configWriter = new ConfigWriter( schemaManager, configBean );
+
+ // Reading the original config file
+ LdifReader ldifReader = new LdifReader( configFile );
+ List<LdifEntry> originalConfigEntries = new ArrayList<LdifEntry>();
+ while ( ldifReader.hasNext() )
+ {
+ originalConfigEntries.add( ldifReader.next() );
+ }
+ ldifReader.close();
+
+ // Getting the list of entries of generated config
+ List<LdifEntry> generatedConfigEntries = configWriter.getConvertedLdifEntries();
+
+ // Comparing the number of entries
+ assertEquals( originalConfigEntries.size(), generatedConfigEntries.size() );
+
+ // Comparing each entry in both lists (which have been sorted before)
+ Comparator<LdifEntry> dnComparator = new Comparator<LdifEntry>()
+ {
+ public int compare( LdifEntry o1, LdifEntry o2 )
+ {
+ return o1.getDn().toString().compareToIgnoreCase( o2.getDn().toString() );
+ }
+ };
+ Collections.sort( originalConfigEntries, dnComparator );
+ Collections.sort( generatedConfigEntries, dnComparator );
+ for ( int i = 0; i < originalConfigEntries.size(); i++ )
+ {
+ Entry originalConfigEntry = originalConfigEntries.get( i ).getEntry();
+ Entry generatedConfigEntry = generatedConfigEntries.get( i ).getEntry();
+
+ // Comparing DNs
+ assertTrue( originalConfigEntry.getDn().getNormName().equals( generatedConfigEntry.getDn().getNormName() ) );
+
+ // Comparing attributes
+ Iterator<EntryAttribute> attributesIterator = originalConfigEntry.iterator();
+ while ( attributesIterator.hasNext() )
+ {
+ EntryAttribute originalEntryAttribute = ( EntryAttribute ) attributesIterator.next();
+ assertTrue( generatedConfigEntry.contains( originalEntryAttribute ) );
+
+ EntryAttribute generatedEntryAttribute = generatedConfigEntry.get( originalEntryAttribute.getId() );
+ assertTrue( originalEntryAttribute.equals( generatedEntryAttribute ) );
+ }
+ }
+
+ // Destroying the config partition
+ configPartition.destroy();
+ }
+}