Commits

Anonymous committed d5e9c01

Added test for hierarchy traversal given an interface.

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@281e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (3)

src/test/com/opensymphony/xwork/test/DataAware2-validation.xml

+<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">
+<validators>
+    <field name="bling">
+        <field-validator type="requiredstring">
+            <message>You must enter a value for data.</message>
+        </field-validator>
+    </field>
+</validators>

src/test/com/opensymphony/xwork/test/DataAware2.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.test;
+
+
+/**
+ * Used to test hierarchy traversal for interfaces.
+ *
+ * @author Mark Woon
+ */
+public interface DataAware2 extends DataAware {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void setBling(String bling);
+
+    public String getBling();
+}

src/test/com/opensymphony/xwork/validator/ActionValidatorManagerTest.java

 package com.opensymphony.xwork.validator;
 
 import com.opensymphony.xwork.SimpleAction;
+import com.opensymphony.xwork.test.DataAware2;
 import com.opensymphony.xwork.test.SimpleAction2;
 import com.opensymphony.xwork.test.SimpleAction3;
 import com.opensymphony.xwork.test.User;
     }
 
     public void testGetValidatorsForInterface() {
+        List validatorList = ActionValidatorManager.getValidators(DataAware2.class, alias);
+
+        // 3 in interface hierarchy, 2 from parent interface (1 default + 1 context)
+        assertEquals(3, validatorList.size());
+
+        final FieldValidator dataValidator1 = (FieldValidator) validatorList.get(0);
+        assertEquals("data", dataValidator1.getFieldName());
+        assertTrue(dataValidator1 instanceof RequiredFieldValidator);
+
+        final FieldValidator dataValidator2 = (FieldValidator) validatorList.get(1);
+        assertEquals("data", dataValidator2.getFieldName());
+        assertTrue(dataValidator2 instanceof RequiredStringValidator);
+
+        final FieldValidator blingValidator = (FieldValidator) validatorList.get(2);
+        assertEquals("bling", blingValidator.getFieldName());
+        assertTrue(blingValidator instanceof RequiredStringValidator);
+    }
+
+    public void testGetValidatorsFromInterface() {
         List validatorList = ActionValidatorManager.getValidators(SimpleAction3.class, alias);
 
         // 5 in the class hierarchy + 1 in the interface