r2182 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/xwork2/field test/java/org/nuiton/validator test/java/org/nuiton/validator/model test/java/org/nuiton/validator/xwork2/field test/resources test/resources/org/nuiton/validator/model
Author: tchemit Date: 2011-08-24 15:13:11 +0200 (Wed, 24 Aug 2011) New Revision: 2182 Url: http://nuiton.org/repositories/revision/nuiton-utils/2182 Log: reformat code add svn properties Evolution #1707: Introduce a NuitonFieldValidatorSupport Normalize validators and rename some... Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java Removed: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml trunk/nuiton-validator/src/test/resources/validators.xml Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,70 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Validator for French cities names : - * - No number accepted - * - Accept spaces, - and ' - */ -public class CityNameFieldValidator extends FieldValidatorSupport { - - protected static String CITY_NAME_REGEXP = "[^\\d]+"; - protected static Pattern p = Pattern.compile(CITY_NAME_REGEXP); - - //TODO JC18082011 - Deal with cedex - - @Override - public void validate(Object object) throws ValidationException { - - String fieldName = getFieldName(); - Object value = getFieldValue(fieldName, object); - - if (value == null) { - // no value defined - return; - } - if (value instanceof String) { - Matcher m = p.matcher((String) value); - if (!m.matches()) { - addFieldError(fieldName, object); - return; - } - } else { - addFieldError(fieldName, object); - return; - } - } - - @Override - public String getValidatorType() { - return "cityName"; - } -} Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionFieldExpressionValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -40,7 +40,7 @@ * * @author tchemit <chemit@codelutin.com> */ -public class CollectionFieldExpressionValidator extends FieldExpressionValidator { +public class CollectionFieldExpressionValidator extends NuitonFieldExpressionValidator { public enum Mode { @@ -160,7 +160,7 @@ } @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { if (mode == null) { throw new ValidationException("no mode defined!"); } Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -42,7 +42,7 @@ * * @author tchemit <chemit@codelutin.com> */ -public class CollectionUniqueKeyValidator extends FieldExpressionValidator { +public class CollectionUniqueKeyValidator extends NuitonFieldValidatorSupport { /** * pour indiquer la propriété qui contient la liste à valider. @@ -145,7 +145,7 @@ } @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { if (keys == null || keys.length == 0) { throw new ValidationException("no unique keys defined"); Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,17 +25,19 @@ package org.nuiton.validator.xwork2.field; import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import org.nuiton.util.StringUtil; /** * Validator for email addresses : * - Deal with + in addresses + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 */ -public class EmailFieldValidator extends FieldValidatorSupport { +public class EmailFieldValidator extends NuitonFieldValidatorSupport { @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = getFieldValue(fieldName, object); @@ -45,18 +47,16 @@ return; } if (value instanceof String) { - if (!StringUtil.isEmail((String)value)) { + if (!StringUtil.isEmail((String) value)) { addFieldError(fieldName, object); - return; } } else { addFieldError(fieldName, object); - return; } } @Override public String getValidatorType() { - return "email"; + return "emailNuiton"; } } Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingDirectoryFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,6 @@ package org.nuiton.validator.xwork2.field; import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import java.io.File; @@ -50,7 +49,7 @@ * <param name="fieldName">tmp</param> * <message>tmp is not an existing directory</message> * </validator> - * <p/> + * * <!-- Field-Validator Syntax --> * <field name="tmp"> * <field-validator type="existingDirectory"> @@ -63,10 +62,10 @@ * * @author tchemit <chemit@codelutin.com> */ -public class ExistingDirectoryFieldValidator extends FieldValidatorSupport { +public class ExistingDirectoryFieldValidator extends NuitonFieldValidatorSupport { @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = getFieldValue(fieldName, object); if (value == null) { Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/ExistingFileFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,6 @@ package org.nuiton.validator.xwork2.field; import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import java.io.File; @@ -50,7 +49,7 @@ * <param name="fieldName">tmp</param> * <message>tmp is not an existing file</message> * </validator> - * <p/> + * * <!-- Field-Validator Syntax --> * <field name="tmp"> * <field-validator type="fileExisting"> @@ -63,10 +62,10 @@ * * @author tchemit <chemit@codelutin.com> */ -public class ExistingFileFieldValidator extends FieldValidatorSupport { +public class ExistingFileFieldValidator extends NuitonFieldValidatorSupport { @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = getFieldValue(fieldName, object); if (value == null) { Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FieldExpressionWithParamsValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -42,7 +42,7 @@ * @author tchemit <chemit@codelutin.com> * @since 1.3 */ -public class FieldExpressionWithParamsValidator extends FieldExpressionValidator { +public class FieldExpressionWithParamsValidator extends NuitonFieldExpressionValidator { protected static final Pattern EXTRA_BOOLEAN_PARAM_ENTRY_PATTERN = Pattern.compile("(\\w+)\\:(false|true)"); @@ -167,7 +167,12 @@ @Override public void validate(Object object) throws ValidationException { + super.validate(object); + } + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + booleans = initParams(Boolean.class, booleanParams, EXTRA_BOOLEAN_PARAM_ENTRY_PATTERN); shorts = initParams(Short.class, shortParams, EXTRA_SHORT_PARAM_ENTRY_PATTERN); ints = initParams(Integer.class, intParams, EXTRA_INT_PARAM_ENTRY_PATTERN); @@ -182,7 +187,7 @@ } try { - super.validate(object); + super.validateWhenNotSkip(object); } finally { if (pop) { stack.pop(); Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java) =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,72 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Validator for French cities names : + * - No number accepted + * - Accept spaces, - and ' + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class FrenchCityNameFieldValidator extends NuitonFieldValidatorSupport { + + protected static String CITY_NAME_REGEXP = "[^\\d]+"; + + protected static Pattern p = Pattern.compile(CITY_NAME_REGEXP); + + //TODO JC18082011 - Deal with cedex + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + String fieldName = getFieldName(); + Object value = getFieldValue(fieldName, object); + + if (value == null) { + // no value defined + return; + } + if (value instanceof String) { + Matcher m = p.matcher((String) value); + if (!m.matches()) { + addFieldError(fieldName, object); + } + } else { + addFieldError(fieldName, object); + } + } + + @Override + public String getValidatorType() { + return "frenchCityName"; + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java) =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,70 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Validator for French last names : + * - No number accepted + * - Accept spaces, - and ' + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class FrenchLastNameFieldValidator extends NuitonFieldValidatorSupport { + + protected static String LAST_NAME_REGEXP = "[^\\d]+"; + + protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP); + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + String fieldName = getFieldName(); + Object value = getFieldValue(fieldName, object); + + if (value == null) { + // no value defined + return; + } + if (value instanceof String) { + Matcher m = p.matcher((String) value); + if (!m.matches()) { + addFieldError(fieldName, object); + } + } else { + addFieldError(fieldName, object); + } + } + + @Override + public String getValidatorType() { + return "frenchLastName"; + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java) =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,73 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Validator used to validate French phone numbers like : + * - 0000000000 + * - 00.00.00.00.00 + * - 00-00-00-00-00 + * - 00 00 00 00 00 + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class FrenchPhoneNumberFieldValidator extends NuitonFieldValidatorSupport { + + protected static String PHONE_NUMBER_REGEXP = + "[0-9]{10}|(([0-9]{2}[-\\.\\s]){4})[0-9]{2}"; + + protected static Pattern p = Pattern.compile(PHONE_NUMBER_REGEXP); + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + String fieldName = getFieldName(); + Object value = getFieldValue(fieldName, object); + + if (value == null) { + // no value defined + return; + } + if (value instanceof String) { + Matcher m = p.matcher((String) value); + if (!m.matches()) { + addFieldError(fieldName, object); + } + } else { + addFieldError(fieldName, object); + } + } + + @Override + public String getValidatorType() { + return "frenchPhoneNumber"; + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java) =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,73 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Validate post codes for French cities + * <p/> + * - Take into account 2A and 2B + * - Take into account DOMs and TOMs + * - Postcodes starting with 99 are not valid + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class FrenchPostCodeFieldValidator extends NuitonFieldValidatorSupport { + + protected static String POST_CODE_REGEXP = + "^((0[1-9])|([1-8][0-9])|(9[0-8])|(2A)|(2B))[0-9]{3}$"; + + protected static Pattern p = Pattern.compile(POST_CODE_REGEXP); + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + String fieldName = getFieldName(); + Object value = getFieldValue(fieldName, object); + + if (value == null) { + // no value defined + return; + } + if (value instanceof String) { + Matcher m = p.matcher((String) value); + if (!m.matches()) { + addFieldError(fieldName, object); + } + } else { + addFieldError(fieldName, object); + } + } + + @Override + public String getValidatorType() { + return "frenchPostCode"; + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java) =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,168 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; + +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Validator for French SIRET numbers + * <p/> + * Siret can be in: + * <li>String format: "44211670300038" + * <li>long, int: 44211670300038 + * <li>Array or Collection of something: [4,4,2,1,1,6,7,0,,3,0,0,0,3,8] or ["442","116","703", "0003", "8"] + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + * Validation do the Luhn checksum too + */ +public class FrenchSiretFieldValidator extends NuitonFieldValidatorSupport { + + protected static final String SIRET_REGEXP = "[0-9]{14}"; + + protected static final Pattern p = Pattern.compile(SIRET_REGEXP); + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + String fieldName = getFieldName(); + Object value = getFieldValue(fieldName, object); + + if (value == null) { + // no value defined + return; + } + String siret; + + if (value.getClass().isArray()) { + // le siret est stocker dans un tableau, par exemple un byte[] + siret = ""; + for (int i = 0; i < Array.getLength(value); i++) { + siret += String.valueOf(Array.get(value, i)); + } + } else if (value instanceof Collection<?>) { + // le siret est stocker dans une collection, + // ca doit pas arriver souvent :D, mais autant le gerer + siret = ""; + for (Object o : (Collection<?>) value) { + siret += String.valueOf(o); + } + } else { + // sinon dans tous les autres cas (String, int, long, BigInteger ...) + // on prend le toString + siret = String.valueOf(value); + } + + Matcher m = p.matcher(siret); + if (!m.matches() || !luhnChecksum(siret)) { + addFieldError(fieldName, object); + } + } + + @Override + public String getValidatorType() { + return "frenchSiret"; + } + + /** + * Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit + * dans <a href="http://fr.wikipedia.org/wiki/Luhn">wikipedia</a> + * <p/> + * Algo: + * en fonction de la position du numero dans la sequence, + * on multiplie pas 1 (pour les impaires) ou par 2 pour les paires + * (1 etant le numero le plus a droite) + * On fait la somme de tous les chiffres qui resulte de ces multiplications + * (si un resultat etait 14, on ne fait pas +14 mais +1+4) + * <p/> + * Si le résultat de cette somme donne un reste de 0 une fois divisé par 10 + * le numero est valide. + * + * @param siret une chaine composer que de chiffre + * @return vrai si on a reussi a valider le numero + */ + public static boolean luhnChecksum(String siret) { + + char[] tab = siret.toCharArray(); + int sum = 0; + for (int i = tab.length - 1; i >= 0; i--) { + // recuperation de la valeur + int n = getDigit(tab[i]); + + // 1ere phase il faut faire la multiplication par 1 ou 2 + + // il faut faire x1 pour les paires et x2 sur les impaires. + // en prenant en compte que le numero siret le plus a droite est le + // 1 et le plus a gauche le 14. + // mais comme en informatique on commence a 0 :D + // il faut faire +1 sur l'indice puis un simple module 2 + 1 + // nous convient + n *= (i + 1) % 2 + 1; + + // 2eme phase il faut faire l'addition + + // si une fois multiplie il est superieur a 9, il faut additionner + // toutes ces constituante, mais comme il ne peut pas etre superieur + // a 18, cela revient a retrancher 9 + if (n > 9) { + n -= 9; + } + + // on peut directement faire la somme + sum += n; + } + + // 3eme phase on verifie que c'est bien un multiple de 10 + boolean result = sum % 10 == 0; + + return result; + } + + + /** + * Converti un char en un entier '0' => 0 et '9' => 9, et 'A' => 10 a 'Z' => 36, + * les autres caractere sont aussi convertis pour que 'a' = 10 et 'z' = 36. + * Pour les autres c'est un indedermine + * + * @param c le caractere qui doit etre converti + * @return le chiffre + */ + public static int getDigit(char c) { + int result = 0; + if (c >= '0' && c <= '9') { + result = c - '0'; + } else if (c >= 'A' && c <= 'Z') { + result = c - 'A' + 10; + } else { + result = c - 'a' + 10; + } + return result; + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,68 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Validator for French last names : - * - No number accepted - * - Accept spaces, - and ' - */ -public class LastNameFieldValidator extends FieldValidatorSupport { - - protected static String LAST_NAME_REGEXP = "[^\\d]+"; - protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP); - - @Override - public void validate(Object object) throws ValidationException { - - String fieldName = getFieldName(); - Object value = getFieldValue(fieldName, object); - - if (value == null) { - // no value defined - return; - } - if (value instanceof String) { - Matcher m = p.matcher((String) value); - if (!m.matches()) { - addFieldError(fieldName, object); - return; - } - } else { - addFieldError(fieldName, object); - return; - } - } - - @Override - public String getValidatorType() { - return "lastName"; - } -} Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingDirectoryFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,6 @@ package org.nuiton.validator.xwork2.field; import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import java.io.File; @@ -50,7 +49,7 @@ * <param name="fieldName">tmp</param> * <message>tmp is an existing directory</message> * </validator> - * <p/> + * * <!-- Field-Validator Syntax --> * <field name="tmp"> * <field-validator type="notExistingDirectory"> @@ -63,10 +62,10 @@ * * @author tchemit <chemit@codelutin.com> */ -public class NotExistingDirectoryFieldValidator extends FieldValidatorSupport { +public class NotExistingDirectoryFieldValidator extends NuitonFieldValidatorSupport { @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = getFieldValue(fieldName, object); if (value == null) { Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NotExistingFileFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,6 @@ package org.nuiton.validator.xwork2.field; import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import java.io.File; @@ -50,7 +49,7 @@ * <param name="fieldName">tmp</param> * <message>tmp is an existing file</message> * </validator> - * <p/> + * * <!-- Field-Validator Syntax --> * <field name="tmp"> * <field-validator type="notExistingFile"> @@ -63,10 +62,10 @@ * * @author tchemit <chemit@codelutin.com> */ -public class NotExistingFileFieldValidator extends FieldValidatorSupport { +public class NotExistingFileFieldValidator extends NuitonFieldValidatorSupport { @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = getFieldValue(fieldName, object); if (value == null) { Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,137 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; +import com.opensymphony.xwork2.validator.validators.FieldExpressionValidator; + +/** + * Nuiton default field validator. + * <p/> + * This validator offers a {@link #skip} property that can be used to skip or + * not the validator, this property is a OGNL expression. + * <p/> + * To use this new field validator support, just now implements the method + * {@link #validateWhenNotSkip(Object)}. This method will be invoked only if the skip + * parameter is evaluated to {@code false}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.3 + */ +public abstract class NuitonFieldExpressionValidator extends FieldExpressionValidator { + + /** + * extra parameter at the very beginning of the + * {@link #validate(Object)} method to be able to skip (or not) the + * validator execution. + * <p/> + * by default the value is {@code false} : it seems fair to want to + * validate if the validator is used :D... + */ + protected String skip = "false"; + + /** + * Sets the value of the {@link #skip} parameter. + * + * @param skip the new value of the {@link #skip} parameter + */ + public void setSkip(String skip) { + this.skip = skip; + } + + /** + * Method to be invoked when skip parameter was not evaludated to {@code true}. + * + * @param object the object to be validated. + * @throws ValidationException is thrown if there is validation error(s). + */ + + protected void validateWhenNotSkip(Object object) throws ValidationException { + super.validate(object); + } + + @Override + public void validate(Object object) throws ValidationException { + + // evaluate the skip parameter + boolean mustSkip = evaluateSkipParameter(object); + + if (mustSkip) { + + // skip is set to true, so skip the validation + if (log.isDebugEnabled()) { + log.debug("Skip the validation from " + this + + ", due to skip parameter evaluated to true"); + } + return; + } + + // must validate + validateWhenNotSkip(object); + } + + /** + * Evaluate the skip parameter value against the object to validate. + * <p/> + * This parameter can be an OGNL expression. + * + * @param object the object to validate + * @return the evaluation of the skip parameter. + * @throws ValidationException if could not evaluate the parameter + */ + protected boolean evaluateSkipParameter(Object object) throws ValidationException { + + skip = skip.trim(); + + if ("false".equals(skip)) { + + return false; + } + + if ("true".equals(skip)) { + + return true; + } + + try { + Boolean answer = Boolean.FALSE; + Object obj; + obj = getFieldValue(skip, object); + if (obj != null && obj instanceof Boolean) { + answer = (Boolean) obj; + } + return answer; + } catch (ValidationException e) { + throw e; + } catch (Exception e) { + // let this pass, but it will be logged right below + throw new ValidationException( + "Can not evaluate boolean expression [" + skip + + "] for reason " + e.getMessage()); + } + + } + +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,140 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; +import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; + +/** + * Nuiton default field validator. + * <p/> + * This validator offers a {@link #skip} property that can be used to skip or + * not the validator, this property is a OGNL expression. + * <p/> + * To use this new field validator support, just now implements the method + * {@link #validateWhenNotSkip(Object)}. This method will be invoked only if the skip + * parameter is evaluated to {@code false}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.3 + */ +public abstract class NuitonFieldValidatorSupport extends FieldValidatorSupport { + + /** + * extra parameter at the very beginning of the + * {@link #validate(Object)} method to be able to skip (or not) the + * validator execution. + * <p/> + * by default the value is {@code false} : it seems fair to want to + * validate if the validator is used :D... + */ + protected String skip = "false"; + + /** + * Sets the value of the {@link #skip} parameter. + * + * @param skip the new value of the {@link #skip} parameter + */ + public void setSkip(String skip) { + this.skip = skip; + } + + /** + * Method to be invoked when skip parameter was not evaludated to {@code true}. + * + * @param object the object to be validated. + * @throws ValidationException is thrown if there is validation error(s). + */ + + protected abstract void validateWhenNotSkip(Object object) throws ValidationException; + + @Override + public void validate(Object object) throws ValidationException { + + // evaluate the skip parameter + boolean mustSkip = evaluateSkipParameter(object); + + if (mustSkip) { + + // skip is set to true, so skip the validation + if (log.isDebugEnabled()) { + log.debug("Skip the validation from " + this + + ", due to skip parameter evaluated to true"); + } + return; + } + + // must validate + validateWhenNotSkip(object); + } + + /** + * Evaluate the skip parameter value against the object to validate. + * <p/> + * This parameter can be an OGNL expression. + * + * @param object the object to validate + * @return the evaluation of the skip parameter. + * @throws ValidationException if could not evaluate the parameter + */ + protected boolean evaluateSkipParameter(Object object) throws ValidationException { + + skip = skip.trim(); + + if ("false".equals(skip)) { + + return false; + } + + if ("true".equals(skip)) { + + return true; + } + + try { + Boolean answer = Boolean.FALSE; + Object obj; + obj = getFieldValue(skip, object); + if (obj != null && obj instanceof Boolean) { + answer = (Boolean) obj; + } + return answer; + } catch (ValidationException e) { + throw e; + } catch (Exception e) { + // let this pass, but it will be logged right below + throw new ValidationException( + "Can not evaluate boolean expression [" + skip + + "] for reason " + e.getMessage()); + } + + } + + @Override + public Object getFieldValue(String name, + Object object) throws ValidationException { + return super.getFieldValue(name, object); + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldValidatorSupport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,71 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * - * Validator used to validate French phone numbers like : - * - 0000000000 - * - 00.00.00.00.00 - * - 00-00-00-00-00 - * - 00 00 00 00 00 - */ -public class PhoneNumberFieldValidator extends FieldValidatorSupport { - - protected static String PHONE_NUMBER_REGEXP = "[0-9]{10}|(([0-9]{2}[-\\.\\s]){4})[0-9]{2}"; - protected static Pattern p = Pattern.compile(PHONE_NUMBER_REGEXP); - - @Override - public void validate(Object object) throws ValidationException { - - String fieldName = getFieldName(); - Object value = getFieldValue(fieldName, object); - - if (value == null) { - // no value defined - return; - } - if (value instanceof String) { - Matcher m = p.matcher((String)value); - if (!m.matches()){ - addFieldError(fieldName, object); - return; - } - } else { - addFieldError(fieldName, object); - return; - } - } - - @Override - public String getValidatorType() { - return "phoneNumber"; - } -} Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,70 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Validate post codes for French cities - * - * - Take into account 2A and 2B - * - Take into account DOMs and TOMs - * - Postcodes starting with 99 are not valid - */ -public class PostCodeFieldValidator extends FieldValidatorSupport { - - protected static String POST_CODE_REGEXP = "^((0[1-9])|([1-8][0-9])|(9[0-8])|(2A)|(2B))[0-9]{3}$"; - protected static Pattern p = Pattern.compile(POST_CODE_REGEXP); - - @Override - public void validate(Object object) throws ValidationException { - - String fieldName = getFieldName(); - Object value = getFieldValue(fieldName, object); - - if (value == null) { - // no value defined - return; - } - if (value instanceof String) { - Matcher m = p.matcher((String) value); - if (!m.matches()) { - addFieldError(fieldName, object); - return; - } - } else { - addFieldError(fieldName, object); - return; - } - } - - @Override - public String getValidatorType() { - return "postCode"; - } -} Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/RequiredFileFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,6 @@ package org.nuiton.validator.xwork2.field; import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; import java.io.File; @@ -50,7 +49,7 @@ * <param name="fieldName">tmp</param> * <message>tmp is required</message> * </validator> - * <p/> + * * <!-- Field-Validator Syntax --> * <field name="tmp"> * <field-validator type="requiredFile"> @@ -63,10 +62,10 @@ * * @author tchemit <chemit@codelutin.com> */ -public class RequiredFileFieldValidator extends FieldValidatorSupport { +public class RequiredFileFieldValidator extends NuitonFieldValidatorSupport { @Override - public void validate(Object object) throws ValidationException { + public void validateWhenNotSkip(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = getFieldValue(fieldName, object); if (value == null) { Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,165 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Validator for French SIRET numbers - * - * Siret can be in: - * <li>String format: "44211670300038" - * <li>long, int: 44211670300038 - * <li>Array or Collection of something: [4,4,2,1,1,6,7,0,,3,0,0,0,3,8] or ["442","116","703", "0003", "8"] - * - * Validation do the Luhn checksum too - */ -public class SiretFieldValidator extends FieldValidatorSupport { - - protected static final String SIRET_REGEXP = "[0-9]{14}"; - protected static final Pattern p = Pattern.compile(SIRET_REGEXP); - - @Override - public void validate(Object object) throws ValidationException { - - String fieldName = getFieldName(); - Object value = getFieldValue(fieldName, object); - - if (value == null) { - // no value defined - return; - } - String siret; - - if (value.getClass().isArray()) { - // le siret est stocker dans un tableau, par exemple un byte[] - siret = ""; - for (int i=0; i<Array.getLength(value); i++) { - siret += String.valueOf(Array.get(value, i)); - } - } else if (value instanceof Collection) { - // le siret est stocker dans une collection, - // ca doit pas arriver souvent :D, mais autant le gerer - siret = ""; - for (Object o : (Collection)value) { - siret += String.valueOf(o); - } - } else { - // sinon dans tous les autres cas (String, int, long, BigInteger ...) - // on prend le toString - siret = String.valueOf(value); - } - - Matcher m = p.matcher(siret); - if (!m.matches() || !luhnChecksum(siret)) { - addFieldError(fieldName, object); - } - } - - @Override - public String getValidatorType() { - return "siret"; - } - - /** - * Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit - * dans <a href="http://fr.wikipedia.org/wiki/Luhn">wikipedia</a> - * - * Algo: - * en fonction de la position du numero dans la sequence, - * on multiplie pas 1 (pour les impaires) ou par 2 pour les paires - * (1 etant le numero le plus a droite) - * On fait la somme de tous les chiffres qui resulte de ces multiplications - * (si un resultat etait 14, on ne fait pas +14 mais +1+4) - * - * Si le résultat de cette somme donne un reste de 0 une fois divisé par 10 - * le numero est valide. - * - * @param siret une chaine composer que de chiffre - * @return vrai si on a reussi a valider le numero - */ - static public boolean luhnChecksum(String siret) { - - char[] tab = siret.toCharArray(); - int sum = 0; - for (int i=tab.length-1; i>=0; i--) { - // recuperation de la valeur - int n = getDigit(tab[i]); - - // 1ere phase il faut faire la multiplication par 1 ou 2 - - // il faut faire x1 pour les paires et x2 sur les impaires. - // en prenant en compte que le numero siret le plus a droite est le - // 1 et le plus a gauche le 14. - // mais comme en informatique on commence a 0 :D - // il faut faire +1 sur l'indice puis un simple module 2 + 1 - // nous convient - n *= (i+1)%2+1; - - // 2eme phase il faut faire l'addition - - // si une fois multiplie il est superieur a 9, il faut additionner - // toutes ces constituante, mais comme il ne peut pas etre superieur - // a 18, cela revient a retrancher 9 - if (n > 9) { - n -= 9; - } - - // on peut directement faire la somme - sum += n; - } - - // 3eme phase on verifie que c'est bien un multiple de 10 - boolean result = (sum % 10 == 0); - - return result; - } - - - /** - * Converti un char en un entier '0' => 0 et '9' => 9, et 'A' => 10 a 'Z' => 36, - * les autres caractere sont aussi convertis pour que 'a' = 10 et 'z' = 36. - * Pour les autres c'est un indedermine - * - * @param c le caractere qui doit etre converti - * @return le chiffre - */ - static public int getDigit(char c) { - int result = 0; - if (c >= '0' && c <= '9') { - result = c - '0'; - } else if (c >= 'A' && c <= 'Z'){ - result = c - 'A' + 10; - } else { - result = c - 'a' + 10; - } - return result; - } -} Copied: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java (from rev 2180, trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java) =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java (rev 0) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,68 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import com.opensymphony.xwork2.validator.ValidationException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Validator for EU VAT number. + * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class VATIdentificationNumberFieldValidator extends NuitonFieldValidatorSupport { + + protected static String VAT_INTRA_REGEXP = "^(RO\\d{2,10}|GB\\d{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)\\d{8}|IE[A-Z\\d]{8}|(DE|BG|EE|EL|LT|BE0|PT|CZ)\\d{9}|CY\\d{8}[A-Z]|(ES|GB)[A-Z\\d]{9}|(BE0|PL|SK|CZ)\\d{10}|(FR|IT|LV)\\d{11}|(LT|SE)\\d{12}|(NL|GB)[A-Z\\d]{12})$"; + + protected static Pattern p = Pattern.compile(VAT_INTRA_REGEXP); + + @Override + public void validateWhenNotSkip(Object object) throws ValidationException { + + String fieldName = getFieldName(); + Object value = getFieldValue(fieldName, object); + + if (value == null) { + // no value defined + return; + } + if (value instanceof String) { + Matcher m = p.matcher((String) value); + if (!m.matches()) { + addFieldError(fieldName, object); + } + } else { + addFieldError(fieldName, object); + } + } + + @Override + public String getValidatorType() { + return "VATIdentificationNumber"; + } +} Property changes on: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java =================================================================== --- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,66 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import com.opensymphony.xwork2.validator.ValidationException; -import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Validator for EU VAT number - */ -public class VATIntraFieldValidator extends FieldValidatorSupport { - - protected static String VAT_INTRA_REGEXP = "^(RO\\d{2,10}|GB\\d{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)\\d{8}|IE[A-Z\\d]{8}|(DE|BG|EE|EL|LT|BE0|PT|CZ)\\d{9}|CY\\d{8}[A-Z]|(ES|GB)[A-Z\\d]{9}|(BE0|PL|SK|CZ)\\d{10}|(FR|IT|LV)\\d{11}|(LT|SE)\\d{12}|(NL|GB)[A-Z\\d]{12})$"; - protected static Pattern p = Pattern.compile(VAT_INTRA_REGEXP); - - @Override - public void validate(Object object) throws ValidationException { - - String fieldName = getFieldName(); - Object value = getFieldValue(fieldName, object); - - if (value == null) { - // no value defined - return; - } - if (value instanceof String) { - Matcher m = p.matcher((String) value); - if (!m.matches()) { - addFieldError(fieldName, object); - return; - } - } else { - addFieldError(fieldName, object); - return; - } - } - - @Override - public String getValidatorType() { - return "VATIntra"; - } -} Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/AbstractValidatorDetectorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -98,15 +98,15 @@ } public void assertValidatorEffectiveFields(NuitonValidator<?> validator, - String... expectedFields) { + String... expectedFields) { ValidatorTestHelper.assertValidatorEffectiveFields(validator, expectedFields); } public void assertValidatorEffectiveFields(NuitonValidator<?> validator, - NuitonValidatorScope scope, - String... expectedFields) { + NuitonValidatorScope scope, + String... expectedFields) { ValidatorTestHelper.assertValidatorEffectiveFields(validator, scope, expectedFields); Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,8 @@ package org.nuiton.validator.model; /** - * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 */ public class Company { Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -25,7 +25,8 @@ package org.nuiton.validator.model; /** - * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 */ public class Contact { Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,96 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import org.junit.Test; -import org.nuiton.validator.model.Contact; - -/** - * - */ -public class CityNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { - - public CityNameFieldValidatorTest() { - super(Contact.class); - } - - @Test - @Override - public void testValidator() throws Exception { - - assertNull(bean.getCity()); - - // Valid city - bean.setCity("Nantes"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Valid city - bean.setCity("Couëron"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Valid city - bean.setCity("Saint Sébastien Sur Loire"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Valid city - bean.setCity("St Sebastien sur Loire"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Valid city - bean.setCity("St-Sebastien-sur-Loire"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Valid city - bean.setCity("Y"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Valid city - bean.setCity("Saint-Remy-en-Bouzemont-Saint-Genest-et-Isson"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - false); - - // Not Valid city name - bean.setCity("2Ville"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - true); - - // Not Valid city name - bean.setCity("Ville2Merde"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - true); - - // Not Valid city name - bean.setCity("Ville 2 Merde"); - assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", - true); - - } -} Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CollectionUniqueKeyValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -24,8 +24,8 @@ */ package org.nuiton.validator.xwork2.field; +import org.junit.Test; import org.nuiton.validator.xwork2.field.ValidatorBean.ValidatorBeanEntry; -import org.junit.Test; import java.util.Arrays; Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -28,7 +28,8 @@ import org.nuiton.validator.model.Contact; /** - * + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 */ public class EmailFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java) =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java (rev 0) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,97 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import org.junit.Test; +import org.nuiton.validator.model.Contact; + +/** + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class FrenchCityNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { + + public FrenchCityNameFieldValidatorTest() { + super(Contact.class); + } + + @Test + @Override + public void testValidator() throws Exception { + + assertNull(bean.getCity()); + + // Valid city + bean.setCity("Nantes"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Valid city + bean.setCity("Couëron"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Valid city + bean.setCity("Saint Sébastien Sur Loire"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Valid city + bean.setCity("St Sebastien sur Loire"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Valid city + bean.setCity("St-Sebastien-sur-Loire"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Valid city + bean.setCity("Y"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Valid city + bean.setCity("Saint-Remy-en-Bouzemont-Saint-Genest-et-Isson"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + false); + + // Not Valid city name + bean.setCity("2Ville"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + true); + + // Not Valid city name + bean.setCity("Ville2Merde"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + true); + + // Not Valid city name + bean.setCity("Ville 2 Merde"); + assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format", + true); + + } +} Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchCityNameFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java) =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java (rev 0) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,79 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import org.junit.Test; +import org.nuiton.validator.model.Contact; + +/** + * @author jcouteau <couteau@codelutin.com> + * Date: 18/08/11 + * @since 2.3 + */ +public class FrenchLastNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { + + public FrenchLastNameFieldValidatorTest() { + super(Contact.class); + } + + @Test + @Override + public void testValidator() throws Exception { + + assertNull(bean.getCity()); + + // Valid name + bean.setName("Couteau"); + assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", + false); + + // Valid name + bean.setName("Le Ny"); + assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", + false); + + // Valid name + bean.setName("Clémenceau"); + assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", + false); + + // Valid name + bean.setName("Couteau--Viney"); + assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", + false); + + // Not valid name + bean.setName("2Pac"); + assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", + true); + + // Not valid name + bean.setName("Nom2Merde"); + assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", + true); + + + } +} Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchLastNameFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java) =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java (rev 0) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,128 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import org.junit.Test; +import org.nuiton.validator.model.Contact; + +/** + * @author jcouteau <couteau@codelutin.com> + * Date: 18/08/11 + * @since 2.3 + */ +public class FrenchPhoneNumberFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { + + public FrenchPhoneNumberFieldValidatorTest() { + super(Contact.class); + } + + @Test + @Override + public void testValidator() throws Exception { + + assertNull(bean.getPhone()); + + // Valid phone Number + bean.setPhone("0000000000"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + false); + + // Valid phone Number + bean.setPhone("00 00 00 00 00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + false); + + // Valid phone Number + bean.setPhone("00-00-00-00-00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + false); + + // Valid phone Number + bean.setPhone("00.00.00.00.00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + false); + + // Too long phone Number + bean.setPhone("00 00 00 00 00 00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too long phone Number + bean.setPhone("00-00-00-00-00-00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too long phone Number + bean.setPhone("000000000000"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too long phone Number + bean.setPhone("00.00.00.00.00.00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too short phone Number + bean.setPhone("00.00.00.00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too short phone Number + bean.setPhone("00000000"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too short phone Number + bean.setPhone("00-00-00-00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Too short phone Number + bean.setPhone("00 00 00 00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Invalid character in phone Number + bean.setPhone("00 00 ab 00 00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Invalid character in phone Number + bean.setPhone("0000ab0000"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Invalid character in phone Number + bean.setPhone("00.00.ab.00.00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + // Invalid character in phone Number + bean.setPhone("00-00-ab-00-00"); + assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", + true); + + } +} Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPhoneNumberFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java) =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java (rev 0) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,82 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import org.junit.Test; +import org.nuiton.validator.model.Contact; + +/** + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class FrenchPostCodeFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { + + public FrenchPostCodeFieldValidatorTest() { + super(Contact.class); + } + + @Test + @Override + public void testValidator() throws Exception { + + assertNull(bean.getPostCode()); + + // Valid postCode + bean.setPostCode("44230"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + false); + + // Valid postCode for Corsica + bean.setEmail("2A220"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + false); + + // Valid postCode for DOM + bean.setEmail("97120"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + false); + + // Valid postCode for TOM + bean.setPostCode("98120"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + false); + + // Too long postCode + bean.setPostCode("442300"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + true); + + // Too short postCode + bean.setPostCode("4423"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + true); + + // postCode cannot start with 99 + bean.setPostCode("99230"); + assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", + true); + + } +} Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchPostCodeFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java) =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java (rev 0) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,89 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import org.junit.Test; +import org.nuiton.validator.model.Company; + +/** + * @author jcouteau <couteau@codelutin.com> + * Date: 19/08/11 + * @since 2.3 + */ +public class FrenchSiretFieldValidatorTest extends AbstractFieldValidatorTest<Company> { + + public FrenchSiretFieldValidatorTest() { + super(Company.class); + } + + @Test + public void TestLuhnChecksum() throws Exception { + // verification sur de vrai numero siret (ca doit passer :) + assertTrue(FrenchSiretFieldValidator.luhnChecksum("44211670300038")); + assertTrue(FrenchSiretFieldValidator.luhnChecksum("73282932000074")); + + // verification avec les memes, en ne modifiant que le dernier chiffre + // ca doit failer + assertFalse(FrenchSiretFieldValidator.luhnChecksum("44211670300030")); + assertFalse(FrenchSiretFieldValidator.luhnChecksum("73282932000070")); + } + + @Test + @Override + public void testValidator() throws Exception { + + assertNull(bean.getSiret()); + + // Valid siret + bean.setSiret("44211670300038"); + assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", + false); + + // Valid siret + bean.setSiret("73282932000074"); + assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", + false); + + // Not Valid siret, because bad checksum + bean.setSiret("73282932000071"); + assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", + true); + + // Not valid siret + bean.setSiret("4421167030003"); + assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", + true); + + // Not valid siret + bean.setSiret("442116703000389"); + assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", + true); + + // Not valid siret + bean.setSiret("4421bf1670300038"); + assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", + true); + } +} Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/FrenchSiretFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,78 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import org.junit.Test; -import org.nuiton.validator.model.Contact; - -/** - * User: couteau - * Date: 18/08/11 - */ -public class LastNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { - - public LastNameFieldValidatorTest() { - super(Contact.class); - } - - @Test - @Override - public void testValidator() throws Exception { - - assertNull(bean.getCity()); - - // Valid name - bean.setName("Couteau"); - assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", - false); - - // Valid name - bean.setName("Le Ny"); - assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", - false); - - // Valid name - bean.setName("Clémenceau"); - assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", - false); - - // Valid name - bean.setName("Couteau--Viney"); - assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", - false); - - // Not valid name - bean.setName("2Pac"); - assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", - true); - - // Not valid name - bean.setName("Nom2Merde"); - assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format", - true); - - - } -} Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,127 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import org.junit.Test; -import org.nuiton.validator.model.Contact; - -/** - * User: couteau - * Date: 18/08/11 - */ -public class PhoneNumberFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { - - public PhoneNumberFieldValidatorTest() { - super(Contact.class); - } - - @Test - @Override - public void testValidator() throws Exception { - - assertNull(bean.getPhone()); - - // Valid phone Number - bean.setPhone("0000000000"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - false); - - // Valid phone Number - bean.setPhone("00 00 00 00 00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - false); - - // Valid phone Number - bean.setPhone("00-00-00-00-00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - false); - - // Valid phone Number - bean.setPhone("00.00.00.00.00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - false); - - // Too long phone Number - bean.setPhone("00 00 00 00 00 00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too long phone Number - bean.setPhone("00-00-00-00-00-00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too long phone Number - bean.setPhone("000000000000"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too long phone Number - bean.setPhone("00.00.00.00.00.00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too short phone Number - bean.setPhone("00.00.00.00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too short phone Number - bean.setPhone("00000000"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too short phone Number - bean.setPhone("00-00-00-00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Too short phone Number - bean.setPhone("00 00 00 00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Invalid character in phone Number - bean.setPhone("00 00 ab 00 00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Invalid character in phone Number - bean.setPhone("0000ab0000"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Invalid character in phone Number - bean.setPhone("00.00.ab.00.00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - // Invalid character in phone Number - bean.setPhone("00-00-ab-00-00"); - assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format", - true); - - } -} Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,81 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import org.junit.Test; -import org.nuiton.validator.model.Contact; - -/** - * - */ -public class PostCodeFieldValidatorTest extends AbstractFieldValidatorTest<Contact> { - - public PostCodeFieldValidatorTest() { - super(Contact.class); - } - - @Test - @Override - public void testValidator() throws Exception { - - assertNull(bean.getPostCode()); - - // Valid postCode - bean.setPostCode("44230"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - false); - - // Valid postCode for Corsica - bean.setEmail("2A220"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - false); - - // Valid postCode for DOM - bean.setEmail("97120"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - false); - - // Valid postCode for TOM - bean.setPostCode("98120"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - false); - - // Too long postCode - bean.setPostCode("442300"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - true); - - // Too short postCode - bean.setPostCode("4423"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - true); - - // postCode cannot start with 99 - bean.setPostCode("99230"); - assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format", - true); - - } -} Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,88 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import org.junit.Test; -import org.nuiton.validator.model.Company; - -/** - * User: couteau - * Date: 19/08/11 - */ -public class SiretFieldValidatorTest extends AbstractFieldValidatorTest<Company> { - - public SiretFieldValidatorTest() { - super(Company.class); - } - - @Test - public void TestLuhnChecksum () throws Exception { - // verification sur de vrai numero siret (ca doit passer :) - assertTrue(SiretFieldValidator.luhnChecksum("44211670300038")); - assertTrue(SiretFieldValidator.luhnChecksum("73282932000074")); - - // verification avec les memes, en ne modifiant que le dernier chiffre - // ca doit failer - assertFalse(SiretFieldValidator.luhnChecksum("44211670300030")); - assertFalse(SiretFieldValidator.luhnChecksum("73282932000070")); - } - - @Test - @Override - public void testValidator() throws Exception { - - assertNull(bean.getSiret()); - - // Valid siret - bean.setSiret("44211670300038"); - assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", - false); - - // Valid siret - bean.setSiret("73282932000074"); - assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", - false); - - // Not Valid siret, because bad checksum - bean.setSiret("73282932000071"); - assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", - true); - - // Not valid siret - bean.setSiret("4421167030003"); - assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", - true); - - // Not valid siret - bean.setSiret("442116703000389"); - assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", - true); - - // Not valid siret - bean.setSiret("4421bf1670300038"); - assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format", - true); - } -} Copied: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java (from rev 2180, trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java) =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java (rev 0) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -0,0 +1,66 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Validator + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin + * %% + * 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 org.nuiton.validator.xwork2.field; + +import org.junit.Test; +import org.nuiton.validator.model.Company; + +/** + * @author jcouteau <couteau@codelutin.com> + * @since 2.3 + */ +public class VATIdentificationNumberFieldValidatorTest extends AbstractFieldValidatorTest<Company> { + + public VATIdentificationNumberFieldValidatorTest() { + super(Company.class); + } + + @Test + @Override + public void testValidator() throws Exception { + + assertNull(bean.getVat()); + + // Valid vat + bean.setVat("FR57442116703"); + assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", + false); + + // Not valid vat + bean.setVat("FR 57 44211670332"); + assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", + true); + + // Not valid vat + bean.setVat("442116703000389"); + assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", + true); + + // Not valid vat, spaces in it + bean.setVat("FR 57 442116703"); + assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", + true); + } +} Property changes on: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VATIdentificationNumberFieldValidatorTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java =================================================================== --- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java 2011-08-24 13:13:11 UTC (rev 2182) @@ -1,65 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Validator - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin - * %% - * 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 org.nuiton.validator.xwork2.field; - -import org.junit.Test; -import org.nuiton.validator.model.Company; - -/** - * - */ -public class VatIntraFieldValidatorTest extends AbstractFieldValidatorTest<Company> { - - public VatIntraFieldValidatorTest() { - super(Company.class); - } - - @Test - @Override - public void testValidator() throws Exception { - - assertNull(bean.getVat()); - - // Valid vat - bean.setVat("FR57442116703"); - assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", - false); - - // Not valid vat - bean.setVat("FR 57 44211670332"); - assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", - true); - - // Not valid vat - bean.setVat("442116703000389"); - assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", - true); - - // Not valid vat, spaces in it - bean.setVat("FR 57 442116703"); - assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format", - true); - } -} Modified: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml =================================================================== --- trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml 2011-08-24 13:13:11 UTC (rev 2182) @@ -28,13 +28,13 @@ <validators> <field name="siret"> - <field-validator type="siret"> + <field-validator type="frenchSiret"> <message>company.siret.format</message> </field-validator> </field> <field name="vat"> - <field-validator type="vat"> + <field-validator type="vatIdentificationNumber"> <message>company.vat.format</message> </field-validator> </field> Property changes on: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml =================================================================== --- trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml 2011-08-24 13:13:11 UTC (rev 2182) @@ -2,8 +2,8 @@ #%L Nuiton Utils :: Nuiton Validator - $Id: Pet-error-validation.xml 2033 2011-01-23 17:28:26Z tchemit $ - $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/nuiton-validator/src/test/resou... $ + $Id$ + $HeadURL$ %% Copyright (C) 2011 CodeLutin %% @@ -34,25 +34,25 @@ </field> <field name="postCode"> - <field-validator type="postCode"> + <field-validator type="frenchPostCode"> <message>contact.postCode.format</message> </field-validator> </field> <field name="city"> - <field-validator type="cityName"> + <field-validator type="frenchCityName"> <message>contact.city.format</message> </field-validator> </field> <field name="name"> - <field-validator type="lastName"> + <field-validator type="frenchLastName"> <message>contact.name.format</message> </field-validator> </field> <field name="phone"> - <field-validator type="phoneNumber"> + <field-validator type="frenchPhoneNumber"> <message>contact.phoneNumber.format</message> </field-validator> </field> Property changes on: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-validator/src/test/resources/validators.xml =================================================================== --- trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-24 11:34:31 UTC (rev 2181) +++ trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-24 13:13:11 UTC (rev 2182) @@ -50,18 +50,26 @@ <!-- default nuiton-validator validators --> <validator name="collectionFieldExpression" class="org.nuiton.validator.xwork2.field.CollectionFieldExpressionValidator"/> <validator name="collectionUniqueKey" class="org.nuiton.validator.xwork2.field.CollectionUniqueKeyValidator"/> + + <!-- io validators --> <validator name="requiredFile" class="org.nuiton.validator.xwork2.field.RequiredFileFieldValidator"/> <validator name="existingFile" class="org.nuiton.validator.xwork2.field.ExistingFileFieldValidator"/> <validator name="notExistingFile" class="org.nuiton.validator.xwork2.field.NotExistingFileFieldValidator"/> <validator name="existingDirectory" class="org.nuiton.validator.xwork2.field.ExistingDirectoryFieldValidator"/> <validator name="notExistingDirectory" class="org.nuiton.validator.xwork2.field.NotExistingDirectoryFieldValidator"/> <validator name="fieldexpressionwithparams" class="org.nuiton.validator.xwork2.field.FieldExpressionWithParamsValidator"/> - <validator name="phoneNumber" class="org.nuiton.validator.xwork2.field.PhoneNumberFieldValidator"/> + + <!-- much much better email validator :) --> <validator name="emailNuiton" class="org.nuiton.validator.xwork2.field.EmailFieldValidator"/> - <validator name="cityName" class="org.nuiton.validator.xwork2.field.CityNameFieldValidator"/> - <validator name="lastName" class="org.nuiton.validator.xwork2.field.LastNameFieldValidator"/> - <validator name="postCode" class="org.nuiton.validator.xwork2.field.PostCodeFieldValidator"/> - <validator name="siret" class="org.nuiton.validator.xwork2.field.SiretFieldValidator"/> - <validator name="vat" class="org.nuiton.validator.xwork2.field.VATIntraFieldValidator"/> + <!-- french specific validators --> + <validator name="frenchPhoneNumber" class="org.nuiton.validator.xwork2.field.FrenchPhoneNumberFieldValidator"/> + <validator name="frenchCityName" class="org.nuiton.validator.xwork2.field.FrenchCityNameFieldValidator"/> + <validator name="frenchLastName" class="org.nuiton.validator.xwork2.field.FrenchLastNameFieldValidator"/> + <validator name="frenchPostCode" class="org.nuiton.validator.xwork2.field.FrenchPostCodeFieldValidator"/> + <validator name="frenchSiret" class="org.nuiton.validator.xwork2.field.FrenchSiretFieldValidator"/> + + <!-- eu specific validators --> + <validator name="vatIdentificationNumber" class="org.nuiton.validator.xwork2.field.VATIdentificationNumberFieldValidator"/> + </validators> \ No newline at end of file
participants (1)
-
tchemit@users.nuiton.org