struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [2/3] git commit: tests for AppendingValidatorContext and nested visitor conversion validation
Date Fri, 27 Jun 2014 11:40:32 GMT
tests for AppendingValidatorContext and nested visitor conversion validation


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/46f7f6c7
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/46f7f6c7
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/46f7f6c7

Branch: refs/heads/develop
Commit: 46f7f6c7a87cbf70e89c5d30e1155e897f759b09
Parents: 2b8a805
Author: Aleksandr Mashchenko <aleksandr.7m@gmail.com>
Authored: Fri May 16 23:57:29 2014 +0300
Committer: Aleksandr Mashchenko <aleksandr.7m@gmail.com>
Committed: Fri May 16 23:57:29 2014 +0300

----------------------------------------------------------------------
 .../validator/VisitorFieldValidatorTest.java    | 27 ++++++++++-
 .../AppendingValidatorContextTest.java          | 47 ++++++++++++++++++++
 .../xwork2/TestChildBean-validation.xml         | 21 +++++----
 3 files changed, 86 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/46f7f6c7/xwork-core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java
b/xwork-core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java
index 3c47725..ad5c1b6 100644
--- a/xwork-core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java
@@ -179,7 +179,32 @@ public class VisitorFieldValidatorTest extends XWorkTestCase {
         //the error from the action should be there too
         assertTrue(fieldErrors.containsKey("context"));
     }
-    
+
+    public void testVisitorChildConversionValidation() throws Exception {
+        //add conversion error
+        Map<String, Object> conversionErrors = new HashMap<String, Object>();
+        conversionErrors.put("bean.child.count", "bar");
+        ActionContext.getContext().setConversionErrors(conversionErrors);
+
+        validate("visitorChildValidation");
+        assertTrue(action.hasFieldErrors());
+
+        Map<String, List<String>> fieldErrors = action.getFieldErrors();
+        assertEquals(6, fieldErrors.size());
+        assertTrue(!fieldErrors.containsKey("bean.count"));
+        assertTrue(fieldErrors.containsKey("bean.name"));
+        assertTrue(fieldErrors.containsKey("bean.birth"));
+
+        assertTrue(fieldErrors.containsKey("bean.child.name"));
+        assertTrue(fieldErrors.containsKey("bean.child.birth"));
+
+        //the error from the action should be there too
+        assertTrue(fieldErrors.containsKey("context"));
+
+        //nested visitor conversion error
+        assertTrue(fieldErrors.containsKey("bean.child.count"));
+    }
+
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();

http://git-wip-us.apache.org/repos/asf/struts/blob/46f7f6c7/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/AppendingValidatorContextTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/AppendingValidatorContextTest.java
b/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/AppendingValidatorContextTest.java
new file mode 100644
index 0000000..8ce3fb8
--- /dev/null
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/AppendingValidatorContextTest.java
@@ -0,0 +1,47 @@
+package com.opensymphony.xwork2.validator.validators;
+
+import java.util.List;
+import java.util.Map;
+
+import com.opensymphony.xwork2.XWorkTestCase;
+import com.opensymphony.xwork2.validator.DelegatingValidatorContext;
+import com.opensymphony.xwork2.validator.ValidatorContext;
+import com.opensymphony.xwork2.validator.VisitorValidatorTestAction;
+import com.opensymphony.xwork2.validator.validators.VisitorFieldValidator.AppendingValidatorContext;
+
+public class AppendingValidatorContextTest extends XWorkTestCase {
+
+    private static final String FIRST_NAME = "first";
+    private static final String SECOND_NAME = "second";
+    private static final String FIELD_NAME = "fieldName";
+    private static final String FULL_FIELD_NAME = FIRST_NAME + "." + SECOND_NAME + "." +
FIELD_NAME;
+
+    private VisitorValidatorTestAction action;
+    private VisitorFieldValidator.AppendingValidatorContext validatorContext;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        action = new VisitorValidatorTestAction();
+        ValidatorContext vc1 = new DelegatingValidatorContext(action);
+
+        VisitorFieldValidator.AppendingValidatorContext vc2 = new AppendingValidatorContext(
+                vc1, "value", FIRST_NAME, "");
+        validatorContext = new AppendingValidatorContext(vc2, "value", SECOND_NAME, "");
+    }
+
+    public void testGetFullFieldName() throws Exception {
+        String fullFieldName = validatorContext.getFullFieldName(FIELD_NAME);
+        assertEquals(FULL_FIELD_NAME, fullFieldName);
+    }
+
+    public void testAddFieldError() throws Exception {
+        validatorContext.addFieldError(FIELD_NAME, "fieldError");
+        assertTrue(action.hasFieldErrors());
+
+        Map<String, List<String>> fieldErrors = action.getFieldErrors();
+        assertEquals(1, fieldErrors.size());
+        assertTrue(fieldErrors.containsKey(FULL_FIELD_NAME));
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/46f7f6c7/xwork-core/src/test/resources/com/opensymphony/xwork2/TestChildBean-validation.xml
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/resources/com/opensymphony/xwork2/TestChildBean-validation.xml
b/xwork-core/src/test/resources/com/opensymphony/xwork2/TestChildBean-validation.xml
index e8ab8af..9329801 100644
--- a/xwork-core/src/test/resources/com/opensymphony/xwork2/TestChildBean-validation.xml
+++ b/xwork-core/src/test/resources/com/opensymphony/xwork2/TestChildBean-validation.xml
@@ -4,15 +4,20 @@
         <field-validator type="requiredstring" short-circuit="true">
             <message>You must enter a name.</message>
         </field-validator>
-		<field-validator type="fieldexpression">
-			<param name="expression">name == 'test'</param>
-			<message>Name is invalid</message>
-		</field-validator> 
+    <field-validator type="fieldexpression">
+        <param name="expression">name == 'test'</param>
+        <message>Name is invalid</message>
+    </field-validator> 
     </field>
     <field name="birth">
-	    <field-validator type="date">
-	        <param name="min">01/01/1970</param>
-	        <message>You must have been born after 1970.</message>
-	    </field-validator>
+        <field-validator type="date">
+            <param name="min">01/01/1970</param>
+            <message>You must have been born after 1970.</message>
+        </field-validator>
+    </field>
+    <field name="count">
+        <field-validator type="conversion">
+            <message>Count must be an integer.</message>
+        </field-validator>
     </field>
 </validators>


Mime
View raw message