1 21 package org.dbunit.dataset.xml; 22 23 import org.dbunit.dataset.Column; 24 import org.dbunit.dataset.stream.AbstractProducerTest; 25 import org.dbunit.dataset.stream.IDataSetProducer; 26 import org.dbunit.dataset.stream.MockDataSetConsumer; 27 import org.xml.sax.InputSource ; 28 29 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.io.StringReader ; 32 33 38 public class FlatDtdProducerTest extends AbstractProducerTest 39 { 40 private static final File DTD_FILE = 41 new File ("src/dtd/flatDtdProducerTest.dtd"); 42 43 public FlatDtdProducerTest(String s) 44 { 45 super(s); 46 } 47 48 protected IDataSetProducer createProducer() throws Exception 49 { 50 InputSource source = new InputSource (new FileInputStream (DTD_FILE)); 51 return new FlatDtdProducer(source); 52 } 53 54 protected int[] getExpectedRowCount() throws Exception 55 { 56 return new int[] {0, 0, 0, 0, 0, 0}; 57 } 58 59 public void testSequenceModel() throws Exception 60 { 61 MockDataSetConsumer consumer = new MockDataSetConsumer(); 63 consumer.addExpectedStartDataSet(); 64 consumer.addExpectedEmptyTableIgnoreColumns("DUPLICATE_TABLE"); 65 consumer.addExpectedEmptyTableIgnoreColumns("TEST_TABLE"); 66 consumer.addExpectedEmptyTableIgnoreColumns("DUPLICATE_TABLE"); 67 consumer.addExpectedEndDataSet(); 68 69 String content = 71 "<!ELEMENT dataset (DUPLICATE_TABLE*,TEST_TABLE+,DUPLICATE_TABLE?)>" + 72 "<!ELEMENT TEST_TABLE EMPTY>" + 73 "<!ELEMENT DUPLICATE_TABLE EMPTY>"; 74 InputSource source = new InputSource (new StringReader (content)); 75 FlatDtdProducer producer = new FlatDtdProducer(source); 76 producer.setConsumer(consumer); 77 78 producer.produce(); 80 consumer.verify(); 81 } 82 83 public void testChoicesModel() throws Exception 84 { 85 MockDataSetConsumer consumer = new MockDataSetConsumer(); 87 consumer.addExpectedStartDataSet(); 88 consumer.addExpectedEmptyTableIgnoreColumns("TEST_TABLE"); 89 consumer.addExpectedEmptyTableIgnoreColumns("SECOND_TABLE"); 90 consumer.addExpectedEndDataSet(); 91 92 String content = 94 "<!ELEMENT dataset (TEST_TABLE|SECOND_TABLE)>" + 95 "<!ELEMENT TEST_TABLE EMPTY>" + 96 "<!ELEMENT SECOND_TABLE EMPTY>"; 97 InputSource source = new InputSource (new StringReader (content)); 98 FlatDtdProducer producer = new FlatDtdProducer(source); 99 producer.setConsumer(consumer); 100 101 producer.produce(); 103 consumer.verify(); 104 } 105 106 public void testAttrListBeforeParentElement() throws Exception 107 { 108 MockDataSetConsumer consumer = new MockDataSetConsumer(); 110 consumer.addExpectedStartDataSet(); 111 Column[] expectedColumns = createExpectedColumns(Column.NULLABLE); 112 consumer.addExpectedEmptyTable("TEST_TABLE", expectedColumns); 113 consumer.addExpectedEndDataSet(); 114 115 String content = 117 "<!ELEMENT dataset (TEST_TABLE)>" + 118 "<!ATTLIST TEST_TABLE " + 119 "COLUMN0 CDATA #IMPLIED " + 120 "COLUMN1 CDATA #IMPLIED " + 121 "COLUMN2 CDATA #IMPLIED " + 122 "COLUMN3 CDATA #IMPLIED>" + 123 "<!ELEMENT TEST_TABLE EMPTY>"; 124 125 InputSource source = new InputSource (new StringReader (content)); 126 FlatDtdProducer producer = new FlatDtdProducer(source); 127 producer.setConsumer(consumer); 128 129 producer.produce(); 131 consumer.verify(); 132 } 133 } 134 | Popular Tags |