001    package com.sptci.rwt;
002    
003    import java.sql.Connection;
004    import java.util.Collection;
005    
006    import static junit.framework.Assert.*;
007    import junit.framework.Test;
008    import junit.framework.TestCase;
009    import junit.framework.TestSuite;
010    
011    /**
012     * Unit test for the {@link IndexAnalyser} object.
013     *
014     * <p>Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
015     * @author Rakesh Vidyadharan 2007-09-25
016     * @version $Id: IndexAnalyserTest.java 4123 2008-05-25 21:49:01Z rakesh $
017     */
018    public class IndexAnalyserTest extends TestCase
019    {
020      public static Test suite()
021      {
022        return new TestSuite( IndexAnalyserTest.class );
023      }
024    
025      /**
026       * Test fetching all columns from the database connection.
027       */
028      public void testAnalyse() throws Exception
029      {
030        IndexAnalyser analyser = new IndexAnalyser(
031            CreateTestObjects.manager );
032        Collection<IndexMetaData> metadata = analyser.analyse(
033            SchemaAnalyserTest.metadata, TableAnalyserTest.metadata );
034    
035        assertTrue( "Checking non-zero indices", metadata.size() > 0 );
036      }
037    
038      /**
039       * Test to ensure that the {@link TableMetaData#indices} field was updated
040       * with {@link IndexMetaData} information.
041       */
042      public void testTableUpdated()
043      {
044        assertTrue( "Checking indices added to table metadata",
045            TableAnalyserTest.metadata.getIndices().size() > 0 );
046      }
047    
048      /**
049       * Test to ensure that the {@link IndexMetaData} created for testing
050       * has multiple columns.
051       */
052      public void testMultipleColumns()
053      {
054        for ( IndexMetaData imd : TableAnalyserTest.metadata.getIndices() )
055        {
056          if ( CreateTestObjects.indexName.equalsIgnoreCase( imd.getName() ) )
057          {
058            assertTrue( "Checking index has multiple columns",
059                imd.getColumns().size() > 1 );
060          }
061        }
062      }
063    }