Author: jpapouse
Date: 2012-01-05 10:07:31 -0500 (Thu, 05 Jan 2012)
New Revision: 23131
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java
Log:
tests for rich:hotKey component (attributes)
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java 2012-01-05
13:28:33 UTC (rev 23130)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/AbstractRichHotKeyTest.java 2012-01-05
15:07:31 UTC (rev 23131)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010-2012s, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2012, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -21,9 +21,13 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richHotKey;
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+
import java.net.URL;
+import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.utils.URLUtils;
+import org.jboss.test.selenium.waiting.NegationCondition;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.ftest.attributes.Attributes;
@@ -32,11 +36,34 @@
*/
public abstract class AbstractRichHotKeyTest extends AbstractMetamerTest {
+ protected static final String INPUT_1_LOCATOR = "input.first-input";
+ protected static final String INPUT_2_LOCATOR = "input.second-input";
+
+ protected static final JQueryLocator HOTKEY_1 =
pjq("span[id$=richHotKey1]");
+ protected static final JQueryLocator HOTKEY_2 =
pjq("span[id$=richHotKey2]");
+
+ protected static final JQueryLocator INPUT_1 = pjq(INPUT_1_LOCATOR);
+ protected static final JQueryLocator INPUT_2 = pjq(INPUT_2_LOCATOR);
+
+ private static final JQueryLocator CLEAR_BUTTON =
pjq("button.rf-log-element");
+ private static final String HOT_KEY_EVENT_LOCATOR =
"span.rf-log-entry-msg-info:contains({0})";
+
@Override
public URL getTestUrl() {
return URLUtils.buildUrl(contextPath,
"faces/components/richHotKey/simple.xhtml");
}
+ protected void checkEvent(String text, int number) {
+ waitGui
+ .failWith("The number of hotkey events doesn't match. Found
<" + selenium.getCount(pjq(format(HOT_KEY_EVENT_LOCATOR, text))) + ">,
expected <" + number + ">.")
+ .until(countEquals.locator(pjq(format(HOT_KEY_EVENT_LOCATOR,
text))).count(number));
+ }
+
+ protected void clearHotKeyEvents() {
+ selenium.click(CLEAR_BUTTON);
+
waitGui.until(NegationCondition.getInstance().condition(elementPresent.locator(pjq(format(HOT_KEY_EVENT_LOCATOR,
"''")))));
+ }
+
protected static final Attributes<HotKeyAttributes> ATTRIBUTES_FIRST = new
Attributes<HotKeyAttributes>(pjq("table.attributes[id$=attributes1]"));
protected static final Attributes<HotKeyAttributes> ATTRIBUTES_SECOND = new
Attributes<HotKeyAttributes>(pjq("table.attributes[id$=attributes2]"));
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java 2012-01-05
13:28:33 UTC (rev 23130)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/HotKeyAttributes.java 2012-01-05
15:07:31 UTC (rev 23131)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2012, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java 2012-01-05
13:28:33 UTC (rev 23130)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKey.java 2012-01-05
15:07:31 UTC (rev 23131)
@@ -36,10 +36,6 @@
private static final int NUMBER_OF_TESTS = 5;
- private final JQueryLocator clearButton = pjq("button.rf-log-element");
- private final JQueryLocator firstInput = pjq("input[id$=firstInput]");
- private final String hotKeyEeventLocator =
"span.rf-log-entry-msg-info:contains({0})";
-
@Test
public void testFirstAndSecondPair() {
for (int i=1; i<=NUMBER_OF_TESTS; i++) {
@@ -65,7 +61,6 @@
@Test
public void testFirstOne() {
ATTRIBUTES_FIRST.set(HotKeyAttributes.key, "x");
- selenium.focus(firstInput);
for (int i=1; i<=NUMBER_OF_TESTS; i++) {
for (int j=0; j<i; j++) {
selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
@@ -87,19 +82,9 @@
testPair(KeyEvent.VK_ALT, KeyEvent.VK_X, "hotkey 2");
}
- private void checkEvent(String text, int number) {
- waitGui
- .failWith("The number of hotkey events doesn't match. Found
<" + selenium.getCount(pjq(format(hotKeyEeventLocator, text))) + ">,
expected <" + number + ">.")
- .until(countEquals.locator(pjq(format(hotKeyEeventLocator,
text))).count(number));
- }
-
- private void clearHotKeyEvents() {
- selenium.click(clearButton);
-
waitGui.until(NegationCondition.getInstance().condition(elementPresent.locator(pjq(format(hotKeyEeventLocator,
"''")))));
- }
+
private void testPair(int firstKey, int secondKey, String text) {
- selenium.focus(firstInput);
for (int i=1; i<=NUMBER_OF_TESTS; i++) {
for (int j=0; j<i; j++) {
selenium.keyPressNative(String.valueOf(firstKey));
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richHotKey/TestRichHotKeyAttributes.java 2012-01-05
15:07:31 UTC (rev 23131)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2012, 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.richHotKey;
+
+import java.awt.event.KeyEvent;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestRichHotKeyAttributes extends AbstractRichHotKeyTest {
+
+ @AfterMethod
+ public void tearDown() {
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_CONTROL));
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_ALT));
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_M));
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_X));
+ }
+
+ @Test
+ public void enabledInInput() {
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.key, "x");
+ // true
+ selenium.focus(INPUT_1);
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 1);
+ clearHotKeyEvents();
+ // false
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.enabledInInput, false);
+ selenium.focus(INPUT_1);
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 0);
+ }
+
+ @Test
+ public void testRendered() {
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.rendered, false);
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.key, "x");
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 0);
+ }
+
+ @Test
+ public void testSelector() {
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.key, "x");
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.selector, INPUT_1_LOCATOR);
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 0);
+ selenium.focus(INPUT_2);
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 0);
+ selenium.focus(INPUT_1);
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_X));
+ checkEvent("hotkey 1", 1);
+ }
+
+ @Test
+ public void testTypeKeydownOne() {
+ testTypeOne("keydown", 3, KeyEvent.VK_CONTROL, "ctrl");
+ }
+
+ @Test
+ public void testTypeKeydownPair() {
+ testTypePair("keydown", 3, KeyEvent.VK_ALT, KeyEvent.VK_CONTROL,
"alt+ctrl");
+ }
+
+ @Test
+ public void testTypeKeypressOne() {
+ testTypeOne("keypress", 0, KeyEvent.VK_CONTROL, "ctrl");
+ tearDown();
+ testTypeOne("keypress", 3, KeyEvent.VK_X, "x");
+ }
+
+ @Test
+ public void testTypeKeypressPair() {
+ testTypePair("keypress", 3, KeyEvent.VK_CONTROL, KeyEvent.VK_X,
"ctrl+x");
+ }
+
+ @Test
+ public void testTypeKeyupOne() {
+ testTypeOne("keyup", 2, KeyEvent.VK_CONTROL, "ctrl");
+ }
+
+ @Test
+ public void testTypeKeyupPair() {
+ testTypePair("keyup", 2, KeyEvent.VK_ALT, KeyEvent.VK_CONTROL,
"alt+ctrl");
+ }
+
+ private void processOneKeySequence(int correctKey, int wrongKey) {
+ selenium.keyDownNative(String.valueOf(correctKey));
+ selenium.keyDownNative(String.valueOf(wrongKey));
+ selenium.keyUpNative(String.valueOf(correctKey));
+ selenium.keyUpNative(String.valueOf(wrongKey));
+ selenium.keyPressNative(String.valueOf(correctKey));
+ selenium.keyPressNative(String.valueOf(wrongKey));
+ selenium.keyDownNative(String.valueOf(correctKey));
+ selenium.keyDownNative(String.valueOf(wrongKey));
+ }
+
+ private void processPairKeySequence(int firstKey, int secondCorrectKey, int
secondWrongKey) {
+ selenium.keyDownNative(String.valueOf(firstKey));
+ processOneKeySequence(secondCorrectKey, secondWrongKey);
+ }
+
+ private void testTypeOne(String event, int number, int correctKeyCode, String
correctKeyName) {
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.key, correctKeyName);
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.type, event);
+ processOneKeySequence(correctKeyCode, KeyEvent.VK_M);
+ checkEvent("hotkey 1", number);
+ clearHotKeyEvents();
+ }
+
+ private void testTypePair(String event, int number, int firstCorrectKeyCode, int
secondCorrectKeyCode, String keyNames) {
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.key, keyNames);
+ ATTRIBUTES_FIRST.set(HotKeyAttributes.type, event);
+ processPairKeySequence(firstCorrectKeyCode, secondCorrectKeyCode,
KeyEvent.VK_M);
+ checkEvent("hotkey 1", number);
+ clearHotKeyEvents();
+ }
+
+}