Author: lfryc(a)redhat.com
Date: 2009-09-02 05:14:50 -0400 (Wed, 02 Sep 2009)
New Revision: 15434
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/push/PushTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/messages.properties
Log:
- refactored Push test cases to follow conventions, extended to 2-cycle
testPushingStartAndStop
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/push/PushTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/push/PushTestCase.java 2009-09-02
08:13:18 UTC (rev 15433)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/push/PushTestCase.java 2009-09-02
09:14:50 UTC (rev 15434)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces
+ *
+ * Copyright (C) 2009 Red Hat, Inc.
+ *
+ * This code 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 code 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 test suite; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.jboss.richfaces.integrationTest.push;
import org.apache.commons.lang.StringUtils;
@@ -2,5 +22,6 @@
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
-import org.jboss.test.selenium.waiting.Condition;
-import org.jboss.test.selenium.waiting.Wait;
-import org.testng.Assert;
+import org.jboss.test.selenium.waiting.*;
+import static org.testng.Assert.*;
+
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -12,95 +33,114 @@
* @version $Revision$
*/
public class PushTestCase extends AbstractSeleniumRichfacesTestCase {
+ private final String LOC_BUTTON_POLL_CONTROL = getLoc("BUTTON_POLL_CONTROL");
+ private final String LOC_OUTPUT_TEXT = getLoc("OUTPUT_TEXT");
+
+ private final String MSG_OUTPUT_PUSH_ACTIVE = getMsg("OUTPUT_PUSH_ACTIVE");
+ private final String MSG_OUTPUT_PUSH_INACTIVE =
getMsg("OUTPUT_PUSH_INACTIVE");
+
/**
- * Opens specified page
+ * Start pushing and checks that new values are really pushed.
*/
- private void openPage() {
- selenium.open(contextPath + "/richfaces/push.jsf?c=push&tab=usage");
-
- scrollIntoView(control, false);
- }
-
- private String control = getLoc("push--control");
- private String outputText = getLoc("push--output-text");
-
@Test
public void testPushingProgress() {
- openPage();
-
setPushingStatus(true);
- pushingProgress();
+ checkPushingProgress();
}
+ /**
+ * Stop pushing and checks that pushing isn't in progress.
+ */
@Test
public void testPushingStop() {
- openPage();
-
setPushingStatus(false);
- pushingStopped();
+ checkPushingStopped();
}
+ /**
+ * Switches between active and inactive pushing states and checks that
+ * output behave appropriately.
+ */
@Test
public void testPushingStopAndStart() {
- openPage();
+ setPushingStatus(false);
+ checkPushingStopped();
+
+ setPushingStatus(true);
+
+ checkPushingProgress();
+
setPushingStatus(false);
- pushingStopped();
+ checkPushingStopped();
setPushingStatus(true);
- pushingProgress();
+ checkPushingProgress();
}
- public void pushingProgress() {
- Assert.assertTrue(isPushingActive());
+ private void checkPushingProgress() {
+ assertTrue(isPushingActive(), "Pushing was inactive but should be active");
- final String old = selenium.getText(outputText);
+ final String oldOutput = selenium.getText(LOC_OUTPUT_TEXT);
- Wait.interval(2500).timeout(20000).until(new Condition() {
- public boolean isTrue() {
- String actual = selenium.getText(outputText);
+ Wait.failWith("When waiting for text change, it never
happen").interval(2500).timeout(20000).until(
+ new Condition() {
+ public boolean isTrue() {
+ String actualOutput = selenium.getText(LOC_OUTPUT_TEXT);
- return !old.equals(actual);
- }
- });
+ return !oldOutput.equals(actualOutput);
+ }
+ });
- String uuid = StringUtils.removeStart(selenium.getText(outputText),
- getMess("push--active"));
+ String uuid = selenium.getText(LOC_OUTPUT_TEXT);
- Assert.assertTrue(StringUtils.isNotBlank(uuid));
+ assertTrue(uuid.startsWith(MSG_OUTPUT_PUSH_ACTIVE));
+
+ uuid = StringUtils.removeStart(uuid, MSG_OUTPUT_PUSH_ACTIVE);
+
+ assertTrue(StringUtils.isNotBlank(uuid), "Generated UUID should not be
blank");
}
- public void pushingStopped() {
- Assert.assertFalse(isPushingActive());
+ private void checkPushingStopped() {
+ assertFalse(isPushingActive(), "Pushing was active but expected to be
inactive");
- String expected = getMess("push--inactive");
-
+ String expected = MSG_OUTPUT_PUSH_INACTIVE;
+
for (int i = 0; i < 7; i++) {
- if (i > 0) waitFor(2500);
- String actual = selenium.getText(outputText);
+ if (i > 0)
+ waitFor(2500);
+ String actual = selenium.getText(LOC_OUTPUT_TEXT);
- Assert.assertEquals(actual, expected);
+ assertEquals(actual, expected);
}
}
- public void setPushingStatus(final boolean pushingActive) {
- if (pushingActive != isPushingActive()) {
+ private void setPushingStatus(final boolean requiredPushingStatus) {
+ if (requiredPushingStatus != isPushingActive()) {
- selenium.click(control);
+ selenium.click(LOC_BUTTON_POLL_CONTROL);
Wait.until(new Condition() {
public boolean isTrue() {
- return pushingActive == isPushingActive();
+ return requiredPushingStatus == isPushingActive();
}
});
}
}
- public boolean isPushingActive() {
- return !getMess("push--inactive").equals(selenium.getText(outputText));
+ private boolean isPushingActive() {
+ return !MSG_OUTPUT_PUSH_INACTIVE.equals(selenium.getText(LOC_OUTPUT_TEXT));
}
+
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Push");
+
+ scrollIntoView(LOC_BUTTON_POLL_CONTROL, true);
+ }
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/locators.properties 2009-09-02
08:13:18 UTC (rev 15433)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/locators.properties 2009-09-02
09:14:50 UTC (rev 15434)
@@ -1,2 +1,2 @@
-push--control=//*[@type\='button' and (@value\='Start' or
@value\='Stop')]
-push--output-text=//*[text()\='Press Start to run push example' or
starts-with(text(), 'Generated UUID\:')]
+BUTTON_POLL_CONTROL=//*[@type\='button' and (@value\='Start' or
@value\='Stop')]
+OUTPUT_TEXT=//*[text()\='Press Start to run push example' or starts-with(text(),
'Generated UUID\:')]
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/messages.properties 2009-09-02
08:13:18 UTC (rev 15433)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/push/messages.properties 2009-09-02
09:14:50 UTC (rev 15434)
@@ -1,2 +1,2 @@
-push--inactive=Press Start to run push example
-push--active=Generated UUID\:
+OUTPUT_PUSH_ACTIVE=Generated UUID\:
+OUTPUT_PUSH_INACTIVE=Press Start to run push example
Show replies by date