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.csv;
23  
24  
25  import java.io.File;
26  import java.net.MalformedURLException;
27  import java.net.URL;
28  
29  import junit.framework.TestCase;
30  
31  import org.dbunit.dataset.DataSetException;
32  import org.dbunit.dataset.ITable;
33  import org.dbunit.testutil.TestUtils;
34  
35  /**
36   * @author Lenny Marks (lenny@aps.org)
37   * @author dIon gillard (diongillard@users.sourceforge.net)
38   * @version $Revision$
39   * @since 2.1.0
40   */
41  public class CsvURLDataSetTest extends TestCase {
42      
43      public CsvURLDataSetTest(String s) {
44          super(s);
45      }
46  
47      public void testNullColumns() throws DataSetException, MalformedURLException {
48  		URL csvDir = TestUtils.getFile("csv/orders/").toURL();
49      	CsvURLDataSet dataSet = new CsvURLDataSet(csvDir);
50      	
51      	ITable table = dataSet.getTable("orders");
52      	assertNull(table.getValue(4, "description"));
53      }
54  
55      public void testSpacesInColumns() throws DataSetException, MalformedURLException {
56  		URL csvDir = TestUtils.getFile("csv/accounts/").toURL();
57      	CsvURLDataSet dataSet = new CsvURLDataSet(csvDir);
58      	
59      	ITable table = dataSet.getTable("accounts");
60      	assertEquals("   123", table.getValue(0, "acctid"));
61      	assertEquals("  2", table.getValue(1, "acctid"));
62      	assertEquals("   3spaces", table.getValue(2, "acctid"));
63      	assertEquals("    -4", table.getValue(3, "acctid"));
64      	assertEquals("     5     ", table.getValue(4, "acctid"));
65      }
66  
67  }
68  
69  
70  
71