Author: lfryc(a)redhat.com
Date: 2009-09-03 16:19:17 -0400 (Thu, 03 Sep 2009)
New Revision: 15459
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/log/LogTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/messages.properties
Log:
- refactored Log test cases to follow conventions
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/log/LogTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/log/LogTestCase.java 2009-09-03
19:23:31 UTC (rev 15458)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/log/LogTestCase.java 2009-09-03
20:19:17 UTC (rev 15459)
@@ -1,12 +1,33 @@
+/**
+ * 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.log;
-import junit.framework.Assert;
+import static org.testng.Assert.*;
import org.apache.commons.lang.StringUtils;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.waiting.Condition;
import org.jboss.test.selenium.waiting.Wait;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
@@ -14,43 +35,41 @@
* @version $Revision$
*/
public class LogTestCase extends AbstractSeleniumRichfacesTestCase {
+
+ private final String LOC_FIELDSET_HEADER = getLoc("FIELDSET_HEADER");
+ private final String LOC_INPUT_TEXT = getLoc("INPUT_TEXT");
+ private final String LOC_BUTTON_CLEAR = getLoc("BUTTON_CLEAR");
+ private final String LOC_OUTPUT_LOG_CONSOLE = getLoc("OUTPUT_LOG_CONSOLE");
+ private final String LOC_DIV_LOG_CONSOLE_ENTRY =
getLoc("DIV_LOG_CONSOLE_ENTRY");
+
+ private final String MSG_INPUT_SAMPLE = getMsg("INPUT_SAMPLE");
+ private final String MSG_OUTPUT_DEBUG = getMsg("OUTPUT_DEBUG");
+ private final String MSG_OUTPUT_CLEAR = getMsg("OUTPUT_CLEAR");
+
/**
- * Opens specified page
+ * Force event and wait for log contain specified text
*/
- private void openPage() {
- selenium.open(contextPath + "/richfaces/log.jsf?c=log&tab=usage");
- scrollIntoView(header, true);
- }
-
- private String header = getLoc("log--header");
- private String inputText = getLoc("log--input--text");
- private String buttonClear = getLoc("log--button--clear");
- private String outputText = getLoc("log--output--text");
- private String outputDivs = getLoc("log--output--divs");
- private String messageSample = getMess("log--input--sample");
- private String messageDebug = getMess("log--output--debug");
- private String messageClear = getMess("log--output--clear");
-
@Test
public void testFillLog() {
- openPage();
-
fillLog();
}
+ /**
+ * Force event, wait for log contain specified text and log entries count
+ * stabilizes and then tries to clear the log
+ */
@Test
public void testClearLog() {
- openPage();
-
fillLog();
waitForLogStabilize();
clearLog();
}
+ /**
+ * Try fill the log and next clear and checks right behaviour
+ */
@Test
public void testRepeatingFillAndClear() {
- openPage();
-
fillLog();
waitForLogStabilize();
clearLog();
@@ -60,45 +79,56 @@
clearLog();
}
- public void waitForLogStabilize() {
- Wait.interval(3000).timeout(9000).until(new Condition() {
- long count = -1;
+ private void fillLog() {
+ final long startCount = selenium.getXpathCount(LOC_DIV_LOG_CONSOLE_ENTRY).longValue();
+ selenium.type(LOC_INPUT_TEXT, MSG_INPUT_SAMPLE);
+ selenium.fireEvent(LOC_INPUT_TEXT, Event.KEYUP);
+
+ Wait.failWith("Count of log entries never increase").until(new Condition() {
public boolean isTrue() {
- long actual = selenium.getXpathCount(outputDivs).longValue();
- if (actual == count) {
- return true;
- }
- count = actual;
- return false;
+ return selenium.getXpathCount(LOC_DIV_LOG_CONSOLE_ENTRY).longValue() >
startCount;
}
});
+
+ String consoleText = selenium.getText(LOC_OUTPUT_LOG_CONSOLE);
+
+ assertTrue(consoleText.contains(MSG_OUTPUT_DEBUG), format("Console text should
contain word '{0}'",
+ MSG_OUTPUT_DEBUG));
}
- public void fillLog() {
- final long startCount = selenium.getXpathCount(outputDivs).longValue();
+ private void clearLog() {
+ selenium.click(LOC_BUTTON_CLEAR);
- selenium.type(inputText, messageSample);
- selenium.fireEvent(inputText, Event.KEYUP);
-
- Wait.until(new Condition() {
+ Wait.failWith("Text of the console never get without entries (clear button
only)").until(new Condition() {
public boolean isTrue() {
- return selenium.getXpathCount(outputDivs).longValue() > startCount;
+ String consoleText = selenium.getText(LOC_OUTPUT_LOG_CONSOLE);
+ return MSG_OUTPUT_CLEAR.equals(StringUtils.trim(consoleText));
}
});
+ }
- String output = selenium.getText(outputText);
- Assert.assertTrue(output.contains(messageDebug));
+ private void waitForLogStabilize() {
+ Wait.failWith("Log stabilized in entry count in given
time").interval(3000).timeout(9000).until(
+ new Condition() {
+ long count = -1;
+
+ public boolean isTrue() {
+ long actual = selenium.getXpathCount(LOC_DIV_LOG_CONSOLE_ENTRY).longValue();
+ if (actual == count) {
+ return true;
+ }
+ count = actual;
+ return false;
+ }
+ });
}
- public void clearLog() {
- selenium.click(buttonClear);
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Log");
- Wait.until(new Condition() {
- public boolean isTrue() {
- String output = selenium.getText(outputText);
- return messageClear.equals(StringUtils.trim(output));
- }
- });
+ scrollIntoView(LOC_FIELDSET_HEADER, true);
}
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/locators.properties 2009-09-03
19:23:31 UTC (rev 15458)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/locators.properties 2009-09-03
20:19:17 UTC (rev 15459)
@@ -1,5 +1,5 @@
-log--header=//legend[text()\='Log demo']
-log--input--text=//input[@type\='text']
-log--button--clear=//button[text()\='Clear']
-log--output--text //div[@id\='logConsole']
-log--output--divs=//div[@id\='logConsole']/div
+FIELDSET_HEADER=//legend[text()\='Log demo']
+INPUT_TEXT=//input[@type\='text']
+BUTTON_CLEAR=//button[text()\='Clear']
+OUTPUT_LOG_CONSOLE //div[@id\='logConsole']
+DIV_LOG_CONSOLE_ENTRY=//div[@id\='logConsole']/div
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/messages.properties 2009-09-03
19:23:31 UTC (rev 15458)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/log/messages.properties 2009-09-03
20:19:17 UTC (rev 15459)
@@ -1,3 +1,3 @@
-log--input--sample=abc
-log--output--debug=debug
-log--output--clear=Clear
+INPUT_SAMPLE=abc
+OUTPUT_DEBUG=debug
+OUTPUT_CLEAR=Clear
Show replies by date