You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2012/02/27 07:03:49 UTC

svn commit: r1294038 - in /myfaces/tobago/trunk/tobago-core/src: main/java/org/apache/myfaces/tobago/component/Sorter.java test/java/org/apache/myfaces/tobago/component/SorterUnitTest.java

Author: bommel
Date: Mon Feb 27 06:03:48 2012
New Revision: 1294038

URL: http://svn.apache.org/viewvc?rev=1294038&view=rev
Log:
(TOBAGO-986) improved logging 
start adding a unit test

Added:
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/SorterUnitTest.java
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=1294038&r1=1294037&r2=1294038&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java Mon Feb 27 06:03:48 2012
@@ -76,6 +76,11 @@ public class Sorter {
           String attributeName = child instanceof AbstractUICommand ? Attributes.LABEL:Attributes.VALUE;
           if (FacesUtils.hasValueBindingOrValueExpression(child, attributeName)) {
             String var = data.getVar();
+            if (var == null) {
+                LOG.error("No sorting performed. Property var of sheet is not set!");
+                unsetSortableAttribute(column);
+                return;
+            }
             String expressionString = FacesUtils.getExpressionString(child, attributeName);
             if (isSimpleProperty(expressionString)) {
               if (expressionString.startsWith("#{")
@@ -98,8 +103,11 @@ public class Sorter {
               actualComparator =
                   FacesUtils.getBindingOrExpressionComparator(facesContext, child, var, descending, comparator);
             }
+          } else {
+              LOG.error("No sorting performed. No Expression target found for sorting!");
+              unsetSortableAttribute(column);
+              return;
           }
-
         } else {
           LOG.error("No sorting performed. Value is not instanceof List or Object[]!");
           unsetSortableAttribute(column);

Added: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/SorterUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/SorterUnitTest.java?rev=1294038&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/SorterUnitTest.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/component/SorterUnitTest.java Mon Feb 27 06:03:48 2012
@@ -0,0 +1,55 @@
+package org.apache.myfaces.tobago.component;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.myfaces.test.mock.MockValueBinding;
+import org.apache.myfaces.tobago.event.SortActionEvent;
+import org.apache.myfaces.tobago.internal.mock.faces.AbstractTobagoTestBase;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SorterUnitTest extends AbstractTobagoTestBase {
+
+    @Test
+    public void testSorter() {
+        UISheet sheet = new UISheet();
+        UIColumn column = new UIColumn();
+        sheet.getChildren().add(column);
+        
+        Sorter sorter = new Sorter();
+        SortActionEvent sortActionEvent = new SortActionEvent(sheet, column);
+        sorter.perform(sortActionEvent);
+
+        List list = new ArrayList();
+        sheet.setValue(list);
+        sorter.perform(sortActionEvent);
+
+        UILink link = new UILink();
+        column.getChildren().add(link);
+
+        sorter.perform(sortActionEvent);
+        
+        link.setValueBinding(Attributes.LABEL,
+                new MockValueBinding(getFacesContext().getApplication(), "var.test"));
+
+        sorter.perform(sortActionEvent);
+
+    }
+}