Author: sergeyhalipov
Date: 2008-03-10 16:05:00 -0400 (Mon, 10 Mar 2008)
New Revision: 6667
Modified:
trunk/ui/dataTable/src/test/java/org/richfaces/component/AbstractColumnComponentTest.java
trunk/ui/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
trunk/ui/dataTable/src/test/java/org/richfaces/renderkit/DataTableRenderingTest.java
Log:
Some changes within JUnit tests.
http://jira.jboss.com/jira/browse/RF-1743
Modified:
trunk/ui/dataTable/src/test/java/org/richfaces/component/AbstractColumnComponentTest.java
===================================================================
---
trunk/ui/dataTable/src/test/java/org/richfaces/component/AbstractColumnComponentTest.java 2008-03-10
19:23:28 UTC (rev 6666)
+++
trunk/ui/dataTable/src/test/java/org/richfaces/component/AbstractColumnComponentTest.java 2008-03-10
20:05:00 UTC (rev 6667)
@@ -24,6 +24,8 @@
import java.util.Comparator;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockValueExpression;
+import org.richfaces.model.Ordering;
/**
* Created 01.03.2008
@@ -31,14 +33,27 @@
* @since 3.2
*/
-public abstract class AbstractColumnComponentTest extends AbstractAjax4JsfTestCase {
+public class AbstractColumnComponentTest extends AbstractAjax4JsfTestCase {
+ private UIColumn column;
/**
* @param name
*/
public AbstractColumnComponentTest(String name) {
super(name);
}
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ column = (UIColumn) application.createComponent(UIColumn.COMPONENT_TYPE);
+ }
+
+ public void tearDown() throws Exception {
+ column = null;
+
+ super.tearDown();
+ }
private Comparator comparator0 = new Comparator() {
@@ -63,4 +78,25 @@
protected Comparator<Object> createTestData_1_comparator() {
return comparator1;
}
+
+ public void testSettersAndGetters() throws Exception {
+ column.setValueExpression("sortOrder", new
MockValueExpression(Ordering.ASCENDING));
+ assertEquals(Ordering.ASCENDING, column.getSortOrder());
+ column.setSortOrder(Ordering.DESCENDING);
+ assertEquals(Ordering.DESCENDING, column.getSortOrder());
+
+ column.setValueExpression("filterValue", new MockValueExpression(null));
+ assertNull(column.getFilterValue());
+ column.setFilterValue("filterValue");
+ assertEquals("filterValue", column.getFilterValue());
+ }
+
+ public void testToggleSortOrder() {
+ column.setSortOrder(null);
+ column.toggleSortOrder();
+ assertEquals(Ordering.ASCENDING, column.getSortOrder());
+
+ column.toggleSortOrder();
+ assertEquals(Ordering.DESCENDING, column.getSortOrder());
+ }
}
Modified:
trunk/ui/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
===================================================================
---
trunk/ui/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java 2008-03-10
19:23:28 UTC (rev 6666)
+++
trunk/ui/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java 2008-03-10
20:05:00 UTC (rev 6667)
@@ -23,40 +23,39 @@
import java.util.ArrayList;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
+import javax.el.ELContext;
+import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
+import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputLink;
import javax.faces.component.html.HtmlOutputText;
-import javax.faces.context.FacesContext;
-import javax.faces.el.EvaluationException;
-import javax.faces.el.PropertyNotFoundException;
-import javax.faces.el.ValueBinding;
import javax.faces.model.ListDataModel;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.collections.Predicate;
+import org.richfaces.model.Ordering;
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
/**
* Unit test for DataTable component.
*/
public class DataTableComponentTest extends AbstractAjax4JsfTestCase {
+
+ private static final String SORT_FILTER_PARAMETER = "fsp";
+ private static final String FILTER_INPUT_FACET_NAME = "filterValueInput";
private UIDataTable dataTable;
-
private UIColumn column1;
-
private UIColumn column2;
-
+ private UIColumn column3;
+ private UIColumn column4;
private UIForm form = null;
-
private UIColumnGroup columnGroup;
/**
@@ -84,7 +83,7 @@
.createComponent("org.richfaces.DataTable");
dataTable.setId("dataTable");
- List list = new ArrayList();
+ List<Date> list = new ArrayList<Date>();
for (int i = 1; i <= 5; i++) {
list.add(new Date((long) Math.random()));
}
@@ -99,26 +98,7 @@
UIOutput cellElement1 = (UIOutput) createComponent(
HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
null, null, null);
- cellElement1.setValueBinding("value", new ValueBinding() {
- public Class getType(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
- return String.class;
- }
-
- public Object getValue(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
- return Long.toString(((Date) dataTable.getValue()).getTime());
- }
-
- public boolean isReadOnly(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
- return false;
- }
-
- public void setValue(FacesContext context, Object value)
- throws EvaluationException, PropertyNotFoundException {
- }
- });
+ cellElement1.setValueExpression("value", new ColumnValueExpression());
column1.getChildren().add(cellElement1);
columnGroup.getChildren().add(column1);
@@ -127,29 +107,23 @@
UIOutput cellElement2 = (UIOutput) createComponent(
HtmlOutputText.COMPONENT_TYPE, HtmlOutputLink.class.getName(),
null, null, null);
- cellElement2.setValueBinding("value", new ValueBinding() {
- public Class getType(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
- return String.class;
- }
-
- public Object getValue(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
- return Long.toString(((Date) dataTable.getValue()).getTime());
- }
-
- public boolean isReadOnly(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
- return false;
- }
-
- public void setValue(FacesContext context, Object value)
- throws EvaluationException, PropertyNotFoundException {
- }
- });
+ cellElement2.setValueExpression("value", new ColumnValueExpression());
column2.getChildren().add(cellElement2);
- columnGroup.getChildren().add(column2);
+ columnGroup.getChildren().add(column2);
+ column3 = (UIColumn)
application.createComponent("org.richfaces.Column");
+ UIOutput cellElement3 = (UIOutput) createComponent(HtmlOutputText.COMPONENT_TYPE,
HtmlOutputText.class.getName(),
+ null, null, null);
+ cellElement3.setValueExpression("value", new ColumnValueExpression());
+ column3.getChildren().add(cellElement1);
+ dataTable.getChildren().add(column3);
+
+ column4 = (UIColumn) application.createComponent("org.richfaces.Column");
+ UIOutput cellElement4 = (UIOutput) createComponent(HtmlOutputText.COMPONENT_TYPE,
HtmlOutputText.class.getName(),
+ null, null, null);
+ cellElement4.setValueExpression("value", new ColumnValueExpression());
+ column4.getChildren().add(cellElement1);
+ dataTable.getChildren().add(column4);
form.getChildren().add(dataTable);
@@ -165,6 +139,8 @@
column1 = null;
column2 = null;
+ column3 = null;
+ column4 = null;
columnGroup = null;
dataTable = null;
}
@@ -234,10 +210,6 @@
HtmlPage page = renderView();
assertNotNull(page);
- // System.out.println(page.asXml());
-
- // System.out.println(page.asXml());
-
}
/**
@@ -280,4 +252,71 @@
assertTrue(!ajaxSupportPredicate.evaluate(notAjaxSupport));
}
+
+ /**
+ * Tests if component accepts request parameters and stores them
+ *
+ * @throws Exception
+ */
+ public void testDecode() throws Exception {
+ dataTable.setVar("var");
+
+ UIInput input = new UIInput();
+ input.setId("input");
+ column3.getFacets().put(FILTER_INPUT_FACET_NAME, input);
+
+ externalContext.addRequestParameterMap(dataTable.getClientId(facesContext),
SORT_FILTER_PARAMETER);
+ externalContext.addRequestParameterMap(SORT_FILTER_PARAMETER,
column3.getClientId(facesContext));
+ externalContext.addRequestParameterMap(input.getClientId(facesContext),
FILTER_INPUT_FACET_NAME);
+
+ column4.setSortOrder(Ordering.ASCENDING);
+
+ dataTable.processDecodes(facesContext);
+ assertEquals(Ordering.UNSORTED, column4.getSortOrder());
+ assertEquals(FILTER_INPUT_FACET_NAME, column3.getFilterValue());
+
+ }
+
+ protected class ColumnValueExpression extends ValueExpression {
+
+ private static final long serialVersionUID = -4572752019634445014L;
+
+ public Class<?> getExpectedType() {
+ return null;
+ }
+
+ public Class<?> getType(ELContext context) {
+ return String.class;
+ }
+
+ public Object getValue(ELContext context) {
+ return Long.toString(((Date) dataTable.getValue()).getTime());
+ }
+
+ public boolean isReadOnly(ELContext context) {
+ return false;
+ }
+
+ public void setValue(ELContext context, Object value) {
+
+ }
+
+ public boolean equals(Object obj) {
+ return false;
+ }
+
+ public String getExpressionString() {
+ return null;
+ }
+
+ public int hashCode() {
+ return 0;
+ }
+
+ public boolean isLiteralText() {
+ return false;
+ }
+
+ }
+
}
\ No newline at end of file
Modified:
trunk/ui/dataTable/src/test/java/org/richfaces/renderkit/DataTableRenderingTest.java
===================================================================
---
trunk/ui/dataTable/src/test/java/org/richfaces/renderkit/DataTableRenderingTest.java 2008-03-10
19:23:28 UTC (rev 6666)
+++
trunk/ui/dataTable/src/test/java/org/richfaces/renderkit/DataTableRenderingTest.java 2008-03-10
20:05:00 UTC (rev 6667)
@@ -106,8 +106,13 @@
null, null, null);
cellElement2.setValueExpression("value", new ColumnValueExpression());
column2.getChildren().add(cellElement2);
- columnGroup.getChildren().add(column2);
+ columnGroup.getChildren().add(column2);
+ javax.faces.component.UIColumn column3 = new javax.faces.component.UIColumn();
+ UIOutput cellElement3 = (UIOutput)
application.createComponent(UIOutput.COMPONENT_TYPE);
+ cellElement3.setValue("value");
+ column3.getChildren().add(cellElement3);
+ dataTable.getChildren().add(column3);
form.getChildren().add(dataTable);
@@ -251,17 +256,17 @@
.getClientId(facesContext));
assertNotNull(table);
- List captions = table.getHtmlElementsByTagName("caption");
+ List<HtmlElement> captions =
table.getHtmlElementsByTagName("caption");
assertNotNull(captions);
assertEquals(1, captions.size());
String classAttr = ((HtmlElement) captions.get(0))
.getAttributeValue("class");
assertTrue(classAttr.contains("dr-table-caption rich-table-caption"));
- List headers = table.getHtmlElementsByTagName("thead");
+ List<HtmlElement> headers =
table.getHtmlElementsByTagName("thead");
assertNotNull(headers);
assertEquals(1, headers.size());
- List trs = ((HtmlElement) headers.get(0))
+ List<HtmlElement> trs = ((HtmlElement) headers.get(0))
.getHtmlElementsByTagName("tr");
assertTrue(trs.size() > 0);
HtmlElement tr = (HtmlElement) trs.get(0);
@@ -279,7 +284,7 @@
.contains("dr-table-headercell rich-table-headercell"));
assertTrue(classAttr.contains("cola"));
- List footers = table.getHtmlElementsByTagName("tfoot");
+ List<HtmlElement> footers =
table.getHtmlElementsByTagName("tfoot");
assertNotNull(footers);
assertEquals(1, footers.size());
trs = ((HtmlElement) footers.get(0)).getHtmlElementsByTagName("tr");
@@ -329,7 +334,7 @@
.getClientId(facesContext));
assertNotNull(table);
- List captions = table.getHtmlElementsByTagName("caption");
+ List<HtmlElement> captions =
table.getHtmlElementsByTagName("caption");
assertNotNull(captions);
assertEquals(1, captions.size());
String classAttr = ((HtmlElement) captions.get(0))
@@ -338,16 +343,16 @@
classAttr = ((HtmlElement)
captions.get(0)).getAttributeValue("style");
assertTrue(classAttr.contains("captionStyle"));
- List bodies = table.getHtmlElementsByTagName("tbody");
+ List<HtmlElement> bodies =
table.getHtmlElementsByTagName("tbody");
assertTrue(bodies.size() > 0);
- List trs = ((HtmlElement)
bodies.get(0)).getHtmlElementsByTagName("tr");
+ List<HtmlElement> trs = ((HtmlElement)
bodies.get(0)).getHtmlElementsByTagName("tr");
assertTrue(trs.size() > 0);
HtmlElement tr = (HtmlElement) trs.get(0);
assertNotNull(tr);
classAttr = tr.getAttributeValue("class");
assertTrue(classAttr.contains("row1"));
- List tds = tr.getHtmlElementsByTagName("td");
+ List<HtmlElement> tds = tr.getHtmlElementsByTagName("td");
assertTrue(tds.size() > 0);
HtmlElement td = (HtmlElement) tds.get(0);
assertNotNull(td);
@@ -358,6 +363,8 @@
protected class ColumnValueExpression extends ValueExpression {
+ private static final long serialVersionUID = -4572752019634445014L;
+
public Class<?> getExpectedType() {
return null;
}