Author: ppitonak(a)redhat.com
Date: 2011-01-18 09:48:02 -0500 (Tue, 18 Jan 2011)
New Revision: 21055
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarAjax.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarClient.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarStatic.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichProgressBarBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/clientMode.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/static.xhtml
Log:
https://issues.jboss.org/browse/RFPL-864
* samples for rich:progressBar fixed
* added 34 tests for rich:progressBar
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichProgressBarBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichProgressBarBean.java 2011-01-18
13:01:51 UTC (rev 21054)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichProgressBarBean.java 2011-01-18
14:48:02 UTC (rev 21055)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -64,7 +64,7 @@
attributes.setAttribute("maxValue", 100);
attributes.setAttribute("minValue", 0);
- attributes.setAttribute("interval", 1000);
+ attributes.setAttribute("interval", 500);
attributes.setAttribute("rendered", true);
attributes.setAttribute("value", -1);
@@ -89,13 +89,13 @@
public Long getCurrentValue() {
if (Boolean.TRUE.equals(attributes.get("enabled").getValue())) {
- Long current = (new Date().getTime() - startTime) / 1000;
- if (current > 100) {
+ Long current = (new Date().getTime() - startTime) / 500;
+ if (current >= 100) {
buttonRendered = true;
} else if (current.equals(0L)) {
return 1L;
}
- return (new Date().getTime() - startTime) / 1000;
+ return (new Date().getTime() - startTime) / 500;
}
if (startTime == null) {
return -1L;
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/clientMode.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/clientMode.xhtml 2011-01-18
13:01:51 UTC (rev 21054)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/clientMode.xhtml 2011-01-18
14:48:02 UTC (rev 21055)
@@ -6,7 +6,7 @@
<!--
JBoss, Home of Professional Open Source
-Copyright 2010, Red Hat, Inc. and individual contributors
+Copyright 2010-2011, Red Hat, Inc. and individual contributors
by the @authors tag. See the copyright.txt in the distribution for a
full listing of individual contributors.
@@ -42,12 +42,12 @@
<script type="text/javascript">
//<![CDATA[
- var counter = 1;
+ var counter = 0;
var intervalID;
function updateProgress(i) {
- #{rich:component('progressBar')}.setValue(counter*5);
- if ((counter++)>20){
+ #{rich:component('progressBar')}.setValue(counter*2);
+ if ((counter++)>50){
clearInterval(intervalID);
#{rich:element('startButton')}.disabled=false;
#{rich:element('pauseButton')}.disabled=true;
@@ -59,7 +59,7 @@
#{rich:element('startButton')}.disabled=true;
#{rich:element('pauseButton')}.disabled=false;
#{rich:component('progressBar')}.enable();
- #{rich:component('progressBar')}.setValue(counter*5);
+ #{rich:component('progressBar')}.setValue(counter*2);
intervalID = setInterval(updateProgress,1000);
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/static.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/static.xhtml 2011-01-18
13:01:51 UTC (rev 21054)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richProgressBar/static.xhtml 2011-01-18
14:48:02 UTC (rev 21055)
@@ -41,9 +41,9 @@
<ui:define name="component">
<h:panelGrid id="settingsPanel" columns="2">
- Children rendered: <h:selectBooleanCheckbox
value="#{richProgressBarBean.childrenRendered}" onclick="submit()"
/>
- 'initial' facet rendered: <h:selectBooleanCheckbox
value="#{richProgressBarBean.initialFacetRendered}" onclick="submit()"
/>
- 'finish' facet rendered: <h:selectBooleanCheckbox
value="#{richProgressBarBean.finishFacetRendered}" onclick="submit()"
/>
+ Children rendered: <h:selectBooleanCheckbox
id="childrenRendered" value="#{richProgressBarBean.childrenRendered}"
onclick="submit()" />
+ 'initial' facet rendered: <h:selectBooleanCheckbox
id="initialFacetRendered"
value="#{richProgressBarBean.initialFacetRendered}" onclick="submit()"
/>
+ 'finish' facet rendered: <h:selectBooleanCheckbox
id="finishFacetRendered"
value="#{richProgressBarBean.finishFacetRendered}" onclick="submit()"
/>
</h:panelGrid>
<rich:progressBar id="progressBar"
@@ -84,7 +84,7 @@
</f:facet>
<f:facet name="finish">
<h:panelGroup
rendered="#{richProgressBarBean.finishFacetRendered}">
- <h:outputText id="completeOutput"
value="Complete"/>
+ <h:outputText id="finishOutput"
value="Finish"/>
</h:panelGroup>
</f:facet>
</rich:progressBar>
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarAjax.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarAjax.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarAjax.java 2011-01-18
14:48:02 UTC (rev 21055)
@@ -0,0 +1,288 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richProgressBar;
+
+import java.text.ParseException;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.test.selenium.dom.Event;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richProgressBar/ajaxMode.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestProgressBarAjax extends AbstractMetamerTest {
+
+ private JQueryLocator progressBar = pjq("div[id$=progressBar]");
+ private JQueryLocator initialOutput = pjq("div.rf-pb-init > span");
+ private JQueryLocator completeOutput = pjq("div.rf-pb-fin > span");
+ private JQueryLocator startButton = pjq("div.rf-pb-init > input");
+ private JQueryLocator restartButton = pjq("div.rf-pb-fin > input");
+ private JQueryLocator remain = pjq("div.rf-pb-rmng");
+ private JQueryLocator progress = pjq("div.rf-pb-prgs");
+ private JQueryLocator complete = pjq("div[id$=complete]");
+ private JQueryLocator label = pjq("div.rf-pb-lbl");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richProgressBar/ajaxMode.xhtml");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isElementPresent(progressBar), "Progress bar is not
present on the page.");
+ assertTrue(selenium.isDisplayed(progressBar), "Progress bar is not present
on the page.");
+ assertTrue(selenium.isDisplayed(initialOutput), "Initial output is not
present on the page.");
+ assertFalse(selenium.isElementPresent(completeOutput), "Complete output
should not be present on the page.");
+ assertTrue(selenium.isDisplayed(startButton), "Start button is not present
on the page.");
+ assertFalse(selenium.isElementPresent(restartButton), "Restart button should
not be present on the page.");
+
+ if (selenium.isElementPresent(remain)) {
+ assertFalse(selenium.isVisible(remain), "Progress bar should not show
progress.");
+ }
+ if (selenium.isElementPresent(progress)) {
+ assertFalse(selenium.isVisible(progress), "Progress bar should not show
progress.");
+ }
+ if (selenium.isElementPresent(label)) {
+ assertFalse(selenium.isVisible(label), "Progress bar should not show
progress.");
+ }
+ }
+
+ @Test
+ public void testStart() {
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).click(startButton);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ assertTrue(selenium.isDisplayed(progressBar), "Progress bar is not present
on the page.");
+ assertFalse(selenium.isElementPresent(initialOutput), "Initial output should
not be present on the page.");
+ assertFalse(selenium.isElementPresent(completeOutput), "Complete output
should not be present on the page.");
+ assertFalse(selenium.isElementPresent(startButton), "Start button should not
be present on the page.");
+ assertFalse(selenium.isElementPresent(restartButton), "Restart button should
not be present on the page.");
+
+ assertTrue(selenium.isElementPresent(remain), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(remain), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(progress), "Progress bar should not show
progress.");
+ assertFalse(selenium.isElementPresent(complete), "Progress bar should not
show progress.");
+
+ assertEquals(selenium.getText(label), "1 %", "Progress bar's
label after start");
+ }
+
+ @Test
+ public void testProgress() throws ParseException {
+ testOneRunOfProgressBar(startButton, 500);
+ testOneRunOfProgressBar(restartButton, 500);
+ }
+
+ @Test
+ public void testData() {
+ selenium.type(pjq("input[type=text][id$=dataInput]"), "RichFaces
4");
+ selenium.waitForPageToLoad();
+
+ selenium.type(pjq("input[type=text][id$=oncompleteInput]"), "data
= event.data");
+ selenium.waitForPageToLoad();
+
+ String reqTime = selenium.getText(time);
+ guardXhr(selenium).click(startButton);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+ reqTime = selenium.getText(time);
+ waitGui.failWith("Page was not updated").waitForChange(reqTime,
retrieveText.locator(time));
+
+ String data = selenium.getEval(new JavaScript("window.data"));
+ assertEquals(data, "RichFaces 4", "Data sent with ajax
request");
+ }
+
+ @Test
+ public void testInterval() throws ParseException {
+ selenium.type(pjq("input[type=text][id$=intervalInput]"),
"1000");
+ selenium.waitForPageToLoad();
+
+ testOneRunOfProgressBar(startButton, 1000);
+ }
+
+ @Test
+ public void testEvents() {
+ selenium.type(pjq("input[type=text][id$=onbeginInput]"),
"metamerEvents += \"begin \"");
+ selenium.waitForPageToLoad();
+ selenium.type(pjq("input[type=text][id$=onbeforedomupdateInput]"),
"metamerEvents += \"beforedomupdate \"");
+ selenium.waitForPageToLoad();
+ selenium.type(pjq("input[type=text][id$=oncompleteInput]"),
"metamerEvents += \"complete \"");
+ selenium.waitForPageToLoad();
+
+ selenium.getEval(new JavaScript("window.metamerEvents =
\"\";"));
+
+ guardXhr(selenium).click(startButton);
+ waitGui.timeout(55000).failWith("Progress bar should disappear after it
finishes.").until(elementPresent.locator(restartButton));
+
+ String[] events = selenium.getEval(new
JavaScript("window.metamerEvents")).split(" ");
+
+ assertEquals(events.length % 3, 0, "Number of events should be a multiple of
3.");
+ for (int i = 0; i < events.length; i += 3) {
+ assertEquals(events[i], "begin", "Event nr." + i + "
should be begin.");
+ assertEquals(events[i + 1], "beforedomupdate", "Event
nr." + (i + 1) + " should be beforedomupdate.");
+ assertEquals(events[i + 2], "complete", "Event nr." + (i
+ 2) + " should be complete.");
+ }
+ }
+
+ @Test
+ public void testOnclick() {
+ testFireEvent(Event.CLICK, progressBar);
+ }
+
+ @Test
+ public void testOndblclick() {
+ testFireEvent(Event.DBLCLICK, progressBar);
+ }
+
+ @Test
+ public void testOnfinish() {
+ selenium.type(pjq("input[type=text][id$=onfinishInput]"),
"metamerEvents += \"finish \"");
+ selenium.waitForPageToLoad();
+
+ selenium.getEval(new JavaScript("window.metamerEvents =
\"\";"));
+
+ guardXhr(selenium).click(startButton);
+ waitGui.timeout(55000).failWith("Progress bar should disappear after it
finishes.").until(elementPresent.locator(restartButton));
+
+ String[] events = selenium.getEval(new
JavaScript("window.metamerEvents")).split(" ");
+
+ assertEquals(events.length, 1, "Only one event should be fired.");
+ assertEquals(events[0], "finish", "Onfinish doesn't
work.");
+ }
+
+ @Test
+ public void testOnmousedown() {
+ testFireEvent(Event.MOUSEDOWN, progressBar);
+ }
+
+ @Test
+ public void testOnmousemove() {
+ testFireEvent(Event.MOUSEMOVE, progressBar);
+ }
+
+ @Test
+ public void testOnmouseout() {
+ testFireEvent(Event.MOUSEOUT, progressBar);
+ }
+
+ @Test
+ public void testOnmouseover() {
+ testFireEvent(Event.MOUSEOVER, progressBar);
+ }
+
+ @Test
+ public void testOnmouseup() {
+ testFireEvent(Event.MOUSEUP, progressBar);
+ }
+
+ @Test
+ public void testRendered() {
+
selenium.click(pjq("input[type=radio][name$=renderedInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ assertFalse(selenium.isElementPresent(progressBar), "Progress bar should not
be rendered when rendered=false.");
+ }
+
+ private void testOneRunOfProgressBar(JQueryLocator button, int interval) throws
ParseException {
+ SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss.SSS");
+ long delta = (long) (interval * 0.5);
+ Set<String> timesSet = new TreeSet<String>();
+ List<String> labelsList = new ArrayList<String>();
+ List<String> progressList = new ArrayList<String>();
+
+ guardXhr(selenium).click(button);
+
+ for (int i = 0; i < 40; i++) {
+ waitFor(delta);
+ timesSet.add(selenium.getText(time));
+ labelsList.add(selenium.getText(label).replace(" %",
""));
+ String width =
selenium.getAttribute(progress.getAttribute(Attribute.STYLE)).replace("%",
"").replace("width:", "");
+ progressList.add(width.replace(";", "").trim());
+ }
+
+ Date[] timesArray = new Date[timesSet.size()];
+ List<String> timesList = new ArrayList<String>(timesSet);
+
+ for (int i = 1; i < timesList.size(); i++) {
+ timesArray[i] = sdf.parse(timesList.get(i));
+ }
+
+ long average = countAverage(timesArray);
+ assertTrue(Math.abs(average - interval) < delta, "Average interval "
+ average + " is too far from set value (" + interval + ")");
+ assertFalse(average < interval, "Average interval " + average +
" cannot be smaller than set value (" + interval + ")");
+
+ int first = 0;
+ int second = -1;
+
+ for (int i = 0; i < labelsList.size() - 1; i++) {
+ first = Integer.parseInt(labelsList.get(i));
+ second = Integer.parseInt(labelsList.get(i + 1));
+ assertTrue(first <= second, "Number of percent in label should be
increasing: " + first + "!<= " + second);
+ }
+
+ for (int i = 0; i < progressList.size() - 1; i++) {
+ first = Integer.parseInt(progressList.get(i));
+ second = Integer.parseInt(progressList.get(i + 1));
+ assertTrue(first <= second, "Progress of progress bar should be
increasing: " + first + "!<= " + second);
+ }
+
+ waitGui.timeout(40000).failWith("Progress bar should disappear after it
finishes.").until(elementPresent.locator(restartButton));
+ assertTrue(selenium.isElementPresent(completeOutput), "Complete output
should be present on the page.");
+
+ assertTrue(selenium.isDisplayed(progressBar), "Progress bar is not present
on the page.");
+ assertFalse(selenium.isElementPresent(initialOutput), "Initial output should
not be present on the page.");
+ assertTrue(selenium.isDisplayed(completeOutput), "Complete output should be
present on the page.");
+ assertFalse(selenium.isElementPresent(startButton), "Start button should not
be present on the page.");
+ assertTrue(selenium.isVisible(restartButton), "Restart button should be
present on the page.");
+
+ assertFalse(selenium.isDisplayed(remain), "Progress bar should not show
progress.");
+ }
+
+ private long countAverage(Date[] times) {
+ long total = 0L;
+ for (int i = 1; i < times.length - 1; i++) {
+ total += (times[i].getTime() - times[i + 1].getTime());
+ }
+
+ return Math.abs(total / (times.length - 2));
+ }
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarAjax.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarClient.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarClient.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarClient.java 2011-01-18
14:48:02 UTC (rev 21055)
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richProgressBar;
+
+import java.text.ParseException;
+import static
org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+
+
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richProgressBar/clientMode.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestProgressBarClient extends AbstractMetamerTest {
+
+ private JQueryLocator progressBar = pjq("div[id$=progressBar]");
+ private JQueryLocator initialOutput = pjq("div.rf-pb-init > span");
+ private JQueryLocator completeOutput = pjq("div.rf-pb-fin > span");
+ private JQueryLocator startButton = pjq("input[id$=startButton]");
+ private JQueryLocator pauseButton = pjq("input[id$=pauseButton]");
+ private JQueryLocator remain = pjq("div.rf-pb-rmng");
+ private JQueryLocator progress = pjq("div.rf-pb-prgs");
+ private JQueryLocator complete = pjq("div[id$=complete]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richProgressBar/clientMode.xhtml");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isElementPresent(progressBar), "Progress bar is not
present on the page.");
+ assertTrue(selenium.isDisplayed(progressBar), "Progress bar is not present
on the page.");
+ assertTrue(selenium.isDisplayed(initialOutput), "Initial output is not
present on the page.");
+ assertFalse(selenium.isVisible(completeOutput), "Complete output should not
be present on the page.");
+ assertTrue(selenium.isVisible(startButton), "Start button should be present
on the page.");
+ assertTrue(selenium.isVisible(pauseButton), "Pause button should be present
on the page.");
+
+ assertFalse(selenium.isVisible(remain), "Progress bar should not show
progress.");
+ assertFalse(selenium.isVisible(progress), "Progress bar should not show
progress.");
+ }
+
+ @Test
+ public void testStart() {
+ guardNoRequest(selenium).click(startButton);
+
+ assertTrue(selenium.isDisplayed(progressBar), "Progress bar is not present
on the page.");
+ assertFalse(selenium.isVisible(initialOutput), "Initial output should not be
present on the page.");
+ assertFalse(selenium.isVisible(completeOutput), "Complete output should not
be present on the page.");
+ assertTrue(selenium.isVisible(startButton), "Start button should be present
on the page.");
+ assertTrue(selenium.isVisible(pauseButton), "Restart button should be
present on the page.");
+
+ assertTrue(selenium.isElementPresent(remain), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(remain), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(progress), "Progress bar should not show
progress.");
+ assertFalse(selenium.isElementPresent(complete), "Progress bar should not
show progress.");
+ }
+
+ @Test
+ public void testProgress() throws ParseException {
+ testOneRunOfProgressBar(startButton, 1000);
+ testOneRunOfProgressBar(startButton, 1000);
+ }
+
+ @Test
+ public void testPause() {
+ selenium.click(startButton);
+ waitFor(4000);
+
+ selenium.click(pauseButton);
+ int value = getProgress();
+ assertTrue(value > 0, "Progress bar should show non-null progress after 4
seconds.");
+
+ waitFor(4000);
+ int value2 = getProgress();
+ assertEquals(value2, value, "Progress bar should not be updated when
paused.");
+ selenium.click(startButton);
+
+ value = getProgress();
+ assertTrue(value > value2, "Progress bar's value should increase
after pause.");
+ }
+
+ @Test
+ public void testOnfinish() {
+ selenium.type(pjq("input[type=text][id$=onfinishInput]"),
"metamerEvents += \"finish \"");
+ selenium.waitForPageToLoad();
+
+ selenium.getEval(new JavaScript("window.metamerEvents =
\"\";"));
+
+ selenium.click(startButton);
+ waitGui.timeout(60000).failWith("Progress bar should disappear after it
finishes.").until(isDisplayed.locator(pjq("div.rf-pb-fin")));
+
+ String[] events = selenium.getEval(new
JavaScript("window.metamerEvents")).split(" ");
+
+ assertEquals(events.length, 1, "Only one event should be fired.");
+ assertEquals(events[0], "finish", "Onfinish doesn't
work.");
+ }
+
+ private void testOneRunOfProgressBar(JQueryLocator button, int interval) throws
ParseException {
+ long delta = (long) (interval * 0.5);
+ List<Integer> progressList = new ArrayList<Integer>();
+
+ selenium.click(button);
+
+ for (int i = 0; i < 40; i++) {
+ waitFor(delta);
+ progressList.add(getProgress());
+ }
+
+ int first = 0;
+ int second = -1;
+
+ for (int i = 0; i < progressList.size() - 1; i++) {
+ first = progressList.get(i);
+ second = progressList.get(i + 1);
+ assertTrue(first <= second, "Progress of progress bar should be
increasing: " + first + "!<= " + second);
+ }
+
+ waitGui.timeout(40000).failWith("Progress bar should disappear after it
finishes.").until(isDisplayed.locator(pjq("div.rf-pb-fin")));
+ assertTrue(selenium.isElementPresent(completeOutput), "Complete output
should be present on the page.");
+
+ assertTrue(selenium.isDisplayed(progressBar), "Progress bar is not present
on the page.");
+ assertFalse(selenium.isVisible(initialOutput), "Initial output should not be
present on the page.");
+ assertTrue(selenium.isVisible(completeOutput), "Complete output should be
present on the page.");
+ assertTrue(selenium.isVisible(startButton), "Start button should be present
on the page.");
+ assertTrue(selenium.isVisible(pauseButton), "Restart button should be
present on the page.");
+
+ assertFalse(selenium.isDisplayed(remain), "Progress bar should not show
progress.");
+ }
+
+ private int getProgress() {
+ String width = selenium.getAttribute(progress.getAttribute(Attribute.STYLE));
+ width = width.replace("%", "").replace("width:",
"").replace(";", "").trim();
+ return Integer.parseInt(width);
+ }
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarClient.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarStatic.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarStatic.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarStatic.java 2011-01-18
14:48:02 UTC (rev 21055)
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richProgressBar;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richProgressBar/static.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestProgressBarStatic extends AbstractMetamerTest {
+
+ private JQueryLocator progressBar = pjq("div[id$=progressBar]");
+ private JQueryLocator initialOutput = pjq("div.rf-pb-init > span");
+ private JQueryLocator finishOutput = pjq("div.rf-pb-fin > span");
+ private JQueryLocator remain = pjq("div.rf-pb-rmng");
+ private JQueryLocator progress = pjq("div.rf-pb-prgs");
+ private JQueryLocator complete = pjq("div[id$=complete]");
+ private JQueryLocator label = pjq("div.rf-pb-lbl");
+ private JQueryLocator childrenRenderedCheckbox =
pjq("input[id$=childrenRendered]");
+ private JQueryLocator initialFacetRenderedCheckbox =
pjq("input[id$=initialFacetRendered]");
+ private JQueryLocator finishFacetRenderedCheckbox =
pjq("input[id$=finishFacetRendered]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richProgressBar/static.xhtml");
+ }
+
+ @Test
+ public void testInitialFacet() {
+ assertTrue(selenium.isElementPresent(progressBar), "Progress bar is not
present on the page.");
+ assertTrue(selenium.isVisible(progressBar), "Progress bar should be visible
on the page.");
+ assertTrue(selenium.isVisible(initialOutput), "Initial output should be
present on the page.");
+ assertFalse(selenium.isVisible(finishOutput), "Finish output should not be
present on the page.");
+ assertEquals(selenium.getText(initialOutput), "Initial", "Content
of initial facet.");
+
+ assertFalse(selenium.isVisible(remain), "Progress bar should not show
progress.");
+ assertFalse(selenium.isVisible(progress), "Progress bar should not show
progress.");
+ assertFalse(selenium.isVisible(label), "Progress bar should not show
progress.");
+
+ selenium.click(initialFacetRenderedCheckbox);
+ selenium.waitForPageToLoad();
+
+ assertTrue(selenium.isElementPresent(progressBar), "Progress bar is not
present on the page.");
+ assertTrue(selenium.isVisible(progressBar), "Progress bar should be visible
on the page.");
+ assertFalse(selenium.isElementPresent(initialOutput), "Initial output should
not be present on the page.");
+ assertFalse(selenium.isVisible(finishOutput), "Finish output should not be
present on the page.");
+
+ assertTrue(selenium.isVisible(remain), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(progress), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(label), "Progress bar should show
progress.");
+ }
+
+ @Test
+ public void testFinishFacet() {
+ selenium.type(pjq("input[id$=valueInput]"), "100");
+ selenium.waitForPageToLoad();
+
+ assertTrue(selenium.isElementPresent(progressBar), "Progress bar is not
present on the page.");
+ assertTrue(selenium.isVisible(progressBar), "Progress bar should be visible
on the page.");
+ assertFalse(selenium.isVisible(initialOutput), "Initial output should not be
present on the page.");
+ assertTrue(selenium.isVisible(finishOutput), "Finish output should be
present on the page.");
+ assertEquals(selenium.getText(finishOutput), "Finish", "Content of
finish facet.");
+
+ assertFalse(selenium.isVisible(remain), "Progress bar should not show
progress.");
+ assertFalse(selenium.isVisible(progress), "Progress bar should not show
progress.");
+ assertFalse(selenium.isVisible(label), "Progress bar should not show
progress.");
+
+ selenium.click(finishFacetRenderedCheckbox);
+ selenium.waitForPageToLoad();
+
+ assertTrue(selenium.isElementPresent(progressBar), "Progress bar is not
present on the page.");
+ assertTrue(selenium.isVisible(progressBar), "Progress bar should be visible
on the page.");
+ assertFalse(selenium.isVisible(initialOutput), "Initial output should not be
present on the page.");
+ assertFalse(selenium.isElementPresent(finishOutput), "Finish output should
not be present on the page.");
+
+ assertTrue(selenium.isVisible(remain), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(progress), "Progress bar should show
progress.");
+ assertTrue(selenium.isVisible(label), "Progress bar should show
progress.");
+ }
+
+ @Test
+ public void testFinishClass() {
+ testStyleClass(pjq("div.rf-pb-fin"), "finishClass");
+ }
+
+ @Test
+ public void testInitialClass() {
+ testStyleClass(pjq("div.rf-pb-init"), "initialClass");
+ }
+
+ @Test
+ public void testLabel() {
+ selenium.click(initialFacetRenderedCheckbox);
+ selenium.waitForPageToLoad();
+ String labelValue = selenium.getText(label);
+ assertEquals(labelValue, "", "Label when not set.");
+
+ selenium.type(pjq("input[id$=labelInput]"), "metamer");
+ selenium.waitForPageToLoad();
+ labelValue = selenium.getText(label);
+ assertEquals(labelValue, "metamer", "Label when set to
metamer.");
+
+ selenium.click(childrenRenderedCheckbox);
+ selenium.waitForPageToLoad();
+ labelValue = selenium.getText(label);
+ assertEquals(labelValue, "child + metamer", "Label when set to
metamer and children are rendered too.");
+ }
+
+ @Test
+ public void testMaxValue() {
+ selenium.type(pjq("input[id$=maxValueInput]"), "1000");
+ selenium.waitForPageToLoad();
+ selenium.type(pjq("input[id$=valueInput]"), "100");
+ selenium.waitForPageToLoad();
+
+ assertEquals(getProgress(), 10, "Progress when value=100 and
maxValue=1000.");
+ }
+
+ @Test
+ public void testMinValue() {
+ selenium.type(pjq("input[id$=minValueInput]"), "90");
+ selenium.waitForPageToLoad();
+ selenium.type(pjq("input[id$=valueInput]"), "95");
+ selenium.waitForPageToLoad();
+
+ assertEquals(getProgress(), 50, "Progress when value=95 and
minValue=90.");
+ }
+
+ @Test
+ public void testProgressClass() {
+ testStyleClass(progress, "progressClass");
+ }
+
+ @Test
+ public void testRemainingClass() {
+ testStyleClass(remain, "remainingClass");
+ }
+
+ @Test
+ public void testStyle() {
+ testStyle(progressBar, "style");
+ }
+
+ @Test
+ public void testStyleClass() {
+ testStyleClass(progressBar, "styleClass");
+ }
+
+ @Test
+ public void testValue() {
+ selenium.type(pjq("input[id$=valueInput]"), "0");
+ selenium.waitForPageToLoad();
+ assertEquals(getProgress(), 0, "Progress when value=0.");
+
+ selenium.type(pjq("input[id$=valueInput]"), "37");
+ selenium.waitForPageToLoad();
+ assertEquals(getProgress(), 37, "Progress when value=37.");
+
+ selenium.type(pjq("input[id$=valueInput]"), "100");
+ selenium.waitForPageToLoad();
+ assertEquals(getProgress(), 100, "Progress when value=100.");
+
+ selenium.type(pjq("input[id$=valueInput]"), "-345");
+ selenium.waitForPageToLoad();
+ assertEquals(getProgress(), 0, "Progress when value=-345.");
+ assertTrue(selenium.isVisible(initialOutput), "Initial output should be
visible on the page.");
+ assertFalse(selenium.isVisible(finishOutput), "Finish output should not be
visible on the page.");
+
+ selenium.type(pjq("input[id$=valueInput]"), "456");
+ selenium.waitForPageToLoad();
+ assertEquals(getProgress(), 100, "Progress when value=456.");
+ assertFalse(selenium.isVisible(initialOutput), "Initial output should not be
visible on the page.");
+ assertTrue(selenium.isVisible(finishOutput), "Finish output should be
visible on the page.");
+ }
+
+ private int getProgress() {
+ String width = selenium.getAttribute(progress.getAttribute(Attribute.STYLE));
+ width = width.replace("%", "").replace("width:",
"").replace(";", "").trim();
+ return Integer.parseInt(width);
+ }
+}
Property changes on:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richProgressBar/TestProgressBarStatic.java
___________________________________________________________________
Name: svn:keywords
+ Revision