Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 19485 invoked from network); 8 Dec 2010 15:38:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Dec 2010 15:38:45 -0000 Received: (qmail 44568 invoked by uid 500); 8 Dec 2010 15:38:45 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 44511 invoked by uid 500); 8 Dec 2010 15:38:45 -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 44504 invoked by uid 99); 8 Dec 2010 15:38:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 15:38:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED 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; Wed, 08 Dec 2010 15:38:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9D3DD238897A; Wed, 8 Dec 2010 15:38:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1043457 - /directory/apacheds/branches/server-config-annotations/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java Date: Wed, 08 Dec 2010 15:38:19 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101208153819.9D3DD238897A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Wed Dec 8 15:38:19 2010 New Revision: 1043457 URL: http://svn.apache.org/viewvc?rev=1043457&view=rev Log: Added a test for the ConfigWriter. Added: directory/apacheds/branches/server-config-annotations/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java Added: directory/apacheds/branches/server-config-annotations/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/server-config-annotations/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java?rev=1043457&view=auto ============================================================================== --- directory/apacheds/branches/server-config-annotations/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java (added) +++ directory/apacheds/branches/server-config-annotations/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java Wed Dec 8 15:38:19 2010 @@ -0,0 +1,136 @@ +/* + * 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.assertNotNull; +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.util.ArrayList; +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.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 Apache Directory Project + */ +@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 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 originalConfigEntries = new ArrayList(); + while ( ldifReader.hasNext() ) + { + originalConfigEntries.add( ldifReader.next() ); + } + + // Comparing the number of entries + assertEquals( originalConfigEntries.size(), configWriter.getConvertedLdifEntries().size() ); + + // Destroying the config partition + configPartition.destroy(); + } +}