Author: konstantin.mishin
Date: 2009-02-05 09:53:01 -0500 (Thu, 05 Feb 2009)
New Revision: 12579
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataListBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataList.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataListAutoTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataListTest.java
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml
Log:
RF-5684
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataListBean.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataListBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataListBean.java 2009-02-05
14:53:01 UTC (rev 12579)
@@ -0,0 +1,143 @@
+package org.ajax4jsf.bean;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.event.ActionEvent;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+public class DataListBean implements Validator{
+
+ public class Row {
+
+ private String cell1;
+ private String cell2;
+ private String cell3;
+
+ public Row(String index) {
+ this.cell1 = index + "A";
+ this.cell2 = index + "B";
+ this.cell3 = index + "C";
+ }
+
+ public String getCell1() {
+ return cell1;
+ }
+
+ public void setCell1(String cell1) {
+ this.cell1 = cell1;
+ }
+
+ public String getCell2() {
+ return cell2;
+ }
+
+ public void setCell2(String cell2) {
+ this.cell2 = cell2;
+ }
+
+ public String getCell3() {
+ return cell3;
+ }
+
+ public void setCell3(String cell3) {
+ this.cell3 = cell3;
+ }
+ }
+
+ private List<Row> model;
+ private int rows;
+ private String trace;
+ private Set<Integer> ajaxKeys;
+
+ public DataListBean() {
+ init();
+ }
+
+ public void init() {
+ model = new ArrayList<Row>(10);
+ for (int i = 0; i < 10; i++) {
+ model.add(new Row(Integer.toString(i)));
+ }
+ rows = 0;
+ trace = "";
+ ajaxKeys = new HashSet<Integer>(10);
+ for (int i = 0; i < 10; i++) {
+ if (i != 2 && i != 6) {
+ ajaxKeys.add(i);
+ }
+ }
+ }
+
+ public void submit(ActionEvent event) {
+ trace = event.getComponent().getClientId(FacesContext.getCurrentInstance());
+ }
+
+ public void reRender(ActionEvent event) {
+ for (Row element : model) {
+ element.setCell2("XXX");
+ }
+ }
+
+ public void setModel(List<Row> model) {
+ this.model = model;
+ }
+
+ public List<Row> getModel() {
+ return model;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setTrace(String trace) {
+ this.trace = trace;
+ }
+
+ public String getTrace() {
+ return trace;
+ }
+
+ public void validate(FacesContext context, UIComponent component,
+ Object value) throws ValidatorException {
+ if ("fail".equals(value)) {
+ throw new ValidatorException(new FacesMessage("validation failure"));
+ }
+ }
+
+ public void setAjaxKeys(Set<Integer> ajaxKeys) {
+ this.ajaxKeys = ajaxKeys;
+ }
+
+ public Set<Integer> getAjaxKeys() {
+ return ajaxKeys;
+ }
+
+ public Converter getRowKeyConverter() {
+ return new Converter(){
+
+ public Object getAsObject(FacesContext context,
+ UIComponent component, String value) {
+ return new Integer(value.substring(2));
+ }
+
+ public String getAsString(FacesContext context,
+ UIComponent component, Object value) {
+ return "c_" + value.toString();
+ }
+
+ };
+ }
+}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml 2009-02-05
14:23:57 UTC (rev 12578)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml 2009-02-05
14:53:01 UTC (rev 12579)
@@ -174,6 +174,11 @@
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
+ <managed-bean-name>dataList</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.bean.DataListBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
<managed-bean-name>sliderBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.bean.InputNumberSliderBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataList.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataList.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataList.xhtml 2009-02-05
14:53:01 UTC (rev 12579)
@@ -0,0 +1,50 @@
+<!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:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition template="#{templateBean.template}">
+ <ui:define name="component">
+ <h:form id="attrForm">
+ <h:outputText value="rows" />
+ <h:inputText id="rows" value="#{dataList.rows}">
+ <a4j:support event="onchange" reRender="panelGroup"/>
+ </h:inputText>
+ </h:form>
+ <h:form id="mainForm">
+ <h:panelGroup id="panelGroup">
+ <rich:dataList id="dataList" value="#{dataList.model}"
var="rows"
+ rows="#{dataList.rows}" ajaxKeys="#{dataList.ajaxKeys}"
+ stateVar="stateVar" rowKeyVar="rowKeyVar"
+ componentState="#{componentState}"
+ rowKeyConverter="#{dataList.rowKeyConverter}">
+ <h:outputText id="rowKeyVar" value="#{rowKeyVar}
"></h:outputText>
+ <h:outputText id="first" value="#{stateVar.range.firstRow}
"></h:outputText>
+ <h:outputText id="rows" value="#{stateVar.range.rows}
"></h:outputText>
+ <h:outputText id="firstState"
value="#{componentState.range.firstRow} "></h:outputText>
+ <h:outputText id="rowsState" value="#{componentState.range.rows}
"></h:outputText>
+ <h:outputText value="#{rows.cell1}"></h:outputText>
+ <h:inputText id="inputText" value="#{rows.cell2}"
validator="#{dataList.validate}"></h:inputText>
+ <h:outputText value="#{rows.cell3}"></h:outputText>
+ <h:commandButton id="submit" value="submit"
actionListener="#{dataList.submit}"></h:commandButton>
+ <a4j:commandButton id="ajaxSubmit" value="ajaxSubmit"
actionListener="#{dataList.submit}"></a4j:commandButton>
+ <a4j:commandButton id="ajaxSingleSubmit"
value="ajaxSingleSubmit" actionListener="#{dataList.submit}"
ajaxSingle="true"></a4j:commandButton>
+ </rich:dataList>
+ <a4j:commandButton id="reRender" value="reRender"
reRender="inputText"
actionListener="#{dataList.reRender}"></a4j:commandButton>
+ </h:panelGroup>
+ </h:form>
+ <a4j:outputPanel ajaxRendered="true">
+ <h:outputText id="outputText"
value="#{dataList.trace}"></h:outputText>
+ <h:dataTable id="dataTable" value="#{dataList.model}"
var="row" rows="#{dataList.rows}">
+ <h:column>
+ <h:outputText value="#{row.cell2}"></h:outputText>
+ </h:column>
+ </h:dataTable>
+ </a4j:outputPanel>
+ <rich:messages></rich:messages>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataListAutoTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataListAutoTest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataList/dataListAutoTest.xhtml 2009-02-05
14:53:01 UTC (rev 12579)
@@ -0,0 +1,31 @@
+<!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:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition template="#{templateBean.autoTestTemplate}">
+ <ui:define name="component">
+ <rich:dataList id="componentId" value="#{dataGrid.model}"
var="row"
+ rendered="#{autoTestBean.rendered}"
+ style="width: 100%; color: yellow"
+ styleClass="noname"
+ onclick="EventQueue.fire('onclick')"
+ onmousedown="EventQueue.fire('onmousedown')"
+ onmousemove="EventQueue.fire('onmousemove')"
+ onmouseup="EventQueue.fire('onmouseup')"
+ onmouseout="EventQueue.fire('onmouseout')"
+ onmouseover="EventQueue.fire('onmouseover')"
+ onkeydown="EventQueue.fire('onkeydown')"
+ onkeypress="EventQueue.fire('onkeypress')"
+ onkeyup="EventQueue.fire('onkeyup')"
+ >
+ <h:panelGroup>
+ <h:inputText id="inputText"
value="#{row.cell2}"></h:inputText>
+ </h:panelGroup>
+ </rich:dataList>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataListTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataListTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataListTest.java 2009-02-05
14:53:01 UTC (rev 12579)
@@ -0,0 +1,164 @@
+package org.richfaces.testng;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ajax4jsf.template.Template;
+import org.richfaces.AutoTester;
+import org.richfaces.SeleniumTestBase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class DataListTest extends SeleniumTestBase {
+
+ private String rows;
+
+ private String dataList;
+
+ private String reRender;
+
+ private String outputText;
+
+ private String dataTable;
+
+ private void init(Template template) {
+ renderPage(null, template, "#{dataList.init}");
+ String attrForm = getParentId() + "attrForm";
+ rows = attrForm + ":rows";
+ String mainForm = getParentId() + "mainForm";
+ dataList = mainForm + ":dataList";
+ reRender = mainForm + ":reRender";
+ outputText = getParentId() + "outputText";
+ dataTable = getParentId() + "dataTable";
+ }
+
+ /**
+ * items from collection defined as value attribute are output to the client;
+ * number of items is limited using elements attribute and not
+ */
+ @Test
+ public void testStructure(Template template) {
+ init(template);
+ chekStructure();
+ selenium.type(rows, "3");
+ waitForAjaxCompletion();
+ Assert.assertEquals(selenium.getXpathCount("id('"+ dataList +
"')/li"), 3);
+ chekStructure();
+ }
+
+ /**
+ * nested input and command components work correctly
+ * for the cases of validation failure or not
+ */
+ @Test
+ public void testComponentsProcessingWithValidation(Template template) {
+ init(template);
+ String liLocator = "xpath=id('"+ dataList + "')/li[";
+ String inputLocator = liLocator + "6]/input[";
+ Assert.assertEquals(selenium.getText(outputText), "");
+ selenium.click(inputLocator + "2]");
+ waitForPageToLoad();
+ Assert.assertTrue(selenium.getText(outputText).endsWith("5:submit"));
+ selenium.click(inputLocator + "3]");
+ waitForAjaxCompletion();
+ Assert.assertTrue(selenium.getText(outputText).endsWith("5:ajaxSubmit"));
+ selenium.click(inputLocator + "4]");
+ waitForAjaxCompletion();
+ Assert.assertTrue(selenium.getText(outputText).endsWith("5:ajaxSingleSubmit"));
+ selenium.type(inputLocator + "1]", "abc5");
+ selenium.click(inputLocator + "3]");
+ waitForAjaxCompletion();
+ chekStructure();
+ selenium.type(inputLocator + "1]", "fail");
+ selenium.type(liLocator + "3]/input[1]", "fail");
+ selenium.click(inputLocator + "3]");
+ waitForAjaxCompletion();
+ chekStructure(3, 6);
+ }
+
+ /**
+ * rows defined by ajaxKeys attribute are re-rendered correctly
+ */
+ @Test
+ public void testAjaxKeys(Template template) {
+ init(template);
+ chekStructure();
+ clickAjaxCommandAndWait(reRender);
+ chekStructure(3, 7);
+ }
+
+ /**
+ * components using rowKeyVar and stateVar variables are correctly output to the
client
+ */
+ @Test
+ public void testVars(Template template) {
+ init(template);
+ Assert.assertEquals(selenium.getText(dataList + ":c_2:first"), "0",
"Attribute 'stateVar' works wrong.");
+ Assert.assertEquals(selenium.getText(dataList + ":c_2:rows"), "0",
"Attribute 'stateVar' works wrong.");
+ int rows = selenium.getXpathCount("id('"+ dataList +
"')/tbody/tr").intValue();
+ for (int i = 0; i < rows; i++) {
+ Assert.assertEquals(selenium.getText(dataList + ":c_" + i +
":rowKeyVar"), Integer.toString(i));
+ }
+ }
+
+ /**
+ * componentState attribute stores nested components state across requests
+ */
+ @Test
+ public void testComponentState(Template template) {
+ init(template);
+ Assert.assertEquals(selenium.getText(dataList + ":c_2:firstState"),
"0", "Attribute 'componentState' works wrong.");
+ Assert.assertEquals(selenium.getText(dataList + ":c_2:rowsState"),
"0", "Attribute 'componentState' works wrong.");
+ }
+
+ /**
+ * component with rendered = false is not present on the page,
+ * style and classes, standard HTML attributes are output to client
+ */
+ @Test
+ public void testStandardAttributes(Template template) {
+ AutoTester autoTester = getAutoTester(this);
+ autoTester.renderPage(template, "#{dataGrid.init}");
+ autoTester.testRendered();
+ Map<String, String> styleAttributes = new HashMap<String, String>();
+ styleAttributes.put("width", "100%");
+ styleAttributes.put("color", "yellow");
+ autoTester.testStyleAndClasses(new String[]{"noname"}, styleAttributes);
+ autoTester.testHTMLEvents();
+ }
+
+ /**
+ * rowKeyConverter outputs correct client ids
+ */
+ @Test
+ public void testRowKeyConverter(Template template) {
+ init(template);
+ Assert.assertTrue(selenium.getAttribute("xpath=id('"+ dataList +
"')/li[3]@id").endsWith(":c_2"), "Attribute
'rowKeyConverter' works wrong.");
+ }
+
+ private void chekStructure(int ... notEqualRows) {
+ String dataTableRowLocator = "id('"+ dataTable + "')/li";
+ int count = selenium.getXpathCount(dataTableRowLocator).intValue();
+ for (int i = 1; i <= count; i++) {
+ if (Arrays.binarySearch(notEqualRows, i) < 0) {
+ Assert.assertEquals(selenium.getValue("xpath=id('"+ dataList +
"')/li[" + i + "]/input"),
+ selenium.getText("xpath=" + dataTableRowLocator + "[" + i +
"]"));
+ } else {
+ Assert.assertFalse(selenium.
+ getValue("xpath=id('"+ dataList + "')/li[" + i +
"]/input").
+ equals(selenium.getText("xpath=" + dataTableRowLocator + "[" +
i + "]")));
+ }
+ }
+ }
+
+ @Override
+ public String getTestUrl() {
+ return "pages/dataList/dataList.xhtml";
+ }
+
+ @Override
+ public String getAutoTestUrl() {
+ return "pages/dataList/dataListAutoTest.xhtml";
+ }
+}