[richfaces-svn-commits] JBoss Rich Faces SVN: r365 - trunk/richfaces/dataTable/src/test/java/org/richfaces/component.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Wed Apr 11 10:48:18 EDT 2007
Author: a.izobov
Date: 2007-04-11 10:48:17 -0400 (Wed, 11 Apr 2007)
New Revision: 365
Added:
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
Removed:
trunk/richfaces/dataTable/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
test development
Added: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java (rev 0)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/DataTableComponentTest.java 2007-04-11 14:48:17 UTC (rev 365)
@@ -0,0 +1,234 @@
+/**
+ * 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());
+
+
+ }
+
+}
Deleted: trunk/richfaces/dataTable/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/richfaces/dataTable/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-11 14:16:05 UTC (rev 364)
+++ trunk/richfaces/dataTable/src/test/java/org/richfaces/component/JSFComponentTest.java 2007-04-11 14:48:17 UTC (rev 365)
@@ -1,53 +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 junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import javax.faces.component.UIComponent;
-
-/**
- * Unit test for simple Component.
- */
-public class JSFComponentTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public JSFComponentTest( String testName )
- {
- super( testName );
- }
-
-
- /**
- * Rigourous Test :-)
- */
- public void testComponent()
- {
- assertTrue( true );
- }
-}
More information about the richfaces-svn-commits
mailing list