CVS: plexus-container-new/src/java/org/apache/plexus PlexusTestCase.java,1.6,1.7

[email protected] Thu, 22 May 2003 19:38:38 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus
In directory eng.werken.com:/tmp/cvs-serv32567

Modified Files:
	PlexusTestCase.java 
Log Message:
o Adding more consistent lookup methods.

Index: PlexusTestCase.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/PlexusTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- PlexusTestCase.java	1 May 2003 23:10:54 -0000	1.6
+++ PlexusTestCase.java	23 May 2003 00:38:30 -0000	1.7
@@ -70,6 +70,12 @@
     DefaultPlexusContainer container;
 
     /**
+     * Basedir for all file I/O. Important when running tests from
+     * the reactor.
+     */
+    public String basedir = System.getProperty( "basedir" );
+
+    /**
      * Constructor.
      *
      *  @param testName
@@ -87,13 +93,12 @@
     {
         // For testing we want to set the root directory so that context
         // values can retrieved without error.
-        if ( System.getProperty( "basedir" ) == null )
+        if ( basedir == null )
         {
-            File basedir = new File( "" );
-            System.setProperty( "basedir", basedir.getAbsolutePath() );
+            basedir = new File( "" ).getPath();
         }
 
-        File f = new File( System.getProperty( "basedir" ), "target/plexus-home" );
+        File f = new File( basedir, "target/plexus-home" );
         System.setProperty( "plexus.home", f.getAbsolutePath() );
         
         if ( !f.isDirectory() )
@@ -229,23 +234,72 @@
         return getClass().getClassLoader();
     }
 
-    /** Retrieve a component by role.
+    /**
      *
-     *  @param role The role.
+     * @param componentKey
+     * @return
+     * @throws Exception
+     */
+    protected Object lookup( String componentKey )
+        throws Exception
+    {
+        return getContainer().getComponentRepository().lookup( componentKey );
+    }
+
+    protected Object lookup( String role, String id )
+        throws Exception
+    {
+        return getContainer().getComponentRepository().lookup( role, id );
+    }
+
+    /** Retrieve a component by componentKey.
+     *
+     *  @param componentKey The componentKey.
      *
      *  @return A matching component.
      *
      *  @throws Exception If an error occurs.
+     *  @deprecated use lookup( componentKey )
      */
-    protected Object getComponent( String role )
+    protected Object getComponent( String componentKey )
         throws Exception
     {
-        return getContainer().getComponentRepository().lookup( role );
+        return lookup( componentKey );
     }
 
-    protected Object getComponent( String role, String id )
+    /**
+     *
+     * @param componentKey
+     * @param id
+     * @return
+     * @throws Exception
+     * @deprecated use lookup( componentKey, id )
+     */
+    protected Object getComponent( String componentKey, String id )
         throws Exception
     {
-        return getContainer().getComponentRepository().lookup( role, id );
+        return lookup( componentKey, id );
+    }
+
+    // Some convenience methods for retrieving files in tests.
+
+    /**
+     * Get test input file.
+     *
+     * @param path Path to test input file.
+     */
+    public String getTestFile( String path )
+    {
+        return new File( basedir, path ).getAbsolutePath();
+    }
+
+    /**
+     * Get test input file.
+     *
+     * @param path Path to test input file.
+     */
+    public String getTestFile( String basedir, String path )
+    {
+        return new File( basedir, path ).getAbsolutePath();
     }
 }