ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/aut/src/test/org/apache/aut/vfs/test AbstractFileSystemTestCase.java
Date Wed, 10 Apr 2002 12:24:19 GMT
donaldp     02/04/10 05:24:19

  Modified:    aut/src/test/org/apache/aut/vfs/test
                        AbstractFileSystemTestCase.java
  Log:
  Decoupled TestCase from AbstractMyrmidonTestCase.
  
  Need to create a AbstractAUTTestCase in future and have AbstractMyrmidonTestCase extend
AbstractAUTTestCase
  
  Revision  Changes    Path
  1.3       +133 -13   jakarta-ant-myrmidon/aut/src/test/org/apache/aut/vfs/test/AbstractFileSystemTestCase.java
  
  Index: AbstractFileSystemTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/aut/src/test/org/apache/aut/vfs/test/AbstractFileSystemTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractFileSystemTestCase.java	7 Apr 2002 02:27:57 -0000	1.2
  +++ AbstractFileSystemTestCase.java	10 Apr 2002 12:24:19 -0000	1.3
  @@ -8,25 +8,29 @@
   package org.apache.aut.vfs.test;
   
   import java.io.ByteArrayOutputStream;
  +import java.io.File;
  +import java.io.IOException;
   import java.io.InputStream;
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  -import org.apache.aut.vfs.impl.DefaultFileSystemManager;
  -import org.apache.aut.vfs.provider.AbstractFileObject;
  -import org.apache.aut.vfs.provider.LocalFileSystemProvider;
  -import org.apache.aut.vfs.provider.local.DefaultLocalFileSystemProvider;
  +import junit.framework.TestCase;
  +import org.apache.aut.vfs.FileContent;
  +import org.apache.aut.vfs.FileName;
   import org.apache.aut.vfs.FileObject;
  -import org.apache.aut.vfs.FileType;
   import org.apache.aut.vfs.FileSystemException;
  -import org.apache.aut.vfs.FileName;
  +import org.apache.aut.vfs.FileType;
   import org.apache.aut.vfs.NameScope;
  -import org.apache.aut.vfs.FileContent;
  +import org.apache.aut.vfs.impl.DefaultFileSystemManager;
  +import org.apache.aut.vfs.provider.AbstractFileObject;
  +import org.apache.aut.vfs.provider.local.DefaultLocalFileSystemProvider;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.myrmidon.AbstractMyrmidonTest;
  +import org.apache.avalon.framework.ExceptionUtil;
  +import org.apache.avalon.framework.logger.ConsoleLogger;
  +import org.apache.avalon.framework.logger.Logger;
   
   /**
    * File system test cases, which verifies the structure and naming
  @@ -38,13 +42,15 @@
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    */
   public abstract class AbstractFileSystemTestCase
  -    extends AbstractMyrmidonTest
  +    extends TestCase
   {
  -    private final static Resources REZ
  -        = ResourceManager.getPackageResources( AbstractFileObject.class );
  +    private final static Resources REZ =
  +        ResourceManager.getPackageResources( AbstractFileObject.class );
   
       protected FileObject m_baseFolder;
       protected DefaultFileSystemManager m_manager;
  +    private final File m_testBaseDir;
  +    private Logger m_logger;
   
       // Contents of "file1.txt"
       private String m_charContent;
  @@ -52,6 +58,76 @@
       public AbstractFileSystemTestCase( String name )
       {
           super( name );
  +        final String baseDirProp = System.getProperty( "test.basedir" );
  +        final File baseDir = getCanonicalFile( new File( baseDirProp ) );
  +        final String packagePath = getPackageName( getClass() ).replace( '.', File.separatorChar
);
  +        m_testBaseDir = getCanonicalFile( new File( baseDir, packagePath ) );
  +    }
  +
  +    protected File getTestResource( final String name )
  +    {
  +        return getTestResource( name, true );
  +    }
  +
  +    /**
  +     * Returns the name of the package containing a class.
  +     *
  +     * @return The . delimited package name, or an empty string if the class
  +     *         is in the default package.
  +     */
  +    protected static String getPackageName( final Class clazz )
  +    {
  +        final Package pkg = clazz.getPackage();
  +        if( null != pkg )
  +        {
  +            return pkg.getName();
  +        }
  +
  +        final String name = clazz.getName();
  +        if( -1 == name.lastIndexOf( "." ) )
  +        {
  +            return "";
  +        }
  +        else
  +        {
  +            return name.substring( 0, name.lastIndexOf( "." ) );
  +        }
  +    }
  +
  +    /**
  +     * Locates a test resource.
  +     *
  +     * @param name path of the resource, relative to this test's base directory.
  +     */
  +    protected File getTestResource( final String name, final boolean mustExist )
  +    {
  +        File file = new File( m_testBaseDir, name );
  +        file = getCanonicalFile( file );
  +        if( mustExist )
  +        {
  +            assertTrue( "Test file \"" + file + "\" does not exist.", file.exists() );
  +        }
  +        else
  +        {
  +            assertTrue( "Test file \"" + file + "\" should not exist.", !file.exists()
);
  +        }
  +
  +        return file;
  +    }
  +
  +    /**
  +     * Makes a file canonical
  +     */
  +    private File getCanonicalFile( final File file )
  +    {
  +        try
  +        {
  +            return file.getCanonicalFile();
  +        }
  +        catch( IOException e )
  +        {
  +            return file.getAbsoluteFile();
  +        }
       }
   
       /**
  @@ -92,7 +168,7 @@
           m_baseFolder = getBaseFolder();
   
           // Make some assumptions absout the name
  -        assertTrue( ! m_baseFolder.getName().getPath().equals( "/" ) );
  +        assertTrue( !m_baseFolder.getName().getPath().equals( "/" ) );
   
           // Build the expected content of "file1.txt"
           final String eol = System.getProperty( "line.separator" );
  @@ -108,6 +184,18 @@
       }
   
       /**
  +     * Creates a logger.
  +     */
  +    protected Logger getLogger()
  +    {
  +        if( m_logger == null )
  +        {
  +            m_logger = new ConsoleLogger( ConsoleLogger.LEVEL_WARN );
  +        }
  +        return m_logger;
  +    }
  +
  +    /**
        * Tests resolution of absolute URI.
        */
       public void testAbsoluteURI() throws Exception
  @@ -595,6 +683,38 @@
       }
   
       /**
  +     * Asserts that an exception contains the expected message.
  +     */
  +    protected void assertSameMessage( final String message, final Throwable throwable )
  +    {
  +        assertSameMessage( new String[]{message}, throwable );
  +    }
  +
  +    /**
  +     * Asserts that an exception chain contains the expected messages.
  +     *
  +     * @param messages The messages, in order.  A null entry in this array
  +     *                 indicates that the message should be ignored.
  +     */
  +    protected void assertSameMessage( final String[] messages,
  +                                      final Throwable throwable )
  +    {
  +        Throwable current = throwable;
  +        for( int i = 0; i < messages.length; i++ )
  +        {
  +            String message = messages[ i ];
  +            assertNotNull( current );
  +            if( message != null )
  +            {
  +                assertEquals( message, current.getMessage() );
  +            }
  +
  +            // Get the next exception in the chain
  +            current = ExceptionUtil.getCause( current, true );
  +        }
  +    }
  +
  +    /**
        * Tests existence determination.
        */
       public void testExists() throws Exception
  @@ -871,7 +991,7 @@
           {
               for( int i = 0; i < baseNames.length; i++ )
               {
  -                String baseName = baseNames[i ];
  +                String baseName = baseNames[ i ];
                   addChild( new FileInfo( baseName, type ) );
               }
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message