View Javadoc
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  
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   * @author Manuel Laflamme
34   * @author Last changed by: $Author$
35   * @version $Revision$ $Date$
36   * @since 1.0 (Feb 22, 2002)
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