1 21 22 package org.dbunit; 23 24 import org.dbunit.database.DatabaseConfig; 25 import org.dbunit.database.DatabaseConnection; 26 import org.dbunit.database.ForwardOnlyResultSetTableFactory; 27 import org.dbunit.database.IDatabaseConnection; 28 import org.dbunit.dataset.DataSetException; 29 import org.dbunit.dataset.IDataSet; 30 import org.dbunit.dataset.excel.XlsDataSet; 31 import org.dbunit.dataset.stream.IDataSetProducer; 32 import org.dbunit.dataset.stream.MockDataSetProducer; 33 import org.dbunit.dataset.stream.StreamingDataSet; 34 import org.dbunit.dataset.xml.*; 35 import org.xml.sax.InputSource ; 36 37 import java.io.*; 38 import java.sql.Connection ; 39 40 47 public class Main 48 { 49 public static void main(String [] args) throws Exception 50 { 51 53 testXmlWriter(); 55 56 83 84 } 102 103 private static void testFlatXmlWriter() throws Exception 104 { 105 MockDataSetProducer mockProducer = new MockDataSetProducer(); 106 mockProducer.setupColumnCount(5); 107 mockProducer.setupRowCount(100000); 108 mockProducer.setupTableCount(10); 109 IDataSet dataSet = new StreamingDataSet(mockProducer); 110 111 OutputStream out = new FileOutputStream("flatXmlWriterTest.xml"); 112 FlatXmlWriter writer = new FlatXmlWriter(new OutputStreamWriter(out, "UTF8")); 113 writer.write(dataSet); 114 } 115 116 private static void testXmlWriter() throws Exception 117 { 118 MockDataSetProducer mockProducer = new MockDataSetProducer(); 119 mockProducer.setupColumnCount(5); 120 mockProducer.setupRowCount(100000); 121 mockProducer.setupTableCount(10); 122 IDataSet dataSet = new StreamingDataSet(mockProducer); 123 124 OutputStream out = new FileOutputStream("xmlWriterTest.xml"); 125 XmlDataSetWriter writer = new XmlDataSetWriter(new OutputStreamWriter(out, "UTF8")); 126 writer.write(dataSet); 127 } 128 129 138 public void test() throws Exception 139 { 140 Connection jdbcConnection = null; 141 IDatabaseConnection connection = new DatabaseConnection(jdbcConnection, ""); 142 DatabaseConfig config = connection.getConfig(); 143 144 config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, 146 new ForwardOnlyResultSetTableFactory()); 147 148 IDataSetProducer producer = new FlatXmlProducer( 150 new InputSource ("dataset.xml")); 151 IDataSet dataSet = new StreamingDataSet(producer); 152 } 153 154 155 private static void oldMain() throws Exception 156 { 157 158 IDatabaseConnection connection = 160 DatabaseEnvironment.getInstance().getConnection(); 161 164 Writer out = new FileWriter("test.xml"); 172 FlatXmlDataSet.write(connection.createDataSet(), out); 174 177 178 191 } 197 198 private static void writeXls() throws IOException, DataSetException 199 { 200 Reader in = new FileReader( 201 "P:/dbunit-cvs/dbunit/src/xml/dataSetTest.xml"); 202 FileOutputStream out = new FileOutputStream( 203 "P:/dbunit-cvs/dbunit/dataSetTest.xls"); 204 XlsDataSet.write(new XmlDataSet(in), out); 205 out.close(); 206 } 207 208 303 304 } 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | Popular Tags |