r2896 - in branches/pollen-1.2.3-1.2.x: . pollen-business pollen-ui pollen-ui/src/main/java/org/chorem/pollen/ui/utils pollen-ui/src/test pollen-ui/src/test/java/org/chorem/pollen/ui pollen-ui/src/test/java/org/chorem/pollen/ui/utils pollen-ui/src/test/resources pollen-votecounting
Author: fdesbois Date: 2010-03-05 10:55:30 +0100 (Fri, 05 Mar 2010) New Revision: 2896 Log: Ano #127 : Import CSV problem Added: branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/ branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/resources/ branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/resources/import.csv Modified: branches/pollen-1.2.3-1.2.x/pollen-business/pom.xml branches/pollen-1.2.3-1.2.x/pollen-ui/pom.xml branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java branches/pollen-1.2.3-1.2.x/pollen-votecounting/pom.xml branches/pollen-1.2.3-1.2.x/pom.xml Modified: branches/pollen-1.2.3-1.2.x/pollen-business/pom.xml =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-business/pom.xml 2010-03-05 09:29:40 UTC (rev 2895) +++ branches/pollen-1.2.3-1.2.x/pollen-business/pom.xml 2010-03-05 09:55:30 UTC (rev 2896) @@ -10,7 +10,7 @@ <parent> <groupId>org.chorem</groupId> <artifactId>pollen</artifactId> - <version>1.2.3</version> + <version>1.2.4-SNAPSHOT</version> </parent> <groupId>org.chorem.pollen</groupId> Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/pom.xml =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/pom.xml 2010-03-05 09:29:40 UTC (rev 2895) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/pom.xml 2010-03-05 09:55:30 UTC (rev 2896) @@ -10,7 +10,7 @@ <parent> <groupId>org.chorem</groupId> <artifactId>pollen</artifactId> - <version>1.2.3</version> + <version>1.2.4-SNAPSHOT</version> </parent> <groupId>org.chorem.pollen</groupId> Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java 2010-03-05 09:29:40 UTC (rev 2895) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java 2010-03-05 09:55:30 UTC (rev 2896) @@ -41,10 +41,12 @@ private static final Log log = LogFactory.getLog(CSVAccountUtil.class); /** - * Import d'une liste de votants à partir d'un flux (fichier CSV). + * CSV import from a reader. The CSV file contains three columns + * corresponding to 'votingId', 'email' and 'weight'.No header column is + * needed, the separator is ','. Ex : "toto","toto@titi.fr","3" * - * @param reader le flux - * @return la liste de votants + * @param reader which contains the input stream + * @return the new PollAccountDTO list from results imported */ public static List<PollAccountDTO> importList(Reader reader) { List<PollAccountDTO> accounts = null; @@ -53,6 +55,7 @@ ColumnPositionMappingStrategy<PollAccountDTO> strat = new ColumnPositionMappingStrategy<PollAccountDTO>(); String[] columns = new String[] { "votingId", "email", "weight" }; + strat.setType(PollAccountDTO.class); strat.setColumnMapping(columns); // Parsing du fichier CSV @@ -78,6 +81,8 @@ * Import d'une liste de votants à partir d'un fichier CSV. * * @param file le fichier CSV + * @return a PollAccountDTO list + * @see #importList(java.io.Reader) */ public static List<PollAccountDTO> importList(UploadedFile file) { if (log.isInfoEnabled()) { Added: branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java (rev 0) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java 2010-03-05 09:55:30 UTC (rev 2896) @@ -0,0 +1,69 @@ + +package org.chorem.pollen.ui.utils; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; +import org.chorem.pollen.business.dto.PollAccountDTO; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author fdesbois + */ +public class CSVAccountUtilTest { + + public CSVAccountUtilTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of importList method, of class CSVAccountUtil. + */ + @Test + public void testImportList_Reader() { + System.out.println("importList"); + + InputStream input = getClass().getResourceAsStream("/import.csv"); + InputStreamReader reader = new InputStreamReader(input); + + List<PollAccountDTO> accounts = CSVAccountUtil.importList(reader); + + Assert.assertEquals(3, accounts.size()); + + PollAccountDTO account = accounts.get(0); + + Assert.assertEquals("toto", account.getVotingId()); + Assert.assertEquals("toto@titi.fr", account.getEmail()); + Assert.assertEquals(3., account.getWeight(), 0.1); + } + + /** + * Test of importList method, of class CSVAccountUtil. + */ + @Test + public void testImportList_UploadedFile() { + System.out.println("importList"); + } + +} \ No newline at end of file Property changes on: branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/resources/import.csv =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/resources/import.csv (rev 0) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/test/resources/import.csv 2010-03-05 09:55:30 UTC (rev 2896) @@ -0,0 +1,3 @@ +toto,"toto@titi.fr","3" +John Locke,john@locke.fr,1 +"Jack Pot","jackpot@bloum.fr","1" \ No newline at end of file Modified: branches/pollen-1.2.3-1.2.x/pollen-votecounting/pom.xml =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-votecounting/pom.xml 2010-03-05 09:29:40 UTC (rev 2895) +++ branches/pollen-1.2.3-1.2.x/pollen-votecounting/pom.xml 2010-03-05 09:55:30 UTC (rev 2896) @@ -10,7 +10,7 @@ <parent> <groupId>org.chorem</groupId> <artifactId>pollen</artifactId> - <version>1.2.3</version> + <version>1.2.4-SNAPSHOT</version> </parent> <groupId>org.chorem.pollen</groupId> Modified: branches/pollen-1.2.3-1.2.x/pom.xml =================================================================== --- branches/pollen-1.2.3-1.2.x/pom.xml 2010-03-05 09:29:40 UTC (rev 2895) +++ branches/pollen-1.2.3-1.2.x/pom.xml 2010-03-05 09:55:30 UTC (rev 2896) @@ -15,7 +15,7 @@ <groupId>org.chorem</groupId> <artifactId>pollen</artifactId> - <version>1.2.3</version> + <version>1.2.4-SNAPSHOT</version> <modules> <module>pollen-ui</module>
participants (1)
-
fdesbois@users.chorem.org