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 XmlTableWriteTest extends XmlTableTest 38 { 39 public XmlTableWriteTest(String s) 40 { 41 super(s); 42 } 43 44 protected IDataSet createDataSet() throws Exception 45 { 46 File tempFile = File.createTempFile("xmlDataSetWriteTest", ".xml"); 47 Writer out = new FileWriter (tempFile); 48 try 49 { 50 try 52 { 53 XmlDataSet.write(super.createDataSet(), out); 54 } 55 finally 56 { 57 out.close(); 58 } 59 60 FileReader in = new FileReader (tempFile); 62 try 63 { 64 return new XmlDataSet(in); 65 } 66 finally 67 { 68 in.close(); 69 } 70 } 71 finally 72 { 73 tempFile.delete(); 74 } 75 76 } 77 78 public void testWriteMultipleTable() throws Exception 79 { 80 int tableCount = 5; 81 ITable sourceTable = super.createTable(); 82 83 ITable[] tables = new ITable[tableCount]; 84 for (int i = 0; i < tables.length; i++) 85 { 86 ITableMetaData metaData = new DefaultTableMetaData("table" + i, 87 sourceTable.getTableMetaData().getColumns()); 88 tables[i] = new CompositeTable(metaData, sourceTable); 89 } 90 91 IDataSet dataSet = new DefaultDataSet(tables); 92 File tempFile = File.createTempFile("xmlDataSetWriteTest", "xml"); 93 Writer out = new FileWriter (tempFile); 94 try 95 { 96 try 98 { 99 XmlDataSet.write(dataSet, out); 100 } 101 finally 102 { 103 out.close(); 104 } 105 106 FileReader in = new FileReader (tempFile); 108 try 109 { 110 XmlDataSet xmlDataSet2 = new XmlDataSet(in); 111 112 for (int i = 0; i < tables.length; i++) 114 { 115 ITable table = tables[i]; 116 Assertion.assertEquals(table, xmlDataSet2.getTable(xmlDataSet2.getTableNames()[i])); 117 } 118 } 119 finally 120 { 121 in.close(); 122 } 123 } 124 finally 125 { 126 tempFile.delete(); 127 } 128 129 } 130 131 } 132 133 134 135 136 | Popular Tags |