KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > xml > FlatDtdProducerTest


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

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 JavaDoc;
28
29 import java.io.File JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.StringReader JavaDoc;
32
33 /**
34  * @author Manuel Laflamme
35  * @since Apr 29, 2003
36  * @version $Revision: 1.5 $
37  */

38 public class FlatDtdProducerTest extends AbstractProducerTest
39 {
40     private static final File JavaDoc DTD_FILE =
41             new File JavaDoc("src/dtd/flatDtdProducerTest.dtd");
42
43     public FlatDtdProducerTest(String JavaDoc s)
44     {
45         super(s);
46     }
47
48     protected IDataSetProducer createProducer() throws Exception JavaDoc
49     {
50         InputSource JavaDoc source = new InputSource JavaDoc(new FileInputStream JavaDoc(DTD_FILE));
51         return new FlatDtdProducer(source);
52     }
53
54     protected int[] getExpectedRowCount() throws Exception JavaDoc
55     {
56         return new int[] {0, 0, 0, 0, 0, 0};
57     }
58
59     public void testSequenceModel() throws Exception JavaDoc
60     {
61         // Setup consumer
62
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         // Setup producer
70
String JavaDoc content =
71                 "<!ELEMENT dataset (DUPLICATE_TABLE*,TEST_TABLE+,DUPLICATE_TABLE?)>" +
72                 "<!ELEMENT TEST_TABLE EMPTY>" +
73                 "<!ELEMENT DUPLICATE_TABLE EMPTY>";
74         InputSource JavaDoc source = new InputSource JavaDoc(new StringReader JavaDoc(content));
75         FlatDtdProducer producer = new FlatDtdProducer(source);
76         producer.setConsumer(consumer);
77
78         // Produce and verify consumer
79
producer.produce();
80         consumer.verify();
81     }
82
83     public void testChoicesModel() throws Exception JavaDoc
84     {
85         // Setup consumer
86
MockDataSetConsumer consumer = new MockDataSetConsumer();
87         consumer.addExpectedStartDataSet();
88         consumer.addExpectedEmptyTableIgnoreColumns("TEST_TABLE");
89         consumer.addExpectedEmptyTableIgnoreColumns("SECOND_TABLE");
90         consumer.addExpectedEndDataSet();
91
92         // Setup producer
93
String JavaDoc content =
94                 "<!ELEMENT dataset (TEST_TABLE|SECOND_TABLE)>" +
95                 "<!ELEMENT TEST_TABLE EMPTY>" +
96                 "<!ELEMENT SECOND_TABLE EMPTY>";
97         InputSource JavaDoc source = new InputSource JavaDoc(new StringReader JavaDoc(content));
98         FlatDtdProducer producer = new FlatDtdProducer(source);
99         producer.setConsumer(consumer);
100
101         // Produce and verify consumer
102
producer.produce();
103         consumer.verify();
104     }
105
106     public void testAttrListBeforeParentElement() throws Exception JavaDoc
107     {
108         // Setup consumer
109
MockDataSetConsumer consumer = new MockDataSetConsumer();
110         consumer.addExpectedStartDataSet();
111         Column[] expectedColumns = createExpectedColumns(Column.NULLABLE);
112         consumer.addExpectedEmptyTable("TEST_TABLE", expectedColumns);
113         consumer.addExpectedEndDataSet();
114
115         // Setup producer
116
String JavaDoc 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 JavaDoc source = new InputSource JavaDoc(new StringReader JavaDoc(content));
126         FlatDtdProducer producer = new FlatDtdProducer(source);
127         producer.setConsumer(consumer);
128
129         // Produce and verify consumer
130
producer.produce();
131         consumer.verify();
132     }
133 }
134
Popular Tags