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 PrimaryKeyAnalyser} 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: PrimaryKeyAnalyserTest.java 4123 2008-05-25 21:49:01Z rakesh $
017 */
018 public class PrimaryKeyAnalyserTest extends TestCase
019 {
020 public static Test suite()
021 {
022 return new TestSuite( PrimaryKeyAnalyserTest.class );
023 }
024
025 /**
026 * Test fetching all columns from the database connection.
027 */
028 public void testAnalyse() throws Exception
029 {
030 PrimaryKeyAnalyser analyser = new PrimaryKeyAnalyser(
031 CreateTestObjects.manager );
032 Collection<PrimaryKeyMetaData> metadata = analyser.analyse(
033 SchemaAnalyserTest.metadata, TableAnalyserTest.metadata );
034
035 assertTrue( "Checking single primary key found", metadata.size() == 1 );
036 }
037
038 /**
039 * Test to ensure that the {@link TableMetaData#primaryKey} field was
040 * updated with {@link PrimaryKeyMetaData} information.
041 */
042 public void testTableUpdated()
043 {
044 assertNotNull( "Checking primary keys added to table metadata",
045 TableAnalyserTest.metadata.getPrimaryKey() );
046 assertTrue( "Checking primary key has multiple columns",
047 TableAnalyserTest.metadata.getPrimaryKey().getColumns().size() > 1 );
048 }
049 }