1 21 22 package org.dbunit.operation; 23 24 import org.dbunit.AbstractDatabaseTest; 25 import org.dbunit.dataset.*; 26 import org.dbunit.dataset.xml.XmlDataSet; 27 28 import java.io.FileReader ; 29 import java.io.Reader ; 30 31 36 public class AbstractBatchOperationTest extends AbstractDatabaseTest 37 { 38 public AbstractBatchOperationTest(String s) 39 { 40 super(s); 41 } 42 43 public void testGetOperationMetaDataAndMissingColumns() throws Exception 44 { 45 Reader in = new FileReader ("src/xml/missingColumnTest.xml"); 46 IDataSet xmlDataSet = new XmlDataSet(in); 47 48 ITable[] xmlTables = DataSetUtils.getTables(xmlDataSet); 49 for (int i = 0; i < xmlTables.length; i++) 50 { 51 ITable xmlTable = xmlTables[i]; 52 ITableMetaData xmlMetaData = xmlTable.getTableMetaData(); 53 String tableName = xmlMetaData.getTableName(); 54 55 ITable databaseTable = _connection.createDataSet().getTable(tableName); 56 ITableMetaData databaseMetaData = databaseTable.getTableMetaData(); 57 58 assertTrue(tableName + " missing columns", xmlMetaData.getColumns().length < 60 databaseMetaData.getColumns().length); 61 62 ITableMetaData resultMetaData = 63 AbstractBatchOperation.getOperationMetaData(_connection, xmlMetaData); 64 65 Column[] resultColumns = resultMetaData.getColumns(); 67 assertEquals("result columns count", xmlMetaData.getColumns().length, 68 resultColumns.length); 69 for (int j = 0; j < resultColumns.length; j++) 70 { 71 Column resultColumn = resultColumns[j]; 72 Column databaseColumn = DataSetUtils.getColumn( 73 resultColumn.getColumnName(), databaseMetaData.getColumns()); 74 Column xmlColumn = xmlMetaData.getColumns()[j]; 75 76 assertEquals("column name", xmlColumn.getColumnName(), 77 resultColumn.getColumnName()); 78 assertSame("column instance", resultColumn, databaseColumn); 79 } 80 81 Column[] resultPrimaryKeys = resultMetaData.getPrimaryKeys(); 83 assertEquals("key count", databaseMetaData.getPrimaryKeys().length, 84 resultPrimaryKeys.length); 85 for (int j = 0; j < resultPrimaryKeys.length; j++) 86 { 87 Column resultPrimaryKey = resultPrimaryKeys[j]; 88 Column databasePrimaryKey = databaseMetaData.getPrimaryKeys()[j]; 89 assertSame("key instance", databasePrimaryKey, resultPrimaryKey); 90 } 91 } 92 } 93 94 public void testGetOperationMetaDataAndUnknownColumns() throws Exception 95 { 96 String tableName = "PK_TABLE"; 97 Reader in = new FileReader ("src/xml/unknownColumnTest.xml"); 98 IDataSet xmlDataSet = new XmlDataSet(in); 99 100 ITable xmlTable = xmlDataSet.getTable(tableName); 101 102 try 103 { 104 AbstractBatchOperation.getOperationMetaData(_connection, 105 xmlTable.getTableMetaData()); 106 fail("Should throw a NoSuchColumnException"); 107 } 108 catch (NoSuchColumnException e) 109 { 110 } 111 } 112 113 } 114 115 116 | Popular Tags |