Author: alevkovsky
Date: 2008-06-25 11:46:05 -0400 (Wed, 25 Jun 2008)
New Revision: 9226
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatItemTestBean.java
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatTestBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxRepeat/
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxRepeat/ajaxRepeatTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxRepeatTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
Log:
Add a4j:repeat selenium test
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatItemTestBean.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatItemTestBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatItemTestBean.java 2008-06-25
15:46:05 UTC (rev 9226)
@@ -0,0 +1,106 @@
+/*
+ * A4JRepeatItemTestBean.java Date created: 24.06.2008
+ * Last modified by: $Author$
+ * $Revision$ $Date$
+ */
+
+package org.ajax4jsf.bean;
+
+/**
+ * TODO Class description goes here.
+ * @author Alexandr Levkovsky
+ *
+ */
+public class A4JRepeatItemTestBean {
+
+ private Integer number;
+
+ private Integer output;
+
+ private Integer input;
+
+ private Integer rerenderedChangeCounter;
+
+ private Integer notRerenderedChangeCounter;
+
+ A4JRepeatItemTestBean(Integer index) {
+ this.number = index;
+ this.input = index;
+ this.output = index;
+ this.rerenderedChangeCounter = 0;
+ this.notRerenderedChangeCounter = 0;
+ }
+
+ /**
+ * @return the number
+ */
+ public Integer getNumber() {
+ return number;
+ }
+
+ /**
+ * @param number the number to set
+ */
+ public void setNumber(Integer number) {
+ this.number = number;
+ }
+
+ /**
+ * @return the output
+ */
+ public Integer getOutput() {
+ return output;
+ }
+
+ /**
+ * @param output the output to set
+ */
+ public void setOutput(Integer output) {
+ this.output = output;
+ }
+
+ /**
+ * @return the input
+ */
+ public Integer getInput() {
+ return input;
+ }
+
+ /**
+ * @param input the input to set
+ */
+ public void setInput(Integer input) {
+ this.input = input;
+ }
+
+ /**
+ * @return the rerenderedChangeCounter
+ */
+ public Integer getRerenderedChangeCounter() {
+ return rerenderedChangeCounter;
+ }
+
+ /**
+ * @param rerenderedChangeCounter the rerenderedChangeCounter to set
+ */
+ public void setRerenderedChangeCounter(Integer rerenderedChangeCounter) {
+ this.rerenderedChangeCounter = rerenderedChangeCounter;
+ }
+
+ /**
+ * @return the notRerenderedChangeCounter
+ */
+ public Integer getNotRerenderedChangeCounter() {
+ return notRerenderedChangeCounter;
+ }
+
+ /**
+ * @param notRerenderedChangeCounter the notRerenderedChangeCounter to set
+ */
+ public void setNotRerenderedChangeCounter(Integer notRerenderedChangeCounter) {
+ this.notRerenderedChangeCounter = notRerenderedChangeCounter;
+ }
+
+
+
+}
Property changes on:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatItemTestBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatTestBean.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatTestBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatTestBean.java 2008-06-25
15:46:05 UTC (rev 9226)
@@ -0,0 +1,186 @@
+/*
+ * A4JRepeatTestBean.java Date created: 19.06.2008
+ * Last modified by: $Author$
+ * $Revision$ $Date$
+ */
+
+package org.ajax4jsf.bean;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.ajax4jsf.component.UIRepeat;
+
+/**
+ * a4j:repeat component test bean
+ * @author Alexandr Levkovsky
+ *
+ */
+public class A4JRepeatTestBean {
+
+ private Integer first = 0;
+
+ private Integer rows = 5;
+
+ private Integer visible = 0;
+
+ private List<A4JRepeatItemTestBean> items;
+
+ private UIRepeat repeater;
+
+ private Boolean rendered = true;
+
+ private Set<Integer> keys = null;
+
+ /**
+ * @return the first
+ */
+ public Integer getFirst() {
+ return first;
+ }
+
+ /**
+ * @param first the first to set
+ */
+ public void setFirst(Integer first) {
+ this.first = first;
+ }
+
+ /**
+ * @return the rows
+ */
+ public Integer getRows() {
+ return rows;
+ }
+
+ /**
+ * @param rows the rows to set
+ */
+ public void setRows(Integer rows) {
+ this.rows = rows;
+ }
+
+ /**
+ * @return the items
+ */
+ public List<A4JRepeatItemTestBean> getItems() {
+ if (items == null) {
+ generateItems(getRows());
+ }
+ return items;
+ }
+
+ /**
+ * @param items the items to set
+ */
+ public void setItems(List<A4JRepeatItemTestBean> items) {
+ this.items = items;
+ }
+
+ /**
+ * @return the repeater
+ */
+ public UIRepeat getRepeater() {
+ return repeater;
+ }
+
+ /**
+ * @param repeater the repeater to set
+ */
+ public void setRepeater(UIRepeat repeater) {
+ this.repeater = repeater;
+ }
+
+ /**
+ * @return the rendered
+ */
+ public Boolean getRendered() {
+ return rendered;
+ }
+
+ /**
+ * @param rendered the rendered to set
+ */
+ public void setRendered(Boolean rendered) {
+ this.rendered = rendered;
+ }
+
+
+
+ /**
+ * @return the visible
+ */
+ public Integer getVisible() {
+ return visible;
+ }
+
+ /**
+ * @param visible the visible to set
+ */
+ public void setVisible(Integer visible) {
+ this.visible = visible;
+ }
+
+ private void generateItems(Integer rows) {
+ items = new ArrayList<A4JRepeatItemTestBean>(rows);
+ for (int i = 0; i < rows; i++) {
+ A4JRepeatItemTestBean item = new A4JRepeatItemTestBean(i);
+ items.add(item);
+
+ }
+ }
+
+ public String init(){
+ generateItems(getRows());
+ return null;
+ }
+
+ public String reset(){
+ setRows(5);
+ setRendered(true);
+ setVisible(0);
+ setFirst(0);
+ generateItems(getRows());
+ return null;
+ }
+
+ /**
+ * @return the keys
+ */
+ public Set<Integer> getKeys() {
+ return keys;
+ }
+
+ /**
+ * @param keys the keys to set
+ */
+ public void setKeys(Set<Integer> keys) {
+ this.keys = keys;
+ }
+
+ public String change() {
+ Set<Integer> keys = new HashSet<Integer>();
+ int rowKey = getRepeater().getRowIndex();
+ keys.add(rowKey);
+ setKeys(keys);
+ A4JRepeatItemTestBean item = items.get(rowKey);
+ item.setNotRerenderedChangeCounter(item.getNotRerenderedChangeCounter() + 1);
+ item.setRerenderedChangeCounter(item.getRerenderedChangeCounter() + 1);
+ //priceRef.processValidators(FacesContext.getCurrentInstance());
+ //priceRef.processUpdates(FacesContext.getCurrentInstance());
+ return null;
+ }
+
+ public String change2() {
+ int rowKey = getRepeater().getRowIndex();
+ A4JRepeatItemTestBean item = items.get(rowKey);
+ item.setNotRerenderedChangeCounter(item.getNotRerenderedChangeCounter() + 1);
+ item.setRerenderedChangeCounter(item.getRerenderedChangeCounter() + 1);
+ //priceRef.processValidators(FacesContext.getCurrentInstance());
+ //priceRef.processUpdates(FacesContext.getCurrentInstance());
+ return null;
+ }
+
+}
Property changes on:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JRepeatTestBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-06-25
15:44:37 UTC (rev 9225)
+++
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-06-25
15:46:05 UTC (rev 9226)
@@ -131,6 +131,11 @@
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
+ <managed-bean-name>a4jRepeatBean</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.bean.A4JRepeatTestBean</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
<managed-bean-name>calendarBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.bean.CalendarTestBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxRepeat/ajaxRepeatTest.xhtml
===================================================================
(Binary files differ)
Property changes on:
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxRepeat/ajaxRepeatTest.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-06-25
15:44:37 UTC (rev 9225)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java 2008-06-25
15:46:05 UTC (rev 9226)
@@ -467,6 +467,16 @@
/**
* Asserts DOM node is present
+ *
+ * @param id -
+ * DOM element id
+ */
+ public void AssertPresent(String id) {
+ Assert.assertTrue(isPresentById(id));
+ }
+
+ /**
+ * Asserts DOM node is present
* @param id - DOM element id
*/
public void AssertRendered(String id) {
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxRepeatTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxRepeatTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxRepeatTest.java 2008-06-25
15:46:05 UTC (rev 9226)
@@ -0,0 +1,194 @@
+/*
+ * AjaxRepeatTest.java Date created: 19.06.2008
+ * Last modified by: $Author$
+ * $Revision$ $Date$
+ */
+
+package org.richfaces.testng;
+
+import org.ajax4jsf.template.Template;
+import org.richfaces.SeleniumTestBase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * a4j:repeat component selenium test
+ * @author Alexandr Levkovsky
+ *
+ */
+public class AjaxRepeatTest extends SeleniumTestBase {
+
+ private final static Integer DEFAULT_ROWS_COUNT = 5;
+
+ private final static String FORM1_ID = "form1:";
+
+ private final static String FORM2_ID = "form2:";
+
+ private final static String FIRST_INPUT_ID = "first_input";
+
+ private final static String ROWS_INPUT_ID = "rows_input";
+
+ private final static String RESET_BUTTON_ID = "reset";
+
+ private final static String ROWS_COUNT_INPUT_ID = "rows_count_input";
+
+ private final static String TABLE_ID = "repeat_table";
+
+ private final static String REPEAT_ID = "repeat";
+
+ private final static String INPUT_ID = "input";
+
+ private final static String OUTPUT_ID = "output";
+
+ private final static String APPLY_BUTTON_ID = "apply";
+
+ private final static String RENDERED_CHECKBOX_ID = "rendered_checkbox";
+
+ private final static String LINK_ID = "link";
+
+ private final static String RERENDERED_COUNTER_ID =
"rerendered_change_counter";
+
+ private final static String NOT_RERENDERED_COUNTER_ID =
"not_rerendered_change_counter";
+
+ @Override
+ public String getTestUrl() {
+ return "pages/ajaxRepeat/ajaxRepeatTest.xhtml";
+ }
+
+ @Test(dataProvider = "templates")
+ public void testRenderedAttribute(Template template) throws Exception {
+ renderPage(template);
+ writeStatus("Testing rendered attribute...");
+ clickReset();
+ AssertRendered(TABLE_ID);
+ // repeat has rendered=true and should present on page as table with default 5 rows
+ assertRowsCount(5, TABLE_ID);
+
+ writeStatus("change rendered attribute to false");
+ // change rendered attribute to false
+ String checkboxId = getParentId() + FORM1_ID + RENDERED_CHECKBOX_ID;
+ selenium.click(checkboxId);
+ writeStatus("Click apply");
+ clickApply();
+
+ // repeat now has rendered=false and should not present on page as table with default 0
rows
+ assertRowsCount(0, TABLE_ID);
+ }
+
+ @Test(dataProvider = "templates")
+ public void testFirstAttribute(Template template) throws Exception {
+ renderPage(template);
+ writeStatus("Testing first attribute...");
+ clickReset();
+ AssertRendered(TABLE_ID);
+ // repeat has rendered=true and should present on page as table with default 5 rows
+ assertRowsCount(5, TABLE_ID);
+ // first row default value 0
+ String fullInput0Id = getParentId() + FORM2_ID + REPEAT_ID + ":" + 0 +
":" + OUTPUT_ID;
+ String fullInput1Id = getParentId() + FORM2_ID + REPEAT_ID + ":" + 1 +
":" + OUTPUT_ID;
+ AssertPresent(fullInput0Id);
+ AssertPresent(fullInput1Id);
+ writeStatus("change first attribute to 1");
+
+ String inputId = getParentId() + FORM1_ID + FIRST_INPUT_ID;
+ type(inputId, "1");
+ writeStatus("Click apply");
+ clickApply();
+
+ // now first row value should be 1
+ AssertNotPresent(fullInput0Id);
+ AssertPresent(fullInput1Id);
+ }
+
+ @Test(dataProvider = "templates")
+ public void testRowsAttribute(Template template) throws Exception {
+ renderPage(template);
+ writeStatus("Testing rows attribute...");
+ clickReset();
+ AssertRendered(TABLE_ID);
+ // repeat has rows=0 and table with all default 5 rows should present on page
+ assertRowsCount(5, TABLE_ID);
+
+ writeStatus("change rendered attribute to false");
+ // change rows attribute to 3
+ String inputId = getParentId() + FORM1_ID + ROWS_INPUT_ID;
+ type(inputId, "3");
+ writeStatus("Click apply");
+ clickApply();
+
+ // repeat now has rendered=false and should not present on page as table with default 0
rows
+ assertRowsCount(3, TABLE_ID);
+ // last row should have value 2
+ assertInputValue(2, INPUT_ID, "2");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testRowKeyVarAttribute(Template template) throws Exception {
+ renderPage(template);
+ writeStatus("Testing rowKeyVar attribute...");
+ clickReset();
+ AssertRendered(TABLE_ID);
+ String inputId = getParentId() + FORM1_ID + ROWS_COUNT_INPUT_ID;
+ Integer rowsCount = new Integer(getValueById(inputId));
+ // repeat has rows=0 and table with all default 5 rows should present on
+ // page
+ assertRowsCount(rowsCount, TABLE_ID);
+
+ // output text has value="#{rowKey % 2 == 0 ? '0' : '1'}"
+ for (int i = 0; i < rowsCount; i++) {
+ assertOutputText(i, OUTPUT_ID, i % 2 == 0 ? "0" : "1");
+ }
+ }
+
+ @Test(dataProvider = "templates")
+ public void testAjaxKeysAttribute(Template template) throws Exception {
+ renderPage(template);
+ writeStatus("Testing ajaxKeys attribute...");
+ clickReset();
+ AssertRendered(TABLE_ID);
+ assertRowsCount(DEFAULT_ROWS_COUNT, TABLE_ID);
+
+ for (int i = 0; i < DEFAULT_ROWS_COUNT; i++) {
+ String LinkId = getFullTableElementId(i, LINK_ID);
+ assertOutputText(i, RERENDERED_COUNTER_ID, "0");
+ assertOutputText(i, NOT_RERENDERED_COUNTER_ID, "0");
+ writeStatus("click link...");
+ clickAjaxCommandAndWait(LinkId);
+ assertOutputText(i, RERENDERED_COUNTER_ID, "1");
+ assertOutputText(i, NOT_RERENDERED_COUNTER_ID, "0");
+ }
+ }
+
+ private void clickReset() {
+ String buttonId = getParentId() + FORM2_ID + RESET_BUTTON_ID;
+ writeStatus("Click reset button");
+ clickCommandAndWait(buttonId);
+ }
+
+ private void clickApply() {
+ String buttonId = getParentId() + FORM1_ID + APPLY_BUTTON_ID;
+ clickCommandAndWait(buttonId);
+ }
+
+ private void assertRowsCount(int i, String tableId) {
+ int count = selenium.getXpathCount("//table[@id='" + tableId +
"']/tbody/tr").intValue();
+ Assert.assertEquals(count, i);
+ }
+
+ private void assertInputValue(int row, String inputId, String value) {
+ String fullInputId = getFullTableElementId(row, inputId);
+ String elementValue = getValueById(fullInputId);
+ Assert.assertEquals(elementValue, value);
+ }
+
+ private void assertOutputText(int row, String outputId, String value) {
+ String fullInputId = getFullTableElementId(row, outputId);
+ String elementValue = getTextById(fullInputId);
+ Assert.assertEquals(elementValue, value);
+ }
+
+ private String getFullTableElementId(int row, String elementId) {
+ return getParentId() + FORM2_ID + REPEAT_ID + ":" + row + ":" +
elementId;
+ }
+
+}
Property changes on:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxRepeatTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Show replies by date