struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1311945 - in /struts/struts2/trunk/plugins/oval/src: main/java/org/apache/struts2/oval/interceptor/ test/java/org/apache/struts2/oval/interceptor/ test/resources/ test/resources/org/apache/struts2/oval/interceptor/
Date Tue, 10 Apr 2012 19:29:09 GMT
Author: lukaszlenart
Date: Tue Apr 10 19:29:09 2012
New Revision: 1311945

URL: http://svn.apache.org/viewvc?rev=1311945&view=rev
Log:
WW-3432 pushes messages variables to allow customize validation messages

Modified:
    struts/struts2/trunk/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
    struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/OValValidationInterceptorTest.java
    struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java
    struts/struts2/trunk/plugins/oval/src/test/resources/org/apache/struts2/oval/interceptor/SimpleFieldI18n.properties
    struts/struts2/trunk/plugins/oval/src/test/resources/oval-test.xml

Modified: struts/struts2/trunk/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java?rev=1311945&r1=1311944&r2=1311945&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
(original)
+++ struts/struts2/trunk/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
Tue Apr 10 19:29:09 2012
@@ -180,13 +180,16 @@ public class OValValidationInterceptor e
                 //translate message
                 String key = violation.getMessage();
 
+                String message = key;
+                // push context variable into stack, to allow use ${max}, ${min} etc in error
messages
+                valueStack.push(violation.getMessageVariables());
                 //push the validator into the stack
                 valueStack.push(violation.getContext());
-                String message = key;
                 try {
                     message = validatorContext.getText(key);
                 } finally {
                     valueStack.pop();
+                    valueStack.pop();
                 }
 
                 if (isActionError(violation)) {

Modified: struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/OValValidationInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/OValValidationInterceptorTest.java?rev=1311945&r1=1311944&r2=1311945&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/OValValidationInterceptorTest.java
(original)
+++ struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/OValValidationInterceptorTest.java
Tue Apr 10 19:29:09 2012
@@ -24,14 +24,12 @@ import com.opensymphony.xwork2.ActionPro
 import com.opensymphony.xwork2.ValidationAware;
 import com.opensymphony.xwork2.XWorkTestCase;
 import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import net.sf.oval.configuration.Configurer;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 import java.util.Locale;
-
-import net.sf.oval.configuration.Configurer;
-import org.apache.struts2.oval.interceptor.OValValidationManager;
+import java.util.Map;
 
 public class OValValidationInterceptorTest extends XWorkTestCase {
     public void testSimpleFieldsXML() throws Exception {
@@ -126,6 +124,20 @@ public class OValValidationInterceptorTe
         assertEquals(0, fieldErrors.size());
     }
 
+    public void testSimpleFieldTooLong() throws Exception {
+        ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleFieldTooLong",
null, null);
+        SimpleField action = (SimpleField) baseActionProxy.getAction();
+        action.setName("12367");
+        baseActionProxy.execute();
+
+        Map<String, List<String>> fieldErrors = action.getFieldErrors();
+
+        assertNotNull(fieldErrors);
+        assertEquals(1, fieldErrors.size());
+        assertValue(fieldErrors, "name", Arrays.asList("name is not between 0 and 3 characters
long"));
+        assertValue(fieldErrors, "name", Arrays.asList("name is not between 0 and 3 characters
long"));
+    }
+
     public void testSimpleFieldMultipleValidators() throws Exception {
         ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleField",
null, null);
         SimpleField action = (SimpleField) baseActionProxy.getAction();
@@ -195,6 +207,19 @@ public class OValValidationInterceptorTe
         assertValue(fieldErrors, "name", Arrays.asList("name cannot be null"));
     }
 
+    public void testSimpleFieldI18n2() throws Exception {
+        ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleFieldI18n",
null, null);
+        SimpleFieldI18n action = (SimpleFieldI18n) baseActionProxy.getAction();
+        action.setName("123123");
+        baseActionProxy.execute();
+
+        Map<String, List<String>> fieldErrors = action.getFieldErrors();
+
+        assertNotNull(fieldErrors);
+        assertEquals(1, fieldErrors.size());
+        assertValue(fieldErrors, "name", Arrays.asList("name value is too long, allowed length
is 3"));
+    }
+
     public void testSimpleFieldI18nDefaultKey() throws Exception {
         ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("oval", "simpleFieldI18nDefaultKey",
null, null);
         SimpleFieldI18nDefaultKey action = (SimpleFieldI18nDefaultKey) baseActionProxy.getAction();

Modified: struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java?rev=1311945&r1=1311944&r2=1311945&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java
(original)
+++ struts/struts2/trunk/plugins/oval/src/test/java/org/apache/struts2/oval/interceptor/SimpleFieldI18n.java
Tue Apr 10 19:29:09 2012
@@ -21,12 +21,12 @@
 package org.apache.struts2.oval.interceptor;
 
 import com.opensymphony.xwork2.ActionSupport;
-import net.sf.oval.constraint.NotNull;
-import net.sf.oval.constraint.NotEmpty;
 import net.sf.oval.constraint.Length;
+import net.sf.oval.constraint.NotNull;
 
 public class SimpleFieldI18n  extends ActionSupport {
     @NotNull(message = "notnull.field")
+    @Length(max = 3, message = "field.too.long")
     private String name;
 
     public String getName() {

Modified: struts/struts2/trunk/plugins/oval/src/test/resources/org/apache/struts2/oval/interceptor/SimpleFieldI18n.properties
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/oval/src/test/resources/org/apache/struts2/oval/interceptor/SimpleFieldI18n.properties?rev=1311945&r1=1311944&r2=1311945&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/oval/src/test/resources/org/apache/struts2/oval/interceptor/SimpleFieldI18n.properties
(original)
+++ struts/struts2/trunk/plugins/oval/src/test/resources/org/apache/struts2/oval/interceptor/SimpleFieldI18n.properties
Tue Apr 10 19:29:09 2012
@@ -1 +1,2 @@
-notnull.field=${field.name} cannot be null
\ No newline at end of file
+notnull.field=${field.name} cannot be null
+field.too.long=${field.name} value is too long, allowed length is ${max}
\ No newline at end of file

Modified: struts/struts2/trunk/plugins/oval/src/test/resources/oval-test.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/oval/src/test/resources/oval-test.xml?rev=1311945&r1=1311944&r2=1311945&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/oval/src/test/resources/oval-test.xml (original)
+++ struts/struts2/trunk/plugins/oval/src/test/resources/oval-test.xml Tue Apr 10 19:29:09
2012
@@ -46,6 +46,10 @@
             <interceptor-ref name="ovalValidation"/>
             <result type="void"></result>
         </action>
+        <action name="simpleFieldTooLong" class="org.apache.struts2.oval.interceptor.SimpleField">
+            <interceptor-ref name="ovalValidation"/>
+            <result type="void"></result>
+        </action>
         <action name="simpleMethod" class="org.apache.struts2.oval.interceptor.SimpleMethod">
             <interceptor-ref name="ovalValidation"/>
             <result type="void"></result>



Mime
View raw message