1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.dbunit.dataset;
23
24 import java.io.FileNotFoundException;
25 import java.io.FileReader;
26 import java.io.IOException;
27
28 import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
29 import org.dbunit.dataset.xml.XmlDataSet;
30 import org.dbunit.testutil.TestUtils;
31
32
33
34
35
36
37
38 public class CompositeDataSetTest extends AbstractDataSetTest
39 {
40 public CompositeDataSetTest(String s)
41 {
42 super(s);
43 }
44
45 protected IDataSet createDataSet() throws Exception
46 {
47 IDataSet dataSet1 = new XmlDataSet(
48 TestUtils.getFileReader("xml/compositeDataSetTest1.xml"));
49 assertTrue("count before combine (1)",
50 dataSet1.getTableNames().length < getExpectedNames().length);
51
52 IDataSet dataSet2 = new XmlDataSet(
53 TestUtils.getFileReader("xml/compositeDataSetTest2.xml"));
54 assertTrue("count before combine (2)",
55 dataSet2.getTableNames().length < getExpectedNames().length);
56
57 return new CompositeDataSet(dataSet1, dataSet2);
58 }
59
60 protected IDataSet createDuplicateDataSet() throws Exception
61 {
62 return createCompositeDataSet(false, false);
63 }
64
65 protected IDataSet createMultipleCaseDuplicateDataSet() throws Exception
66 {
67 return createCompositeDataSet(false, true);
68 }
69
70
71 public void testCombineTables() throws Exception
72 {
73 CompositeDataSet combinedDataSet = createCompositeDataSet(true, false);
74 String[] tableNames = combinedDataSet.getTableNames();
75 assertEquals("table count combined", 2, tableNames.length);
76 assertEquals("DUPLICATE_TABLE", tableNames[0]);
77 assertEquals("EMPTY_TABLE", tableNames[1]);
78 }
79
80
81 private CompositeDataSet createCompositeDataSet(boolean combined, boolean multipleCase)
82 throws DataSetException, FileNotFoundException, IOException
83 {
84 IDataSet dataSet1 = new FlatXmlDataSetBuilder().build(
85 TestUtils.getFileReader("xml/compositeDataSetDuplicateTest1.xml"));
86 assertTrue("count before combine (1)",
87 dataSet1.getTableNames().length < getExpectedDuplicateNames().length);
88
89 IDataSet dataSet2 = new FlatXmlDataSetBuilder().build(
90 TestUtils.getFileReader("xml/compositeDataSetDuplicateTest2.xml"));
91 assertTrue("count before combine (2)",
92 dataSet2.getTableNames().length < getExpectedDuplicateNames().length);
93
94 if(multipleCase){
95 dataSet2 = new LowerCaseDataSet(dataSet2);
96 }
97
98 CompositeDataSet dataSet = new CompositeDataSet(dataSet1, dataSet2, combined);
99 return dataSet;
100 }
101
102 }
103
104
105
106