Commits

Anonymous committed 8509b66

Additional unit tests for OGNL-131. Found problem but real fix is needed in Tapestry.

  • Participants
  • Parent commits ba3b5e6

Comments (0)

Files changed (11)

File src/java/ognl/ASTChain.java

     {
         boolean handled = false;
 
-        for(int i = 0, ilast = _children.length - 2; i <= ilast; ++i) {
+        for(int i = 0, ilast = _children.length - 2; i <= ilast; ++i)
+        {
             if (i == ilast) {
-                if (_children[i] instanceof ASTProperty) {
+                if (_children[i] instanceof ASTProperty)
+                {
                     ASTProperty propertyNode = (ASTProperty) _children[i];
                     int indexType = propertyNode.getIndexedPropertyType(context, target);
 
-                    if ((indexType != OgnlRuntime.INDEXED_PROPERTY_NONE) && (_children[i + 1] instanceof ASTProperty)) {
+                    if ((indexType != OgnlRuntime.INDEXED_PROPERTY_NONE) && (_children[i + 1] instanceof ASTProperty))
+                    {
                         ASTProperty indexNode = (ASTProperty) _children[i + 1];
 
-                        if (indexNode.isIndexedAccess()) {
+                        if (indexNode.isIndexedAccess())
+                        {
                             Object index = indexNode.getProperty(context, target);
 
-                            if (index instanceof DynamicSubscript) {
-                                if (indexType == OgnlRuntime.INDEXED_PROPERTY_INT) {
+                            if (index instanceof DynamicSubscript)
+                            {
+                                if (indexType == OgnlRuntime.INDEXED_PROPERTY_INT)
+                                {
                                     Object array = propertyNode.getValue(context, target);
                                     int len = Array.getLength(array);
 
-                                    switch(((DynamicSubscript) index).getFlag()) {
+                                    switch(((DynamicSubscript) index).getFlag())
+                                    {
                                         case DynamicSubscript.ALL:
                                             System.arraycopy(target, 0, value, 0, len);
                                             handled = true;
                                             index = new Integer((len > 0) ? (len - 1) : -1);
                                             break;
                                     }
-                                } else {
-                                    if (indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT) { throw new OgnlException(
-                                            "DynamicSubscript '" + indexNode
-                                            + "' not allowed for object indexed property '" + propertyNode
-                                            + "'"); }
+                                } else
+                                {
+                                    if (indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT)
+                                    {
+                                        throw new OgnlException("DynamicSubscript '" + indexNode
+                                                                + "' not allowed for object indexed property '" + propertyNode
+                                                                + "'");
+                                    }
                                 }
                             }
-                            if (!handled) {
-                                OgnlRuntime.setIndexedProperty(context, target, propertyNode.getProperty(context,
-                                                                                                         target).toString(), index, value);
+                            if (!handled)
+                            {
+                                OgnlRuntime.setIndexedProperty(context, target,
+                                                               propertyNode.getProperty(context, target).toString(),
+                                                               index, value);
                                 handled = true;
                                 i++;
                             }
                     }
                 }
             }
-            if (!handled) {
+            if (!handled)
+            {
                 target = _children[i].getValue(context, target);
             }
         }
-        if (!handled) {
+        if (!handled)
+        {
             _children[_children.length - 1].setValue(context, target, value);
         }
     }

File src/java/ognl/OgnlRuntime.java

     {
         PropertyAccessor accessor;
 
-        if (source == null) {
+        if (source == null)
+        {
             throw new OgnlException("source is null for getProperty(null, \"" + name + "\")");
         }
-        if ((accessor = getPropertyAccessor(getTargetClass(source))) == null) {
-            throw new OgnlException(
-                    "No property accessor for " + getTargetClass(source).getName());
+        if ((accessor = getPropertyAccessor(getTargetClass(source))) == null)
+        {
+            throw new OgnlException("No property accessor for " + getTargetClass(source).getName());
         }
+        
         return accessor.getProperty(context, source, name);
     }
 

File src/test/java/org/ognl/test/ASTPropertyTest.java

         
         assertTrue(List.class.isAssignableFrom(node.getAccessor().get(context, root).getClass()));
     }
+
+    public void test_Set_Chain_Indexed_Property() throws Exception
+    {
+        Root root = new Root();
+        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
+
+        context.setRoot(root);
+        context.setCurrentObject(root);
+
+        SimpleNode node = (SimpleNode) Ognl.parseExpression("tab.searchCriteriaSelections[index1][index2]");
+        node.setValue(context, root, Boolean.FALSE);
+    }
 }

File src/test/java/org/ognl/test/GenericsTest.java

+package org.ognl.test;
+
+import org.ognl.test.objects.BaseGeneric;
+import org.ognl.test.objects.GameGeneric;
+
+/**
+ * Tests java >= 1.5 generics support in ognl.
+ */
+public class GenericsTest 
+{
+    private static BaseGeneric ROOT = new GameGeneric();
+
+    private static Object[][] TESTS = {
+            { ROOT, "ids", new Long[] { 10l, 20l}},
+    };
+}

File src/test/java/org/ognl/test/IndexAccessTest.java

     private static Root ROOT = new Root();
 
     private static Object[][] TESTS = {
-            // indexed access of with navigation chain (should start back at root)
             {ROOT, "list[index]", ROOT.getList().get(ROOT.getIndex())},
             {ROOT, "list[objectIndex]", ROOT.getList().get(ROOT.getObjectIndex().intValue())},
             {ROOT, "array[objectIndex]", ROOT.getArray()[ROOT.getObjectIndex().intValue()] },
             {ROOT, "(index == (array.length - 3)) ? 'toggle toggleSelected' : 'toggle'", "toggle toggleSelected"},
             {ROOT, "\"return toggleDisplay('excdisplay\"+index+\"', this)\"", "return toggleDisplay('excdisplay1', this)"},
             {ROOT, "map[mapKey].split('=')[0]", "StringStuff"},
-            {ROOT, "booleanValues[index1][index2]", Boolean.FALSE}
+            {ROOT, "booleanValues[index1][index2]", Boolean.FALSE},
+            {ROOT, "tab.searchCriteria[index1].displayName", "Woodland creatures"},
+            {ROOT, "tab.searchCriteriaSelections[index1][index2]", Boolean.TRUE},
+            {ROOT, "tab.searchCriteriaSelections[index1][index2]", Boolean.TRUE, Boolean.FALSE, Boolean.FALSE},
     };
 
     /*
     {
         TestSuite result = new TestSuite();
 
-        for (int i = 0; i < TESTS.length; i++) {
-            result.addTest(new IndexAccessTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1], TESTS[i][2]));
+        for (int i = 0; i < TESTS.length; i++)
+        {
+            if (TESTS[i].length == 5)
+            {
+                result.addTest(new IndexAccessTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1], TESTS[i][2],
+                                                   TESTS[i][3], TESTS[i][4]));
+            } else
+            {
+                result.addTest(new IndexAccessTest((String) TESTS[i][1], TESTS[i][0], (String) TESTS[i][1], TESTS[i][2]));
+            }
         }
         return result;
     }
         super(name);
     }
 
-    public IndexAccessTest(String name, Object root, String expressionString, Object expectedResult, Object setValue,
-                           Object expectedAfterSetResult)
+    public IndexAccessTest(String name, Object root, String expressionString, Object expectedResult,
+                           Object setValue, Object expectedAfterSetResult)
     {
         super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
     }

File src/test/java/org/ognl/test/MethodTest.java

 
     private static Simple ROOT = new Simple();
     private static ListSource LIST = new ListSourceImpl();
-    private static BaseGeneric<GameGenericObject> GENERIC = new GameGeneric();
+    private static BaseGeneric<GameGenericObject, Long> GENERIC = new GameGeneric();
 
     private static Object[][] TESTS = {
             { "hashCode()", new Integer(ROOT.hashCode()) } ,

File src/test/java/org/ognl/test/objects/BaseGeneric.java

 package org.ognl.test.objects;
 
+import java.io.Serializable;
+
 /**
  * Used to test ognl handling of java generics.
  */
-public class BaseGeneric<E extends GenericObject> {
+public class BaseGeneric<E extends GenericObject, I extends Serializable> {
 
     E _value;
     GenericService _service;
+    protected I[] ids;
 
     public BaseGeneric()
     {
         _service = new GenericServiceImpl();
     }
 
+    public void setIds(I[] ids)
+    {
+        this.ids = ids;
+    }
+
     public String getMessage()
     {
         return "Message";

File src/test/java/org/ognl/test/objects/GameGeneric.java

 /**
  *
  */
-public class GameGeneric extends BaseGeneric<GameGenericObject> {
+public class GameGeneric extends BaseGeneric<GameGenericObject, Long> {
 
     public GameGeneric()
     {

File src/test/java/org/ognl/test/objects/Root.java

 
     private ITreeContentProvider _contentProvider = new TreeContentProvider();
     private Indexed _indexed = new Indexed();
+    private SearchTab _tab = new SearchTab();
     
     /*===================================================================
 		Public static methods
         return 1;
     }
 
+    public SearchTab getTab()
+    {
+        return _tab;
+    }
+
+    public void setTab(SearchTab tab)
+    {
+        _tab = tab;
+    }
+
     public static class A
     {
         public int methodOfA(B b)

File src/test/java/org/ognl/test/objects/SearchCriteria.java

+package org.ognl.test.objects;
+
+/**
+ * Test for OGNL-131.
+ */
+public class SearchCriteria {
+
+    String _displayName;
+
+    public SearchCriteria(String name)
+    {
+        _displayName = name;
+    }
+
+    public String getDisplayName()
+    {
+        return _displayName;
+    }
+}

File src/test/java/org/ognl/test/objects/SearchTab.java

+package org.ognl.test.objects;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Test for OGNL-131.
+ */
+public class SearchTab {
+
+    /**
+     * Flags stating which search criteria are selected
+     */
+    private List<List<Boolean>> searchCriteriaSelections = new ArrayList<List<Boolean>>();
+    {
+        searchCriteriaSelections.add(Arrays.asList(Boolean.TRUE,  Boolean.FALSE, Boolean.FALSE));
+        searchCriteriaSelections.add(Arrays.asList(Boolean.FALSE,  Boolean.TRUE, Boolean.TRUE));
+    }
+
+    public List<List<Boolean>> getSearchCriteriaSelections(){
+        return this.searchCriteriaSelections;
+    }
+    public void setSearchCriteriaSelections(List<List<Boolean>> selections){
+        this.searchCriteriaSelections = selections;
+    }
+    
+    /**
+     * Filters that can be applied to this tabs searches
+     */
+    private List<SearchCriteria> searchCriteria = new ArrayList<SearchCriteria>();
+    {
+        searchCriteria.add(new SearchCriteria("Crittery critters"));
+        searchCriteria.add(new SearchCriteria("Woodland creatures"));
+    }
+
+    public List<SearchCriteria> getSearchCriteria(){
+        return this.searchCriteria;
+    }
+
+    public void setSearchCriteria(List<SearchCriteria> searchCriteria){
+        this.searchCriteria = searchCriteria;
+    }
+
+    /**
+     * 2D list of options available for each criteria
+     */
+    private List<List<String>> searchCriteriaOptions = new ArrayList<List<String>>();
+
+    public List<List<String>> getSearchCriteriaOptions() {
+        return this.searchCriteriaOptions;
+    }
+
+    public void setSearchCriteriaOptions(List<List<String>> searchCriteriaOptions) {
+        
+        this.searchCriteriaOptions = searchCriteriaOptions;
+    }
+}