// Extracting of the config file
File configDir = new File( workDir, "configWriter" ); // 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( schemaManager, dnFactory );
configPartition.setId( "config" );
configPartition.setPartitionPath( new File( configFile ).toURI() );
configPartition.setSuffixDn( new Dn( "ou=config" ) );
configPartition.setSchemaManager( schemaManager );
configPartition.initialize();
// Reading the config partition
ConfigPartitionReader cpReader = new ConfigPartitionReader( configPartition );
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() ) );
}
// Destroying the config partition
configPartition.destroy();
}