Author: chatellier Date: 2010-11-30 09:56:42 +0000 (Tue, 30 Nov 2010) New Revision: 306 Log: Refactor class name Validation > Control Added: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ControlServiceTest.java Removed: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java Copied: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ControlServiceTest.java (from rev 292, trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java) =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ControlServiceTest.java (rev 0) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ControlServiceTest.java 2010-11-30 09:56:42 UTC (rev 306) @@ -0,0 +1,134 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.services; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Test; + +import fr.ifremer.coser.CoserConstants.Category; +import fr.ifremer.coser.bean.Control; +import fr.ifremer.coser.control.ControlError; +import fr.ifremer.coser.data.Catch; +import fr.ifremer.coser.data.Haul; +import fr.ifremer.coser.data.Length; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.MemoryDataStorage; + +/** + * Test abour validation. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ControlServiceTest extends CoserTestAbstract { + + private static final Log log = LogFactory.getLog(ControlServiceTest.class); + + protected ControlService validationService = new ControlService(config); + + /** + * Test les validations sur les champs vide. + */ + @Test + public void testCatchValidation() { + + Catch myCatch = new Catch(); + + myCatch.setData(new String[]{"1", "","","","","",""}); + List<ControlError> errors = validationService.validate(myCatch, Category.CATCH); + Assert.assertNotNull(errors); + Assert.assertEquals(4, errors.size()); + + myCatch.setData(new String[]{"1", "Toto","","","","999",""}); + errors = validationService.validate(myCatch, Category.CATCH); + Assert.assertNotNull(errors); + Assert.assertEquals(3, errors.size()); + } + + /** + * Test la validation des valeurs NA pour les doubles. + */ + @Test + public void testDoubleValidation() { + Catch myCatch = new Catch(); + myCatch.setData(new String[]{"1", "Test survey","1999","Test trait","Test sp","NA","12"}); + List<ControlError> errors = validationService.validate(myCatch, Category.CATCH); + log.warn(errors); + Assert.assertTrue(errors.isEmpty()); + } + + /** + * Test la validation des valeurs NA pour les doubles. + */ + @Test + public void testLengthStep() { + Length myLength = new Length(); + // "Survey","Year","Haul","Species","Sex","Maturity","Length","Number","Weight","Age" + myLength.setData(new String[]{"1", "Test survey","1999","Test trait","Test sp","i","m","23.25", "3.00", "44.99", "12"}); + List<ControlError> errors = validationService.validate(myLength, Category.LENGTH); + log.warn(errors); + Assert.assertEquals(1, errors.size()); + } + + /** + * Test que certains double ont 5 decimales de définie. + */ + @Test + public void test5DecimalValidation() { + Haul haulBean = new Haul(); + haulBean.setData(new String[]{"1", "COSER_TEST","2010","TRAIT3","10","STR3","0.06","43.89","1.73","115.00"}); + List<ControlError> errors = validationService.validate(haulBean, Category.HAUL); + Assert.assertEquals(3, errors.size()); + + haulBean.setData(new String[]{"1","COSER_TEST","2010","TRAIT3","10","STR3","0.06000","43.89000","1.73234","115.00"}); + errors = validationService.validate(haulBean, Category.HAUL); + Assert.assertTrue(errors.isEmpty()); + } + + /** + * Test, si un poids est reseigné, la capture doit l'etre. + */ + @Test + public void testWeigthWithNonCapture() { + Control control = new Control(); + DataStorage dataCatch = new MemoryDataStorage(); + dataCatch.add(new String[]{"Line", "Campagne","Annee","Trait","Espece","Nombre","Poids"}); + dataCatch.add(new String[]{"1", "Test survey","1999","Test trait","Test sp","0","12"}); + control.setCatch(dataCatch); + List<ControlError> errors = validationService.validateCategory(control, Category.CATCH, null); + if (log.isDebugEnabled()) { + log.debug("Validation errors = " + errors); + } + Assert.assertEquals(2, errors.size()); + } +} Deleted: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java 2010-11-30 09:27:28 UTC (rev 305) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ValidationServiceTest.java 2010-11-30 09:56:42 UTC (rev 306) @@ -1,134 +0,0 @@ -/* - * #%L - * - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.services; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Test; - -import fr.ifremer.coser.CoserConstants.Category; -import fr.ifremer.coser.bean.Control; -import fr.ifremer.coser.control.ControlError; -import fr.ifremer.coser.data.Catch; -import fr.ifremer.coser.data.Haul; -import fr.ifremer.coser.data.Length; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.MemoryDataStorage; - -/** - * Test abour validation. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class ValidationServiceTest extends CoserTestAbstract { - - private static final Log log = LogFactory.getLog(ValidationServiceTest.class); - - protected ControlService validationService = new ControlService(config); - - /** - * Test les validations sur les champs vide. - */ - @Test - public void testCatchValidation() { - - Catch myCatch = new Catch(); - - myCatch.setData(new String[]{"1", "","","","","",""}); - List<ControlError> errors = validationService.validate(myCatch, Category.CATCH); - Assert.assertNotNull(errors); - Assert.assertEquals(4, errors.size()); - - myCatch.setData(new String[]{"1", "Toto","","","","999",""}); - errors = validationService.validate(myCatch, Category.CATCH); - Assert.assertNotNull(errors); - Assert.assertEquals(3, errors.size()); - } - - /** - * Test la validation des valeurs NA pour les doubles. - */ - @Test - public void testDoubleValidation() { - Catch myCatch = new Catch(); - myCatch.setData(new String[]{"1", "Test survey","1999","Test trait","Test sp","NA","12"}); - List<ControlError> errors = validationService.validate(myCatch, Category.CATCH); - log.warn(errors); - Assert.assertTrue(errors.isEmpty()); - } - - /** - * Test la validation des valeurs NA pour les doubles. - */ - @Test - public void testLengthStep() { - Length myLength = new Length(); - // "Survey","Year","Haul","Species","Sex","Maturity","Length","Number","Weight","Age" - myLength.setData(new String[]{"1", "Test survey","1999","Test trait","Test sp","i","m","23.25", "3.00", "44.99", "12"}); - List<ControlError> errors = validationService.validate(myLength, Category.LENGTH); - log.warn(errors); - Assert.assertEquals(1, errors.size()); - } - - /** - * Test que certains double ont 5 decimales de définie. - */ - @Test - public void test5DecimalValidation() { - Haul haulBean = new Haul(); - haulBean.setData(new String[]{"1", "COSER_TEST","2010","TRAIT3","10","STR3","0.06","43.89","1.73","115.00"}); - List<ControlError> errors = validationService.validate(haulBean, Category.HAUL); - Assert.assertEquals(3, errors.size()); - - haulBean.setData(new String[]{"1","COSER_TEST","2010","TRAIT3","10","STR3","0.06000","43.89000","1.73234","115.00"}); - errors = validationService.validate(haulBean, Category.HAUL); - Assert.assertTrue(errors.isEmpty()); - } - - /** - * Test, si un poids est reseigné, la capture doit l'etre. - */ - @Test - public void testWeigthWithNonCapture() { - Control control = new Control(); - DataStorage dataCatch = new MemoryDataStorage(); - dataCatch.add(new String[]{"Line", "Campagne","Annee","Trait","Espece","Nombre","Poids"}); - dataCatch.add(new String[]{"1", "Test survey","1999","Test trait","Test sp","0","12"}); - control.setCatch(dataCatch); - List<ControlError> errors = validationService.validateCategory(control, Category.CATCH, null); - if (log.isDebugEnabled()) { - log.debug("Validation errors = " + errors); - } - Assert.assertEquals(2, errors.size()); - } -}