Author: echatellier Date: 2010-06-01 10:41:57 +0200 (Tue, 01 Jun 2010) New Revision: 69 Url: http://nuiton.org/repositories/revision/wikitty/69 Log: Add CSV import/export tests Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java Added: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java =================================================================== --- trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java (rev 0) +++ trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java 2010-06-01 08:41:57 UTC (rev 69) @@ -0,0 +1,110 @@ +/* *##% + * Copyright (C) 2010 Code Lutin, Chatellier Eric + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.nuiton.wikitty.importexport; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.util.StringUtil; + +/** + * Test for CSV import export class + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ImportExportCSVTest { + + /** + * Test que le pattern match les bonnes choses. + */ + @Test + public void testQueryPattern() { + + ImportExportCSV task = new ImportExportCSV(); + Pattern pattern = task.queryPattern; + + Matcher m = pattern.matcher("rtet"); + Assert.assertFalse(m.find()); + + m = pattern.matcher("Client=4e2e4a93-c412-46b8-beb9-e76e0f16740d"); + Assert.assertFalse(m.find()); + + m = pattern.matcher("Client=4e2e4a93-c412-46b8-beb9-e76e0f16740d"); + Assert.assertFalse(m.find()); + + m = pattern.matcher("Client.name=toto"); + Assert.assertTrue(m.find()); + Assert.assertEquals("Client.name", m.group(1)); + Assert.assertEquals("Client", m.group(2)); + Assert.assertEquals("name", m.group(3)); + Assert.assertEquals("toto", m.group(4)); + + m = pattern.matcher("Client.name=toto"); + Assert.assertTrue(m.find()); + Assert.assertEquals("toto", m.group(6)); + + m = pattern.matcher("Client.name=\"toto\""); + Assert.assertTrue(m.find()); + Assert.assertEquals("toto", m.group(5)); + + m = pattern.matcher("Client.name=\"toto"); + Assert.assertFalse(m.find()); + + m = pattern.matcher("Client.name=\"to\"to\""); + Assert.assertTrue(m.find()); + Assert.assertEquals("to\"to", m.group(5)); + + m = pattern.matcher("Client.name=toto\""); + Assert.assertFalse(m.find()); + } + + /** + * Test de parsing des valeurs multiples wikitty. + */ + @Test + public void testMultipleFieldsParsing() { + String test = "(sdfsdf),(dfsdf),(fdsfsdfg),(sdfsdfqs)"; + String[] result = StringUtil.split(test); + Assert.assertEquals(4, result.length); + Assert.assertEquals("(sdfsdf)", result[0]); + Assert.assertEquals("sdfsdf", result[0].substring(1, result[0].length() -1)); + Assert.assertEquals("(dfsdf)", result[1]); + Assert.assertEquals("(fdsfsdfg)", result[2]); + Assert.assertEquals("(sdfsdfqs)", result[3]); + + test = "(sdf\",\"sdf),(df()sdf),(fds\"(),()\"fsdfg),(sdfsdfqs)"; + result = StringUtil.split(test); + Assert.assertEquals(4, result.length); + Assert.assertEquals("(sdf\",\"sdf)", result[0]); + Assert.assertEquals("(df()sdf)", result[1]); + Assert.assertEquals("(fds\"(),()\"fsdfg)", result[2]); + Assert.assertEquals("(sdfsdfqs)", result[3]); + + test = "toto ?"; + result = StringUtil.split(test); + Assert.assertEquals(1, result.length); + Assert.assertEquals("toto ?", result[0]); + } +} Property changes on: trunk/wikitty-api/src/test/java/org/nuiton/wikitty/importexport/ImportExportCSVTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL