You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/08/24 16:05:54 UTC
svn commit: r988547 -
/myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java
Author: jakobk
Date: Tue Aug 24 14:05:54 2010
New Revision: 988547
URL: http://svn.apache.org/viewvc?rev=988547&view=rev
Log:
MYFACES-2892 INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL applies for String only (test case)
Modified:
myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java
Modified: myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java?rev=988547&r1=988546&r2=988547&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java (original)
+++ myfaces/core/trunk/api/src/test/java/javax/faces/component/UIInputTest.java Tue Aug 24 14:05:54 2010
@@ -207,7 +207,23 @@ public class UIInputTest extends Abstrac
InitParameterMockExternalContext mockExtCtx =
new InitParameterMockExternalContext(servletContext, request, response);
mockExtCtx.getInitParameterMap().put("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL", "true");
+ mockExtCtx.getInitParameterMap().put(UIInput.VALIDATE_EMPTY_FIELDS_PARAM_NAME, "true");
facesContext.setExternalContext(mockExtCtx);
+
+ input.addValidator(new Validator()
+ {
+
+ public void validate(FacesContext context,
+ UIComponent component, Object value)
+ throws ValidatorException
+ {
+ // the value must be null
+ assertNull(value);
+ }
+
+
+ });
+
input.setSubmittedValue("");
input.validate(facesContext);
@@ -218,6 +234,61 @@ public class UIInputTest extends Abstrac
facesContext.setExternalContext(externalContext);
}
}
+
+ public void testValidateWithNonStringWithEmptyStringAsNullEnabled()
+ {
+ try
+ {
+ InitParameterMockExternalContext mockExtCtx =
+ new InitParameterMockExternalContext(servletContext, request, response);
+ mockExtCtx.getInitParameterMap().put("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL", "true");
+ facesContext.setExternalContext(mockExtCtx);
+
+ input.addValidator(new Validator()
+ {
+
+ public void validate(FacesContext context,
+ UIComponent component, Object value)
+ throws ValidatorException
+ {
+ // the value must not be null
+ assertNotNull(value);
+
+ // throw Exception to ensure this was called
+ throw new RuntimeException();
+ }
+
+
+ });
+
+ // set Object with toString() returning "" as submittedValue
+ input.setSubmittedValue(new Object()
+ {
+
+ @Override
+ public String toString()
+ {
+ return "";
+ }
+
+ });
+
+ try
+ {
+ input.validate(facesContext);
+
+ fail(); // validate() was not called --> fail!
+ }
+ catch (RuntimeException e)
+ {
+ // great - validate() was called!
+ }
+ }
+ finally
+ {
+ facesContext.setExternalContext(externalContext);
+ }
+ }
public void testValidateWithNonEmptyStringWithEmptyStringAsNullEnabled()
{