1 21 22 package org.dbunit.dataset.xml; 23 24 import org.dbunit.Assertion; 25 import org.dbunit.dataset.*; 26 27 import java.io.File ; 28 import java.io.FileReader ; 29 import java.io.FileWriter ; 30 import java.io.Writer ; 31 32 37 public class FlatXmlTableWriteTest extends FlatXmlTableTest 38 { 39 public FlatXmlTableWriteTest(String s) 40 { 41 super(s); 42 } 43 44 protected IDataSet createDataSet() throws Exception 45 { 46 File tempFile = File.createTempFile("flatXmlTableWriteTest", ".xml"); 47 Writer out = new FileWriter (tempFile); 48 try 49 { 50 try 52 { 53 FlatXmlDataSet.write(super.createDataSet(true), out); 54 } 55 finally 56 { 57 out.close(); 58 } 59 60 FileReader in = new FileReader (tempFile); 62 try 63 { 64 return new FlatXmlDataSet(in); 65 } 66 finally 67 { 68 in.close(); 69 } 70 } 71 finally 72 { 73 tempFile.delete(); 74 } 75 } 76 77 public void testWriteMultipleTable() throws Exception 78 { 79 int tableCount = 5; 80 ITable sourceTable = super.createTable(); 81 82 ITable[] tables = new ITable[tableCount]; 83 for (int i = 0; i < tables.length; i++) 84 { 85 ITableMetaData metaData = new DefaultTableMetaData("table" + i, 86 sourceTable.getTableMetaData().getColumns()); 87 tables[i] = new CompositeTable(metaData, sourceTable); 88 } 89 90 IDataSet dataSet = new DefaultDataSet(tables); 91 File tempFile = File.createTempFile("flatXmlTableWriteTest", "xml"); 92 Writer out = new FileWriter (tempFile); 93 try 94 { 95 try 97 { 98 FlatXmlDataSet.write(dataSet, out); 99 } 100 finally 101 { 102 out.close(); 103 } 104 105 FileReader in = new FileReader (tempFile); 107 try 108 { 109 FlatXmlDataSet xmlDataSet2 = new FlatXmlDataSet(in); 110 111 for (int i = 0; i < tables.length; i++) 113 { 114 ITable table = tables[i]; 115 Assertion.assertEquals(table, xmlDataSet2.getTable(xmlDataSet2.getTableNames()[i])); 116 } 117 } 118 finally 119 { 120 in.close(); 121 } 122 } 123 finally 124 { 125 tempFile.delete(); 126 } 127 } 128 129 } 130 131 132 133 134 135 136 137 | Popular Tags |