[richfaces-svn-commits] JBoss Rich Faces SVN: r407 - trunk/richfaces/dataTable/src/test/java/org/richfaces/component.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Apr 13 10:37:52 EDT 2007


Author: F.antonov
Date: 2007-04-13 10:37:52 -0400 (Fri, 13 Apr 2007)
New Revision: 407

Added:
   trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java
   trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataGridComponentTest.java
Removed:
   trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
Log:
DataTable components test cases.

Added: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java	                        (rev 0)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/AbstractListComponentsTest.java	2007-04-13 14:37:52 UTC (rev 407)
@@ -0,0 +1,123 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.component;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.model.ListDataModel;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlColumnGroup;
+import org.richfaces.component.html.HtmlColumn;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for DataList component.
+ */
+public class AbstractListComponentsTest extends AbstractAjax4JsfTestCase {
+
+    private UIDataList dataList;
+
+    /**
+     * Create the test case
+     * 
+     * @param testName
+     *            name of the test case
+     */
+    public AbstractListComponentsTest(String testName) {
+        super(testName);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+     */
+    public void setUp() throws Exception {
+        super.setUp();
+
+        dataList = (UIDataList) application
+                .createComponent("org.richfaces.DataList");
+        dataList.setId("dataList");
+
+        List list = new ArrayList();
+        for (int i = 1; i <= 10; i++) {
+            list.add(new Date((long) Math.random()));
+        }
+        dataList.setValue(list);
+
+        facesContext.getViewRoot().getChildren().add(dataList);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        super.tearDown();
+        dataList = null;
+    }
+
+    /**
+     * Test DataList component rendering.
+     * 
+     * @throws Exception
+     */
+    public void testRenderDataList() throws Exception {
+
+        HtmlPage page = renderView();
+        assertNotNull(page);
+        // System.out.println(page.asXml());
+
+        // TYPE=disc|circle|square
+        dataList.getAttributes().put("type", "circle");
+
+        HtmlElement ul = page.getHtmlElementById(dataList
+                .getClientId(facesContext));
+        assertNotNull(ul);
+        assertEquals("ul", ul.getNodeName());
+        String classAttr = ul.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-list rich-datalist"));
+        
+        List lis = ul.getHtmlElementsByTagName("li");
+        assertTrue(lis.size() > 0);
+        assertEquals(lis.size(), 10);
+        HtmlElement li = (HtmlElement) lis.get(0);
+        assertNotNull(li);
+        classAttr = li.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-list-item rich-list-item"));
+
+    }
+
+}

Added: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataGridComponentTest.java
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataGridComponentTest.java	                        (rev 0)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataGridComponentTest.java	2007-04-13 14:37:52 UTC (rev 407)
@@ -0,0 +1,239 @@
+/**
+ * License Agreement.
+ *
+ *  JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007  Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.component;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.model.ListDataModel;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlColumnGroup;
+import org.richfaces.component.html.HtmlColumn;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for DataGrid component.
+ */
+public class DataGridComponentTest extends AbstractAjax4JsfTestCase {
+
+   private UIDataGrid dataGrid;
+   
+   
+
+    /**
+     * Create the test case
+     * 
+     * @param testName
+     *            name of the test case
+     */
+    public DataGridComponentTest(String testName) {
+        super(testName);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+     */
+    public void setUp() throws Exception {
+        super.setUp();
+
+        dataGrid = (UIDataGrid) application
+                .createComponent("org.richfaces.DataGrid");
+        dataGrid.setId("dataGrid");
+        
+        dataGrid.setColumns(5);
+        
+        List list = new ArrayList();
+        for (int i = 1; i <= 10; i++) {
+            list.add(new Date((long) Math.random()));
+        }
+        dataGrid.setValue(list);
+        
+        facesContext.getViewRoot().getChildren().add(dataGrid);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        super.tearDown();        
+        dataGrid = null;
+    }    
+
+    /**
+     * Test DataGrid component rendering.
+     * 
+     * @throws Exception
+     */
+    public void testRenderDataGrid() throws Exception {
+        
+        HtmlPage page = renderView();
+        assertNotNull(page);
+        //System.out.println(page.asXml());
+
+        HtmlElement table = page.getHtmlElementById(dataGrid
+                .getClientId(facesContext));
+        assertNotNull(table);
+    }
+    
+    /**
+     * Test DataGrid component facets rendering.
+     * 
+     * @throws Exception
+     */
+    public void testRenderDataGridFacets() throws Exception {
+        
+        dataGrid.getAttributes().put("rowClasses", "row1,row2");
+        dataGrid.getAttributes().put("columnClasses", "A,B,Y,B,C");
+
+        UIOutput header = (UIOutput) createComponent(
+                HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+                null, null, null);
+        dataGrid.getFacets().put("header", header);
+        header.setValue("Header");
+        
+        UIOutput footer = (UIOutput) createComponent(
+                HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+                null, null, null);
+        dataGrid.getFacets().put("footer", footer);
+        footer.setValue("Footer");
+        
+        UIOutput caption = (UIOutput) createComponent(
+                HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+                null, null, null);
+        dataGrid.getFacets().put("caption", caption);
+        caption.setValue("Caption");
+
+        HtmlPage page = renderView();
+        assertNotNull(page);
+        //System.out.println(page.asXml());
+
+        HtmlElement table = page.getHtmlElementById(dataGrid
+                .getClientId(facesContext));
+        assertNotNull(table);
+        assertEquals("table", table.getNodeName());
+        String classAttr = table.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-table rich-table"));
+        
+        List captions = table.getHtmlElementsByTagName("caption");
+        assertNotNull(captions);
+        assertEquals(1, captions.size());
+        classAttr = ((HtmlElement) captions.get(0))
+                .getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-table-caption rich-table-caption"));
+
+        List headers = table.getHtmlElementsByTagName("thead");
+        assertNotNull(headers);
+        assertEquals(1, headers.size());
+        List trs = ((HtmlElement) headers.get(0))
+                .getHtmlElementsByTagName("tr");
+        assertTrue(trs.size() > 0);
+        HtmlElement tr = (HtmlElement) trs.get(0);
+        assertNotNull(tr);
+        classAttr = tr.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-table-header rich-table-header"));
+
+        List tds = tr.getHtmlElementsByTagName("td");
+        assertTrue(tds.size() > 0);
+        HtmlElement td = (HtmlElement) tds.get(0);
+        assertNotNull(td);
+        classAttr = td.getAttributeValue("class");
+        assertTrue(classAttr
+                .contains("dr-table-headercell rich-table-headercell"));        
+
+        List footers = table.getHtmlElementsByTagName("tfoot");
+        assertNotNull(footers);
+        assertEquals(1, footers.size());
+        trs = ((HtmlElement) footers.get(0)).getHtmlElementsByTagName("tr");
+        assertTrue(trs.size() > 0);
+        tr = (HtmlElement) trs.get(0);
+        assertNotNull(tr);
+        classAttr = tr.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-table-footer rich-table-footer"));
+
+        tds = tr.getHtmlElementsByTagName("td");
+        assertTrue(tds.size() > 0);
+        td = (HtmlElement) tds.get(0);
+        assertNotNull(td);
+        classAttr = td.getAttributeValue("class");
+        assertTrue(classAttr
+                .contains("dr-table-footercell rich-table-footercell"));
+        
+        List bodies = table.getHtmlElementsByTagName("tbody");        
+        assertEquals(1, bodies.size());
+        trs = ((HtmlElement) bodies.get(0)).getHtmlElementsByTagName("tr");
+        assertTrue(trs.size() > 0);
+        tr = (HtmlElement) trs.get(0);
+        assertNotNull(tr);
+        classAttr = tr.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-table-row rich-table-row"));
+        assertTrue(classAttr.contains("row1"));
+
+        tds = tr.getHtmlElementsByTagName("td");
+        assertTrue(tds.size() > 0);
+        td = (HtmlElement) tds.get(0);
+        assertNotNull(td);
+        classAttr = td.getAttributeValue("class");
+        assertTrue(classAttr.contains("dr-table-cell rich-table-cell"));
+        assertTrue(classAttr.contains("A"));        
+    }
+    
+    /**
+     * Test UIDataGrid component class.
+     * 
+     * @throws Exception
+     */
+    public void testUIDataGrid() throws Exception {
+        
+        dataGrid.setColumns(1);
+        
+        dataGrid.setElements(5);
+        assertEquals(5, dataGrid.getElements());        
+        
+        HtmlPage page = renderView();
+        assertNotNull(page);
+        //System.out.println(page.asXml());
+
+        HtmlElement table = page.getHtmlElementById(dataGrid
+                .getClientId(facesContext));
+        assertNotNull(table);
+        List bodies = table.getHtmlElementsByTagName("tbody");        
+        assertEquals(1, bodies.size());
+        List trs = ((HtmlElement) bodies.get(0)).getHtmlElementsByTagName("tr");
+        assertEquals(5, trs.size());
+    }
+    
+}

Deleted: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java	2007-04-13 14:33:24 UTC (rev 406)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java	2007-04-13 14:37:52 UTC (rev 407)
@@ -1,234 +0,0 @@
-/**
- * License Agreement.
- *
- *  JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007  Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
- */
-
-package org.richfaces.component;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-import javax.faces.component.html.HtmlOutputText;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.richfaces.component.html.HtmlColumnGroup;
-import org.richfaces.component.html.HtmlColumn;
-
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
-/**
- * Unit test for simple Component.
- */
-public class DataTableComponentTest extends AbstractAjax4JsfTestCase {
-
-    private UIDataTable dataTable;
-    private UIDataGrid dataGrid;
-
-    /**
-     * Create the test case
-     * 
-     * @param testName
-     *            name of the test case
-     */
-    public DataTableComponentTest(String testName) {
-        super(testName);
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
-     */
-    public void setUp() throws Exception {
-        super.setUp();
-
-        dataTable = (UIDataTable) application
-                .createComponent("org.richfaces.DataTable");
-        dataTable.setId("dataTable");
-        List value = new ArrayList();
-        value.add("First");
-        value.add("Second");
-        dataTable.setValue(value);
-        facesContext.getViewRoot().getChildren().add(dataTable);
-
-        dataGrid = (UIDataGrid) application
-                .createComponent("org.richfaces.DataGrid");
-        dataGrid.setId("dataGrid");
-        facesContext.getViewRoot().getChildren().add(dataGrid);
-
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
-     */
-    public void tearDown() throws Exception {
-        super.tearDown();
-        dataTable = null;
-    }
-
-    /**
-     * Test component rendering
-     * 
-     * @throws Exception
-     */
-    public void testRenderDataTable() throws Exception {
-
-        HtmlColumnGroup header = (HtmlColumnGroup) application
-                .createComponent("org.richfaces.ColumnGroup");
-        header.setColumnClasses("cola, colb");
-        dataTable.getFacets().put("header", header);
-
-        UIComponent caption = createComponent(HtmlOutputText.COMPONENT_TYPE,
-                HtmlOutputText.class.getName(), null, null, null);
-        dataTable.getFacets().put("caption", caption);
-        UIComponent footer = createComponent(HtmlOutputText.COMPONENT_TYPE,
-                HtmlOutputText.class.getName(), null, null, null);
-        dataTable.getFacets().put("footer", footer);
-
-        HtmlColumn column1 = (HtmlColumn) application
-                .createComponent("org.richfaces.Column");
-        dataTable.getChildren().add(column1);
-        HtmlOutputText text = (HtmlOutputText) createComponent(
-                HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
-                null, null, null);
-        text.setValue("Column");
-        column1.getChildren().add(text);
-        
-        HtmlPage page = renderView();
-        assertNotNull(page);
-        System.out.println(page.asXml());
-
-        HtmlElement table = page.getHtmlElementById(dataTable
-                .getClientId(facesContext));
-        assertNotNull(table);
-        assertEquals("table", table.getNodeName());
-
-        String classAttr = table.getAttributeValue("class");
-        assertTrue(classAttr.contains("dr-table rich-table"));
-
-        List captions = table.getHtmlElementsByTagName("caption");
-        assertNotNull(captions);
-        assertEquals(1, captions.size());
-
-        classAttr = ((HtmlElement) captions.get(0)).getAttributeValue("class");
-        assertTrue(classAttr.contains("dr-table-caption rich-table-caption"));
-
-        List headers = table.getHtmlElementsByTagName("thead");
-        assertNotNull(headers);
-        assertEquals(1, headers.size());
-        HtmlElement tr = (HtmlElement) ((HtmlElement) headers.get(0))
-                .getFirstChild();
-        assertNotNull(tr);
-        classAttr = tr.getAttributeValue("class");
-        assertTrue(classAttr.contains("dr-table-header rich-table-header"));
-
-        List footers = table.getHtmlElementsByTagName("tfoot");
-        assertNotNull(footers);
-        assertEquals(1, footers.size());
-        tr = (HtmlElement) ((HtmlElement) footers.get(0)).getFirstChild();
-        assertNotNull(tr);
-        classAttr = tr.getAttributeValue("class");
-        assertTrue(classAttr.contains("dr-table-footer rich-table-footer"));
-
-        List bodies = table.getHtmlElementsByTagName("tbody");
-        assertNotNull(bodies);
-        assertEquals(1, bodies.size());
-        tr = (HtmlElement) ((HtmlElement) bodies.get(0)).getFirstChild();
-        assertNotNull(tr);
-        classAttr = tr.getAttributeValue("class");
-        assertTrue(classAttr.contains("dr-table-firstrow rich-table-firstrow"));
-    }
-
-    /**
-     * Rigourous Test :-)
-     */
-    public void testRenderSubTable() throws Exception {
-        UISubTable subTable = (UISubTable) application
-                .createComponent("org.richfaces.SubTable");
-        subTable.setId("subTable");
-        List value = new ArrayList();
-        value.add("First");
-        subTable.setValue(value);
-        
-        dataTable.getChildren().add(subTable);
-
-        HtmlColumn column1 = (HtmlColumn) application
-                .createComponent("org.richfaces.Column");
-        subTable.getChildren().add(column1);
-        
-        HtmlPage page = renderView();
-        assertNotNull(page);
-        System.out.println(page.asXml());
-        
-        HtmlElement table = page.getHtmlElementById(dataTable
-                .getClientId(facesContext));
-        assertNotNull(table);
-        assertEquals("table", table.getNodeName());
-        
-        List bodies = table.getHtmlElementsByTagName("tbody");
-        assertNotNull(bodies);
-        assertEquals(1, bodies.size());
-        List trs = ((HtmlElement) bodies.get(0)).getHtmlElementsByTagName("tr");
-        assertNotNull(trs);
-
-        Iterator it = trs.iterator();
-        boolean found = false;
-        for( ; it.hasNext();) {
-            HtmlElement tr = (HtmlElement)it.next();
-            String classAttr = tr.getAttributeValue("class");
-            if (classAttr.contains("dr-subtable-")) {
-                found = true;
-                break;
-            }
-        }
-        assertTrue(found);
-        
-    }
-    
-    public void testRenderDataGrid() throws Exception {
-        dataGrid.setColumns(1);
-        List value = new ArrayList();
-        value.add("First");
-        dataGrid.setValue(value);
-        
-        UIComponent caption = createComponent(HtmlOutputText.COMPONENT_TYPE,
-                HtmlOutputText.class.getName(), null, null, null);
-        dataGrid.getChildren().add(caption);
-        
-        HtmlPage page = renderView();
-        assertNotNull(page);
-        System.out.println(page.asXml());
-
-        HtmlElement table = page.getHtmlElementById(dataGrid
-                .getClientId(facesContext));
-        assertNotNull(table);
-        assertEquals("table", table.getNodeName());
-
-        
-    }
-    
-}




More information about the richfaces-svn-commits mailing list