001: /*
002: * CSVParserTest.java
003: *
004: * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019: *
020: * Version: $Revision: 1.3 $
021: */
022: package net.sf.anupam.csv;
023:
024: import junit.framework.TestCase;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import test.net.sf.anupam.csv.beans.Designation;
028: import test.net.sf.anupam.csv.beans.Employee;
029:
030: import java.io.FileNotFoundException;
031:
032: import net.sf.anupam.csv.exceptions.CSVOException;
033:
034: /**
035: * CSVParserTest.
036: *
037: * @author Anupam Sengupta
038: * @version $Revision: 1.3 $
039: */
040: public class CSVParserTest extends TestCase {
041:
042: /**
043: * The sample data file to use for the test.
044: */
045: private static final String SAMPLE_CSV_FILE = "test/net/sf/anupam/csv/beans/sample.csv";
046:
047: /**
048: * The logger to use.
049: */
050: private Log log = LogFactory.getLog(CSVParserTest.class);
051:
052: /**
053: * Constructor for CSVParserTest.
054: *
055: * @param name name of the test
056: */
057: public CSVParserTest(final String name) {
058: super (name);
059: }
060:
061: /**
062: * Main method to run the test.
063: *
064: * @param args Program arguments
065: */
066: public static void main(final String[] args) {
067: junit.textui.TestRunner.run(CSVParserTest.class);
068: }
069:
070: /**
071: * Test method for 'com.tcs.mis.csv.utilities.CSVParser.getMappedBeans()'.
072: *
073: * @throws net.sf.anupam.csv.exceptions.CSVOException
074: *
075: */
076: public void testGetMappedBeans() throws CSVOException {
077: final CSVParserFactory factory = CSVParserFactory
078: .getSingleton();
079: assertNotNull(factory);
080: try {
081: final CSVParser parser = factory.getCSVParser(
082: "employeeBean", SAMPLE_CSV_FILE, true);
083: assertNotNull(parser);
084: for (Object bean : parser) {
085: assertTrue(bean instanceof Employee);
086: final Employee empl = (Employee) bean;
087: assertEquals("123456", empl.getEmployeeID());
088: assertEquals("John", empl.getFirstName());
089: assertEquals("Doe", empl.getLastName());
090: assertEquals("BILLID01", empl.getClientSuppliedID());
091: assertEquals("CONTRACTOR007", empl
092: .getClientSuppliedSecondaryID());
093: final Designation desgn = empl.getDesignation();
094: assertNotNull(desgn);
095: assertEquals("Lead", desgn.getDesignation());
096: log.info(empl);
097: }
098: } catch (final FileNotFoundException e) {
099: fail("Unexpected exception: " + e.getLocalizedMessage());
100: }
101:
102: }
103:
104: }
|