1 21 package org.dbunit.dataset.excel; 22 23 import org.dbunit.Assertion; 24 import org.dbunit.dataset.*; 25 26 import java.io.*; 27 28 33 public class XlsTableWriteTest extends XlsTableTest 34 { 35 public XlsTableWriteTest(String s) 36 { 37 super(s); 38 } 39 40 protected IDataSet createDataSet() throws Exception 41 { 42 File tempFile = File.createTempFile("tableWriteTest", ".xls"); 43 OutputStream out = new FileOutputStream(tempFile); 45 try 46 { 47 try 49 { 50 XlsDataSet.write(super.createDataSet(), out); 51 } 52 finally 53 { 54 out.close(); 55 } 56 57 InputStream in = new FileInputStream(tempFile); 59 try 60 { 61 return new XlsDataSet(in); 62 } 63 finally 64 { 65 in.close(); 66 } 67 } 68 finally 69 { 70 tempFile.delete(); 71 } 72 } 73 74 public void testGetValue() throws Exception 75 { 76 super.testGetValue(); 77 } 78 79 80 public void testWriteMultipleTable() throws Exception 81 { 82 int tableCount = 5; 83 ITable sourceTable = super.createTable(); 84 85 ITable[] tables = new ITable[tableCount]; 86 for (int i = 0; i < tables.length; i++) 87 { 88 ITableMetaData metaData = new DefaultTableMetaData("table" + i, 89 sourceTable.getTableMetaData().getColumns()); 90 tables[i] = new CompositeTable(metaData, sourceTable); 91 } 92 93 IDataSet dataSet = new DefaultDataSet(tables); 94 File tempFile = File.createTempFile("tableWriteTest", ".xls"); 95 OutputStream out = new FileOutputStream(tempFile); 96 try 97 { 98 try 100 { 101 XlsDataSet.write(dataSet, out); 102 } 103 finally 104 { 105 out.close(); 106 } 107 108 FileInputStream in = new FileInputStream(tempFile); 110 try 111 { 112 XlsDataSet dataSet2 = new XlsDataSet(in); 113 114 for (int i = 0; i < tables.length; i++) 116 { 117 ITable table = tables[i]; 118 Assertion.assertEquals(table, 119 dataSet2.getTable(dataSet2.getTableNames()[i])); 120 } 121 } 122 finally 123 { 124 in.close(); 125 } 126 127 } 128 finally 129 { 130 tempFile.delete(); 131 } 132 } 133 134 } 135 | Popular Tags |