From commits-return-4866-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Jun 03 16:33:53 2005 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 3079 invoked from network); 3 Jun 2005 16:33:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Jun 2005 16:33:53 -0000 Received: (qmail 31309 invoked by uid 500); 3 Jun 2005 16:33:53 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 31287 invoked by uid 500); 3 Jun 2005 16:33:52 -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 31274 invoked by uid 99); 3 Jun 2005 16:33:52 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 03 Jun 2005 09:33:47 -0700 Received: (qmail 2955 invoked by uid 65534); 3 Jun 2005 16:33:39 -0000 Message-ID: <20050603163339.2954.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r179831 - /directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/AbstractCoreTest.java Date: Fri, 03 Jun 2005 16:33:38 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Fri Jun 3 09:33:35 2005 New Revision: 179831 URL: http://svn.apache.org/viewcvs?rev=3D179831&view=3Drev Log: Added extra methods to set an LDIF file to load as a class relative resource or as a file from disk. Checks are made to test exactly what is implied. Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/Abst= ractCoreTest.java Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/serve= r/AbstractCoreTest.java URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/j= ava/org/apache/ldap/server/AbstractCoreTest.java?rev=3D179831&r1=3D179830&r= 2=3D179831&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/Abst= ractCoreTest.java (original) +++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/Abst= ractCoreTest.java Fri Jun 3 09:33:35 2005 @@ -35,9 +35,7 @@ import javax.naming.directory.Attributes; import javax.naming.ldap.InitialLdapContext; import javax.naming.ldap.LdapContext; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Hashtable; import java.util.ArrayList; =20 @@ -80,13 +78,56 @@ /** extra environment parameters that can be added before setUp to ove= rride values */ protected Hashtable overrides =3D new Hashtable(); =20 + /** A testEntries of entries as Attributes to add to the DIT for testi= ng */ + protected ArrayList testEntries =3D new ArrayList(); =20 - private ArrayList list =3D null; + /** An optional LDIF file path if set and present is read to add more = test entries */ + private String ldifPath; =20 + /** Load resources relative to this class */ + private Class loadClass; =20 - public AbstractCoreTest() + + /** + * Sets the LDIF path as a relative resource path to use with the + * loadClass parameter to load the resource. + * + * @param ldifPath the relative resource path to the LDIF file + * @param loadClass the class used to load the LDIF as a resource stre= am + */ + protected void setLdifPath( String ldifPath, Class loadClass ) { - list =3D new ArrayList(); + this.loadClass =3D loadClass; + + this.ldifPath =3D ldifPath; + } + + + /** + * Sets the LDIF path to use. If the path is relative to this class t= hen it + * is first tested + * + * @param ldifPath the path to the LDIF file + */ + protected void setLdifPath( String ldifPath ) + { + this.ldifPath =3D ldifPath; + } + + + /** + * Get's the initial context factory for the provider's ou=3Dsystem co= ntext + * root. + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + + // ---------------------------------------------------------------= ---- + // Add a single test entry + // ---------------------------------------------------------------= ---- =20 Attributes attributes =3D new LockableAttributesImpl(); =20 @@ -103,21 +144,55 @@ throw new NestableRuntimeException( e ); } =20 - list.add( attributes ); - } + testEntries.add( attributes ); =20 + // ---------------------------------------------------------------= ---- + // Add more from an optional LDIF file if they exist + // ---------------------------------------------------------------= ---- =20 - /** - * Get's the initial context factory for the provider's ou=3Dsystem co= ntext - * root. - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - super.setUp(); + InputStream in =3D null; + + if ( loadClass =3D=3D null && ldifPath !=3D null ) + { + File ldifFile =3D new File( ldifPath ); + + if ( ldifFile.exists() ) + { + in =3D new FileInputStream( ldifPath ); + } + else + { + in =3D getClass().getResourceAsStream( ldifPath ); + } + + throw new FileNotFoundException( ldifPath ); + } + else if ( loadClass !=3D null && ldifPath !=3D null ) + { + in =3D loadClass.getResourceAsStream( ldifPath ); + } + + if ( in !=3D null ) + { + LdifIterator list =3D new LdifIterator( in ); + + while ( list.hasNext() ) + { + String ldif =3D ( String ) list.next(); =20 - extras.put( EnvKeys.TEST_ENTRIES, list ); + attributes =3D new LockableAttributesImpl(); + + parser.parse( attributes, ldif ); + + testEntries.add( attributes ); + } + } + + // ---------------------------------------------------------------= ---- + // Add key for extra entries to the testEntries of extras + // ---------------------------------------------------------------= ---- + + extras.put( EnvKeys.TEST_ENTRIES, testEntries ); =20 if ( overrides.containsKey( EnvKeys.WKDIR ) ) { @@ -229,6 +304,8 @@ sysRoot =3D null; =20 Runtime.getRuntime().gc(); + + testEntries.clear(); } =20 =20