1 21 22 package org.dbunit.dataset.xml; 23 24 import org.dbunit.DatabaseEnvironment; 25 import org.dbunit.database.IDatabaseConnection; 26 import org.dbunit.dataset.*; 27 import org.dbunit.util.FileAsserts; 28 29 import java.io.*; 30 31 36 public class FlatDtdDataSetTest extends AbstractDataSetTest 37 { 38 private static final File DTD_FILE = 39 new File("src/dtd/flatDtdDataSetTest.dtd"); 40 private static final File DUPLICATE_FILE = 41 new File("src/dtd/flatDtdDataSetDuplicateTest.dtd"); 42 43 public FlatDtdDataSetTest(String s) 44 { 45 super(s); 46 } 47 48 51 protected IDataSet createDataSet() throws Exception 52 { 53 return new FlatDtdDataSet(new FileReader(DTD_FILE)); 54 } 55 56 protected IDataSet createDuplicateDataSet() throws Exception 57 { 58 return new FlatDtdDataSet(new FileReader(DUPLICATE_FILE)); 59 } 60 61 protected int[] getExpectedDuplicateRows() 62 { 63 return new int[] {0, 0, 0}; 64 } 65 66 69 public void testGetDuplicateTable() throws Exception 70 { 71 String expectedTableName = getDuplicateTableName(); 72 73 IDataSet dataSet = createDuplicateDataSet(); 74 ITable table = dataSet.getTable(expectedTableName); 75 String actualTableName = table.getTableMetaData().getTableName(); 76 assertEquals("table name", expectedTableName, actualTableName); 77 } 78 79 public void testGetDuplicateTableMetaData() throws Exception 80 { 81 String expectedTableName = getDuplicateTableName(); 82 83 IDataSet dataSet = createDuplicateDataSet(); 84 ITableMetaData metaData = dataSet.getTableMetaData(expectedTableName); 85 String actualTableName = metaData.getTableName(); 86 assertEquals("table name", expectedTableName, actualTableName); 87 } 88 89 public void testWriteFromDtd() throws Exception 90 { 91 IDataSet dataSet = new FlatDtdDataSet(new FileReader(DTD_FILE)); 92 93 File tempFile = File.createTempFile("flatXmlDocType", ".dtd"); 94 95 try 96 { 97 Writer out = new FileWriter(tempFile); 98 99 try 100 { 101 FlatDtdDataSet.write(dataSet, out); 103 } 104 finally 105 { 106 out.close(); 107 } 108 109 FileAsserts.assertEquals( 110 new BufferedReader(new FileReader(DTD_FILE)), 111 new BufferedReader(new FileReader(tempFile))); 112 } 113 finally 114 { 115 tempFile.delete(); 116 } 117 118 } 119 120 public void testWriteFromDatabase() throws Exception 121 { 122 IDatabaseConnection connection = 123 DatabaseEnvironment.getInstance().getConnection(); 124 IDataSet dataSet = connection.createDataSet(); 125 126 File tempFile = File.createTempFile("flatXmlDocType", ".dtd"); 127 128 try 129 { 130 Writer out = new FileWriter(tempFile); 131 132 try 133 { 134 String [] tableNames = getExpectedNames(); 136 FlatDtdDataSet.write(new FilteredDataSet( 137 tableNames, dataSet), out); 138 } 139 finally 140 { 141 out.close(); 142 } 143 144 FileAsserts.assertEquals( 145 new BufferedReader(new FileReader(DTD_FILE)), 146 new BufferedReader(new FileReader(tempFile))); 147 } 148 finally 149 { 150 tempFile.delete(); 151 } 152 } 153 154 155 } 156 157 158 159 160 161 | Popular Tags |