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 LowerCaseTableMetaDataTest extends TestCase 33 { 34 public LowerCaseTableMetaDataTest(String s) 35 { 36 super(s); 37 } 38 39 public void testGetTableName() throws Exception 40 { 41 String original = "TABLE_NAME"; 42 String expected = original.toLowerCase(); 43 44 ITableMetaData metaData = new LowerCaseTableMetaData( 45 new DefaultTableMetaData(original, new Column[0])); 46 47 assertEquals("table name", expected, metaData.getTableName()); 48 } 49 50 public void testGetColumns() throws Exception 51 { 52 Column[] columns = new Column[]{ 53 new Column("NUMBER_COLUMN", DataType.NUMERIC, "qwerty", Column.NULLABLE), 54 new Column("STRING_COLUMN", DataType.VARCHAR, "toto", Column.NO_NULLS), 55 new Column("BOOLEAN_COLUMN", DataType.BOOLEAN), 56 }; 57 58 ITableMetaData metaData = new LowerCaseTableMetaData( 59 "TABLE_NAME", columns); 60 61 Column[] lowerColumns = metaData.getColumns(); 62 assertEquals("column count", columns.length, lowerColumns.length); 63 for (int i = 0; i < columns.length; i++) 64 { 65 Column column = columns[i]; 66 Column lowerColumn = lowerColumns[i]; 67 68 assertEquals("name", column.getColumnName().toLowerCase(), 69 lowerColumn.getColumnName()); 70 assertTrue("name not equals", 71 !column.getColumnName().equals(lowerColumn.getColumnName())); 72 assertEquals("type", column.getDataType(), lowerColumn.getDataType()); 73 assertEquals("sql type", column.getSqlTypeName(), lowerColumn.getSqlTypeName()); 74 assertEquals("nullable", column.getNullable(), lowerColumn.getNullable()); 75 } 76 assertEquals("key count", 0, metaData.getPrimaryKeys().length); 77 } 78 79 public void testGetPrimaryKeys() throws Exception 80 { 81 Column[] columns = new Column[]{ 82 new Column("NUMBER_COLUMN", DataType.NUMERIC, "qwerty", Column.NULLABLE), 83 new Column("STRING_COLUMN", DataType.VARCHAR, "toto", Column.NO_NULLS), 84 new Column("BOOLEAN_COLUMN", DataType.BOOLEAN), 85 }; 86 String [] keyNames = new String []{"Boolean_Column", "Number_Column"}; 87 88 89 ITableMetaData metaData = new LowerCaseTableMetaData( 90 "TABLE_NAME", columns, keyNames); 91 92 Column[] keys = metaData.getPrimaryKeys(); 93 assertEquals("key count", keyNames.length, keys.length); 94 for (int i = 0; i < keys.length; i++) 95 { 96 assertTrue("name not equals", 97 !keyNames[i].equals(keys[i].getColumnName())); 98 assertEquals("key name", keyNames[i].toLowerCase(), 99 keys[i].getColumnName()); 100 } 101 } 102 103 } 104 105 106 107 108 109 | Popular Tags |