1 21 22 package org.dbunit.dataset; 23 24 import junit.framework.TestCase; 25 import org.dbunit.dataset.datatype.DataType; 26 27 32 public class DefaultTableMetaDataTest extends TestCase 33 { 34 public DefaultTableMetaDataTest(String s) 35 { 36 super(s); 37 } 38 39 protected ITableMetaData createMetaData(String tableName, 40 Column[] columns, String [] keyNames) throws Exception 41 { 42 return new DefaultTableMetaData( 43 tableName, columns, keyNames); 44 } 45 46 public void testGetTableName() throws Exception 47 { 48 String expected = "tableName"; 49 ITableMetaData metaData = createMetaData(expected, null, null); 50 51 assertEquals("table name", expected, metaData.getTableName()); 52 } 53 54 public void testGetColumns() throws Exception 55 { 56 Column[] columns = new Column[]{ 57 new Column("numberColumn", DataType.NUMERIC), 58 new Column("stringColumn", DataType.VARCHAR), 59 new Column("booleanColumn", DataType.BOOLEAN), 60 }; 61 62 ITableMetaData metaData = createMetaData("toto", columns, null); 63 64 assertEquals("column count", columns.length, metaData.getColumns().length); 65 for (int i = 0; i < columns.length; i++) 66 { 67 Column column = columns[i]; 68 assertEquals("columns" + i, column, metaData.getColumns()[i]); 69 } 70 assertEquals("key count", 0, metaData.getPrimaryKeys().length); 71 } 72 73 public void testGetPrimaryKeys() throws Exception 74 { 75 Column[] columns = new Column[]{ 76 new Column("numberColumn", DataType.NUMERIC), 77 new Column("stringColumn", DataType.VARCHAR), 78 new Column("booleanColumn", DataType.BOOLEAN), 79 }; 80 String [] keyNames = new String []{"booleanColumn", "numberColumn"}; 81 82 83 ITableMetaData metaData = createMetaData("toto", columns, keyNames); 84 85 Column[] keys = metaData.getPrimaryKeys(); 86 assertEquals("key count", keyNames.length, keys.length); 87 for (int i = 0; i < keys.length; i++) 88 { 89 assertEquals("key name", keyNames[i], keys[i].getColumnName()); 90 } 91 } 92 93 public void testGetPrimaryKeysColumnDontMatch() throws Exception 94 { 95 Column[] columns = new Column[]{ 96 new Column("numberColumn", DataType.NUMERIC), 97 new Column("stringColumn", DataType.VARCHAR), 98 new Column("booleanColumn", DataType.BOOLEAN), 99 }; 100 String [] keyNames = new String []{"invalidColumn"}; 101 102 103 ITableMetaData metaData = createMetaData("toto", columns, keyNames); 104 105 Column[] keys = metaData.getPrimaryKeys(); 106 assertEquals("key count", 0, keys.length); 107 } 108 } 109 110 111 112 113 114 | Popular Tags |