Author: konstantin.mishin
Date: 2010-07-12 14:26:58 -0400 (Mon, 12 Jul 2010)
New Revision: 17981
Added:
root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/DataGridRendererTest.java
root/ui/iteration/trunk/tables/ui/src/test/resources/dataGridTest.xhtml
Log:
RF-8844
Added:
root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/DataGridRendererTest.java
===================================================================
---
root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/DataGridRendererTest.java
(rev 0)
+++
root/ui/iteration/trunk/tables/ui/src/test/java/org/richfaces/renderkit/DataGridRendererTest.java 2010-07-12
18:26:58 UTC (rev 17981)
@@ -0,0 +1,118 @@
+package org.richfaces.renderkit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+import javax.faces.view.ViewDeclarationLanguage;
+
+import org.jboss.test.faces.FacesEnvironment.FacesRequest;
+import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.component.UIDataGrid;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class DataGridRendererTest {
+
+ private HtmlUnitEnvironment environment;
+
+ @Before
+ public void setUp() {
+ environment = new HtmlUnitEnvironment();
+ environment.withWebRoot(new File("src/test/resources"));
+ environment.start();
+ }
+
+ @After
+ public void tearDown() {
+ environment.release();
+ environment = null;
+ }
+
+ private FacesRequest startFacesRequest() throws IOException {
+ FacesRequest facesRequest =
environment.createFacesRequest("http://localhost/dataGridTest.jsf");
+ facesRequest.withViewId("/dataGridTest.jsf");
+ facesRequest.start();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ViewHandler vh = facesContext.getApplication().getViewHandler();
+ ViewDeclarationLanguage vdl = vh.getViewDeclarationLanguage(facesContext,
facesContext.getViewRoot()
+ .getViewId());
+ vdl.buildView(facesContext, facesContext.getViewRoot());
+ return facesRequest;
+ }
+
+ @Test
+ public final void testGetComponentClass() throws IOException {
+ FacesRequest facesRequest = startFacesRequest();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIDataGrid component = (UIDataGrid)
facesContext.getViewRoot().findComponent("dataGrid");
+ DataGridRenderer renderer = (DataGridRenderer) FacesContext.getCurrentInstance()
+ .getRenderKit().getRenderer(component.getFamily(),
component.getRendererType());
+ assertEquals(UIDataGrid.class, renderer.getComponentClass());
+ facesRequest.release();
+ }
+
+ @Test
+ public final void testDoEncodeChildren() throws IOException {
+ HtmlPage page = environment.getPage("/dataGridTest.jsf");
+ HtmlElement dataGrid = page.getElementById("dataGrid2");
+ assertEquals("rf-dg", dataGrid.getAttribute("class"));
+ assertEquals("noDataFacet", ((HtmlElement) dataGrid
+
.getFirstByXPath("tbody/tr[@class='rf-dg-nd']/td[@class='rf-dg-nd-c']/*[@id='dataGrid2:noDataFacet']"))
+ .getTextContent());
+ }
+
+ @Test
+ public final void testEncodeRow() throws IOException {
+ HtmlPage page = environment.getPage("/dataGridTest.jsf");
+ HtmlElement dataGrid = page.getElementById("dataGrid");
+ assertEquals("value", ((HtmlElement) dataGrid
+
.getFirstByXPath("tbody/tr[@class='rf-dg-r']/td[@class='rf-dg-c']/*[@id='dataGrid:0:outputText']"))
+ .getTextContent());
+ }
+
+ @Test
+ public final void testEncodeHeader() throws IOException {
+ HtmlPage page = environment.getPage("/dataGridTest.jsf");
+ HtmlElement dataGrid = page.getElementById("dataGrid");
+ HtmlElement th = dataGrid
+
.getFirstByXPath("thead[@class='rf-dg-thead']/tr[@class='rf-dg-h']/th[@class='rf-dg-h-c']");
+ assertEquals("1", th.getAttribute("colspan"));
+ assertEquals("headerFacet",
th.getElementById("dataGrid:headerFacet").getTextContent());
+ }
+
+ @Test
+ public final void testEncodeFooter() throws IOException {
+ HtmlPage page = environment.getPage("/dataGridTest.jsf");
+ HtmlElement dataGrid = page.getElementById("dataGrid");
+ HtmlElement td = dataGrid
+
.getFirstByXPath("tfoot[@class='rf-dg-tfoot']/tr[@class='rf-dg-f']/td[@class='rf-dg-f-c']");
+ assertEquals("1", td.getAttribute("colspan"));
+ assertEquals("footerFacet",
td.getElementById("dataGrid:footerFacet").getTextContent());
+ }
+
+ @Test
+ public final void testEncodeCaption() throws IOException {
+ HtmlPage page = environment.getPage("/dataGridTest.jsf");
+ HtmlElement dataGrid = page.getElementById("dataGrid");
+ assertEquals("captionFacet", ((HtmlElement) dataGrid
+
.getFirstByXPath("caption[@class='rf-dg-cap']//*[@id='dataGrid:captionFacet']")).getTextContent());
+ }
+
+ @Test
+ public final void testEncodeTBody() throws IOException {
+ HtmlPage page = environment.getPage("/dataGridTest.jsf");
+ HtmlElement dataGrid = page.getElementById("dataGrid2");
+ assertEquals("rf-dg-body", ((HtmlElement)
dataGrid.getFirstByXPath("tbody[@id='dataGrid2:dgb']"))
+ .getAttribute("class"));
+ }
+
+
+}
Added: root/ui/iteration/trunk/tables/ui/src/test/resources/dataGridTest.xhtml
===================================================================
--- root/ui/iteration/trunk/tables/ui/src/test/resources/dataGridTest.xhtml
(rev 0)
+++ root/ui/iteration/trunk/tables/ui/src/test/resources/dataGridTest.xhtml 2010-07-12
18:26:58 UTC (rev 17981)
@@ -0,0 +1,59 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:rich="http://richfaces.org/rich">
+<!--
+JBoss, Home of Professional Open Source
+Copyright ${year}, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+
+This software 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 software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+-->
+ <h:head>
+ <title>Richfaces DataGrid Test</title>
+ </h:head>
+
+ <h:body>
+ <rich:dataGrid id="dataGrid" value="value" var="var"
>
+ <f:facet name="caption">
+ <h:outputText id="captionFacet" value="captionFacet"/>
+ </f:facet>
+ <f:facet name="header">
+ <h:outputText id="headerFacet" value="headerFacet"/>
+ </f:facet>
+ <f:facet name="noData">
+ <h:outputText id="noDataFacet" value="noDataFacet"/>
+ </f:facet>
+ <f:facet name="footer">
+ <h:outputText id="footerFacet" value="footerFacet"/>
+ </f:facet>
+ <h:outputText id="outputText" value="#{var}"/>
+ </rich:dataGrid>
+ <rich:dataGrid id="dataGrid2" >
+ <f:facet name="noData">
+ <h:outputText id="noDataFacet" value="noDataFacet"/>
+ </f:facet>
+ </rich:dataGrid>
+ </h:body>
+</html>