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.xml;
23  
24  import org.dbunit.dataset.AbstractTableTest;
25  import org.dbunit.dataset.Column;
26  import org.dbunit.dataset.IDataSet;
27  import org.dbunit.dataset.ITable;
28  import org.dbunit.testutil.TestUtils;
29  
30  import java.io.File;
31  
32  /**
33   * @author Manuel Laflamme
34   * @version $Revision$
35   * @since Mar 12, 2002
36   */
37  public class FlatXmlTableTest extends AbstractTableTest
38  {
39      public FlatXmlTableTest(String s)
40      {
41          super(s);
42      }
43  
44      protected ITable createTable() throws Exception
45      {
46          return createDataSet(true).getTable("TEST_TABLE");
47      }
48  
49      protected IDataSet createDataSet(boolean noneAsNull) throws Exception
50      {
51          return new FlatXmlDataSetBuilder().build(TestUtils.getFile("xml/flatXmlTableTest.xml"));
52      }
53  
54      public void testGetMissingValue() throws Exception
55      {
56          int row = 0;
57          Object[] expected = {"row 1 col 0", null, "row 1 col 2"};
58  
59          ITable table = createDataSet(false).getTable("MISSING_VALUES");
60  
61          Column[] columns = table.getTableMetaData().getColumns();
62          assertEquals("column count", expected.length, columns.length);
63          assertEquals("row count", 1, table.getRowCount());
64          for (int i = 0; i < columns.length; i++)
65          {
66              assertEquals("value " + i, expected[i],
67                      table.getValue(row, columns[i].getColumnName()));
68          }
69      }
70  
71      public void testLoadCRLF() throws Exception
72      {
73          int row = 0;
74          Object[] expected = {"row 0 \n col 0 \r"}; // in the expected result the &#xA; and &#xD; should be replaced by \n and \r
75  
76          ITable table = createDataSet(false).getTable("TABLE_VALUE_METACHARS");
77  
78          Column[] columns = table.getTableMetaData().getColumns();
79          assertEquals("column count", expected.length, columns.length);
80          assertEquals("row count", 1, table.getRowCount());
81          for (int i = 0; i < columns.length; i++)
82          {
83              assertEquals("value " + i, expected[i],
84                      table.getValue(row, columns[i].getColumnName()));
85          }
86      }
87      
88      
89  //    public void testGetValueAndNoSuchColumn() throws Exception
90  //    {
91  //        ITable table = createTable();
92  //        String columnName = "Unknown";
93  //
94  //        Object value = table.getValue(0, columnName);
95  //        assertEquals("no value", null, value);
96  //    }
97  
98  }
99  
100 
101 
102 
103 
104 
105 
106 
107