You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by gv...@apache.org on 2006/09/29 04:22:16 UTC
svn commit: r451089 -
/shale/framework/trunk/shale-core/src/test/java/org/apache/shale/validator/CommonsValidatorTestCase.java
Author: gvanmatre
Date: Thu Sep 28 19:22:16 2006
New Revision: 451089
URL: http://svn.apache.org/viewvc?view=rev&rev=451089
Log:
This is a fix for the locale assumptions (SHALE-294) reported by Ingo. Thanks for brining this to our attention.
Modified:
shale/framework/trunk/shale-core/src/test/java/org/apache/shale/validator/CommonsValidatorTestCase.java
Modified: shale/framework/trunk/shale-core/src/test/java/org/apache/shale/validator/CommonsValidatorTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-core/src/test/java/org/apache/shale/validator/CommonsValidatorTestCase.java?view=diff&rev=451089&r1=451088&r2=451089
==============================================================================
--- shale/framework/trunk/shale-core/src/test/java/org/apache/shale/validator/CommonsValidatorTestCase.java (original)
+++ shale/framework/trunk/shale-core/src/test/java/org/apache/shale/validator/CommonsValidatorTestCase.java Thu Sep 28 19:22:16 2006
@@ -18,6 +18,7 @@
import java.io.StringWriter;
import java.util.Iterator;
+import java.util.Locale;
import java.util.StringTokenizer;
import javax.faces.application.FacesMessage;
@@ -33,8 +34,10 @@
import junit.framework.TestSuite;
import org.apache.commons.validator.ValidatorAction;
+import org.apache.shale.component.Subview;
import org.apache.shale.component.ValidatorScript;
import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.util.Messages;
/**
@@ -42,7 +45,12 @@
*/
public class CommonsValidatorTestCase extends AbstractJsfTestCase {
-
+ /**
+ * <p>Validator message resources for this class.</p>
+ */
+ private static Messages messages =
+ new Messages("org.apache.shale.validator.messages",
+ Subview.class.getClassLoader());
protected static final Object[] COMPONENTS = {
new String[] {"javax.faces.NamingContainer", "javax.faces.component.UINamingContainer"},
@@ -107,6 +115,8 @@
loadComponents();
loadConverters();
loadValidators();
+
+ facesContext.getViewRoot().setLocale(new Locale("de", "DE"));
}
@@ -291,8 +301,15 @@
// invoke component validation
component1.validate(facesContext);
+
+ ValidatorAction va = CommonsValidator.getValidatorAction("required");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " is required.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -349,9 +366,15 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("maxlength");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId(),
+ validator1.getVars().get(CommonsValidator.MAX_LENGTH_VARNAME)});
+
// check for a error message
- checkMessage(component1.getId() + " can not be greater than "
- + validator1.getVars().get(CommonsValidator.MAX_LENGTH_VARNAME) + " characters.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -407,10 +430,16 @@
component1.setSubmittedValue("0");
// invoke component validation
component1.validate(facesContext);
-
+
+ ValidatorAction va = CommonsValidator.getValidatorAction("minlength");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId(),
+ validator1.getVars().get(CommonsValidator.MIN_LENGTH_VARNAME)});
+
// check for a error message
- checkMessage(component1.getId() + " can not be less than "
- + validator1.getVars().get(CommonsValidator.MIN_LENGTH_VARNAME) + " characters.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -466,9 +495,15 @@
component1.setSubmittedValue("123Test");
// invoke component validation
component1.validate(facesContext);
-
+
+ ValidatorAction va = CommonsValidator.getValidatorAction("mask");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " is invalid.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -523,8 +558,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("byte");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " must be a byte.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -579,8 +620,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("short");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " must be a short.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -634,8 +681,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("integer");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " must be an integer.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -690,8 +743,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("float");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " must be a float.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -746,8 +805,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("double");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " must be a double.", component1);
+ checkMessage(actualMsg, component1);
}
@@ -785,8 +850,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("long");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " must be a long.", component1);
+ checkMessage(actualMsg, component1);
}
@@ -829,8 +900,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("date");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " is not a date.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -890,9 +967,16 @@
// check for a error message
String min = (String) validator1.getVars().get(CommonsValidator.MIN_VARNAME);
- String max = (String) validator1.getVars().get(CommonsValidator.MAX_VARNAME);
- checkMessage(component1.getId() + " is not in the range " + min
- + " through " + max + ".", component1);
+ String max = (String) validator1.getVars().get(CommonsValidator.MAX_VARNAME);
+
+ ValidatorAction va = CommonsValidator.getValidatorAction("intRange");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId(), min, max});
+
+ // check for a error message
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -957,8 +1041,14 @@
// check for a error message
String min = (String) validator1.getVars().get(CommonsValidator.MIN_VARNAME);
String max = (String) validator1.getVars().get(CommonsValidator.MAX_VARNAME);
- checkMessage(component1.getId() + " is not in the range " + min
- + " through " + max + ".", component1);
+ ValidatorAction va = CommonsValidator.getValidatorAction("floatRange");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId(), min, max});
+
+ // check for a error message
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -1019,8 +1109,15 @@
// check for a error message
String min = (String) validator1.getVars().get(CommonsValidator.MIN_VARNAME);
String max = (String) validator1.getVars().get(CommonsValidator.MAX_VARNAME);
- checkMessage(component1.getId() + " is not in the range " + min
- + " through " + max + ".", component1);
+
+ ValidatorAction va = CommonsValidator.getValidatorAction("doubleRange");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId(), min, max});
+
+ // check for a error message
+ checkMessage(actualMsg, component1);
}
@@ -1058,8 +1155,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("creditCard");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " is an invalid credit card number.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -1119,8 +1222,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("email");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " is an invalid e-mail address.", component1);
+ checkMessage(actualMsg, component1);
// render the javascript for the form
StringBuffer htmlSnippet = encode(script);
@@ -1173,8 +1282,14 @@
// invoke component validation
component1.validate(facesContext);
+ ValidatorAction va = CommonsValidator.getValidatorAction("url");
+ assertNotNull("validator action", va);
+ String actualMsg = messages.getMessage(va.getMsg(),
+ facesContext.getViewRoot().getLocale(),
+ new Object[] {component1.getId()});
+
// check for a error message
- checkMessage(component1.getId() + " is an invalid url address.", component1);
+ checkMessage(actualMsg, component1);
}