| 1 22 package net.sf.anupam.csv; 23 24 import junit.framework.TestCase; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import test.net.sf.anupam.csv.beans.Designation; 28 import test.net.sf.anupam.csv.beans.Employee; 29 30 import java.io.FileNotFoundException ; 31 32 import net.sf.anupam.csv.exceptions.CSVOException; 33 34 40 public class CSVParserTest 41 extends TestCase { 42 43 46 private static final String SAMPLE_CSV_FILE = "test/net/sf/anupam/csv/beans/sample.csv"; 47 48 51 private Log log = LogFactory 52 .getLog(CSVParserTest.class); 53 54 59 public CSVParserTest(final String name) { 60 super(name); 61 } 62 63 68 public static void main(final String [] args) { 69 junit.textui.TestRunner.run(CSVParserTest.class); 70 } 71 72 78 public void testGetMappedBeans() throws CSVOException { 79 final CSVParserFactory factory = CSVParserFactory.getSingleton(); 80 assertNotNull(factory); 81 try { 82 final CSVParser parser = factory.getCSVParser("employeeBean", 83 SAMPLE_CSV_FILE, true); 84 assertNotNull(parser); 85 for (Object bean : parser) { 86 assertTrue(bean instanceof Employee); 87 final Employee empl = (Employee) bean; 88 assertEquals("123456", empl.getEmployeeID()); 89 assertEquals("John", empl.getFirstName()); 90 assertEquals("Doe", empl.getLastName()); 91 assertEquals("BILLID01", empl.getClientSuppliedID()); 92 assertEquals("CONTRACTOR007", empl.getClientSuppliedSecondaryID()); 93 final Designation desgn = empl.getDesignation(); 94 assertNotNull(desgn); 95 assertEquals("Lead", desgn.getDesignation()); 96 log.info(empl); 97 } 98 } catch (final FileNotFoundException e) { 99 fail("Unexpected exception: " 100 + e.getLocalizedMessage()); 101 } 102 103 } 104 105 } 106 | Popular Tags |