1 package org.dbunit.dataset.xml; 2 3 import junit.framework.TestCase; 4 import org.dbunit.dataset.Column; 5 import org.dbunit.dataset.DefaultDataSet; 6 import org.dbunit.dataset.DefaultTable; 7 import org.dbunit.dataset.datatype.DataType; 8 9 import java.io.StringWriter ; 10 11 17 public class FlatDtdWriterTest extends TestCase 18 { 19 public void testWriteSequenceModel() throws Exception 20 { 21 String expectedOutput = 22 "<!ELEMENT dataset (\n" + 23 " TABLE1*,\n" + 24 " TABLE2*)>\n" + 25 "\n" + 26 "<!ELEMENT TABLE1 EMPTY>\n" + 27 "<!ATTLIST TABLE1\n" + 28 " COL0 CDATA #IMPLIED\n" + 29 " COL1 CDATA #IMPLIED\n" + 30 " COL2 CDATA #REQUIRED\n" + 31 ">\n" + 32 "\n" + 33 "<!ELEMENT TABLE2 EMPTY>\n" + 34 "<!ATTLIST TABLE2\n" + 35 " COL0 CDATA #IMPLIED\n" + 36 " COL1 CDATA #IMPLIED\n" + 37 " COL2 CDATA #REQUIRED\n" + 38 ">\n" + 39 "\n"; 40 41 Column[] columns = new Column[]{ 42 new Column("COL0", DataType.UNKNOWN, Column.NULLABLE), 43 new Column("COL1", DataType.UNKNOWN, Column.NULLABLE_UNKNOWN), 44 new Column("COL2", DataType.UNKNOWN, Column.NO_NULLS), 45 }; 46 47 DefaultTable table1 = new DefaultTable("TABLE1", columns); 48 DefaultTable table2 = new DefaultTable("TABLE2", columns); 49 50 StringWriter stringWriter = new StringWriter (); 51 FlatDtdWriter dtdWriter = new FlatDtdWriter(stringWriter); 52 dtdWriter.write(new DefaultDataSet(table1, table2)); 53 54 String actualOutput = stringWriter.toString(); 55 assertEquals("output", expectedOutput, actualOutput); 56 } 57 58 public void testWriteChoiceModel() throws Exception 59 { 60 String expectedOutput = 61 "<!ELEMENT dataset (\n" + 62 " (TABLE1|\n" + 63 " TABLE2)*)>\n" + 64 "\n" + 65 "<!ELEMENT TABLE1 EMPTY>\n" + 66 "<!ATTLIST TABLE1\n" + 67 " COL0 CDATA #IMPLIED\n" + 68 " COL1 CDATA #IMPLIED\n" + 69 " COL2 CDATA #REQUIRED\n" + 70 ">\n" + 71 "\n" + 72 "<!ELEMENT TABLE2 EMPTY>\n" + 73 "<!ATTLIST TABLE2\n" + 74 " COL0 CDATA #IMPLIED\n" + 75 " COL1 CDATA #IMPLIED\n" + 76 " COL2 CDATA #REQUIRED\n" + 77 ">\n" + 78 "\n"; 79 80 Column[] columns = new Column[]{ 81 new Column("COL0", DataType.UNKNOWN, Column.NULLABLE), 82 new Column("COL1", DataType.UNKNOWN, Column.NULLABLE_UNKNOWN), 83 new Column("COL2", DataType.UNKNOWN, Column.NO_NULLS), 84 }; 85 86 DefaultTable table1 = new DefaultTable("TABLE1", columns); 87 DefaultTable table2 = new DefaultTable("TABLE2", columns); 88 89 StringWriter stringWriter = new StringWriter (); 90 FlatDtdWriter dtdWriter = new FlatDtdWriter(stringWriter); 91 dtdWriter.setContentModel(FlatDtdWriter.CHOICE); 92 dtdWriter.write(new DefaultDataSet(table1, table2)); 93 94 String actualOutput = stringWriter.toString(); 95 assertEquals("output", expectedOutput, actualOutput); 96 } 97 98 } 99 | Popular Tags |