Author: hardy.ferentschik
Date: 2009-11-05 04:51:52 -0500 (Thu, 05 Nov 2009)
New Revision: 17927
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/User.java
Modified:
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages.properties
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_de.properties
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_fr.properties
Log:
HV-268 Fixed resource template messages
Modified:
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages.properties
===================================================================
---
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages.properties 2009-11-05
06:47:50 UTC (rev 17926)
+++
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages.properties 2009-11-05
09:51:52 UTC (rev 17927)
@@ -12,8 +12,8 @@
javax.validation.constraints.Past.message=must be in the past
javax.validation.constraints.Pattern.message=must match "{regexp}"
javax.validation.constraints.Size.message=size must be between {min} and {max}
-org.hibernate.validator.constraints.Email.message="{value}" is not a valid
email address
+org.hibernate.validator.constraints.Email.message=not a well-formed email address
org.hibernate.validator.constraints.Length.message=length must be between {min} and
{max}
org.hibernate.validator.constraints.NotEmpty.message=may not be empty
-org.hibernate.validator.constraints.Range.message={value} must be between {min} and
{max}
+org.hibernate.validator.constraints.Range.message=must be between {min} and {max}
Modified:
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_de.properties
===================================================================
---
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_de.properties 2009-11-05
06:47:50 UTC (rev 17926)
+++
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_de.properties 2009-11-05
09:51:52 UTC (rev 17927)
@@ -14,5 +14,5 @@
javax.validation.constraints.Digits.message=numerischer Wert au\u00DFerhalb erlaubten
Wertebereichs (<{integer} Ziffern>.<{fraction} Ziffern> erwarted)
javax.validation.constraints.DecimalMin.message=muss gr\u00F6ssergleich {value} sein
javax.validation.constraints.DecimalMax.message=muss kleinergleich {value} sein
-org.hibernate.validator.constraints.Email.message="{value}" ist keine
g\u00FCltige E-Mail-Adresse
-org.hibernate.validator.constraints.Range.message={value} muss zwischen {min} und {max}
liegen
\ No newline at end of file
+org.hibernate.validator.constraints.Email.message=keine g\u00FCltige E-Mail-Adresse
+org.hibernate.validator.constraints.Range.message=muss zwischen {min} und {max} liegen
\ No newline at end of file
Modified:
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_fr.properties
===================================================================
---
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_fr.properties 2009-11-05
06:47:50 UTC (rev 17926)
+++
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_fr.properties 2009-11-05
09:51:52 UTC (rev 17927)
@@ -14,5 +14,5 @@
javax.validation.constraints.Digits.message=Valeur num\u00E9rique hors limite
(<{integer} chiffres>.<{fraction} chiffres> attendus)
javax.validation.constraints.DecimalMin.message=doit \u00EAtre plus grand que {value}
javax.validation.constraints.DecimalMax.message=doit \u00EAtre plus petit que {value}
-org.hibernate.validator.constraints.Email.message=Address email "{value}" mal
form�e
-org.hibernate.validator.constraints.Range.message={value} doit �tre entre {min} et {max}
\ No newline at end of file
+org.hibernate.validator.constraints.Email.message=Address email mal form\u00E9e
+org.hibernate.validator.constraints.Range.message=doit \u00EAtre entre {min} et {max}
\ No newline at end of file
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java 2009-11-05
09:51:52 UTC (rev 17927)
@@ -0,0 +1,109 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.engine.messageinterpolation;
+
+import java.util.Locale;
+import java.util.Set;
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.engine.ResourceBundleMessageInterpolator;
+import org.hibernate.validator.util.TestUtil;
+import static
org.hibernate.validator.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.validator.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MessageInterpolationWithDefaultBundleTest {
+ private Locale defaultLocale;
+
+ @BeforeClass
+ public void storeDefaultLocale() {
+ defaultLocale = Locale.getDefault();
+ }
+
+ @AfterClass
+ public void restoreDefaultLocale() {
+ Locale.setDefault( defaultLocale );
+ }
+
+ /**
+ * HV-268
+ */
+ @Test
+ public void testEmailAndRangeMessageEnglishLocale() {
+ Locale.setDefault( Locale.ENGLISH );
+ Configuration config = TestUtil.getConfiguration();
+ config.messageInterpolator( new ResourceBundleMessageInterpolator() );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "not a well-formed email address", "must be
between 18 and 21"
+ );
+ }
+
+ /**
+ * HV-268
+ */
+ @Test
+ public void testEmailAndRangeMessageGermanLocale() {
+ Locale.setDefault( Locale.GERMAN );
+ Configuration config = TestUtil.getConfiguration();
+ config.messageInterpolator( new ResourceBundleMessageInterpolator() );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "keine g\u00FCltige E-Mail-Adresse", "muss
zwischen 18 und 21 liegen"
+ );
+ }
+
+ /**
+ * HV-268
+ */
+ @Test
+ public void testEmailAndRangeMessageFrenchLocale() {
+ Locale.setDefault( Locale.FRENCH );
+ Configuration config = TestUtil.getConfiguration();
+ config.messageInterpolator( new ResourceBundleMessageInterpolator() );
+ Validator validator = config.buildValidatorFactory().getValidator();
+ User user = new User();
+ user.setEmail( "foo" );
+ user.setAge( 16 );
+ Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
+ assertNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages(
+ constraintViolations, "Address email mal form\u00E9e", "doit \u00EAtre
entre 18 et 21"
+ );
+ }
+}
+
+
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/User.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/User.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/User.java 2009-11-05
09:51:52 UTC (rev 17927)
@@ -0,0 +1,50 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.engine.messageinterpolation;
+
+import org.hibernate.validator.constraints.Email;
+import org.hibernate.validator.constraints.Range;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class User {
+ @Email
+ private String email;
+
+ @Range(min = 18, max = 21)
+ private int age;
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+}
+
+