Author: jpapouse
Date: 2011-09-22 07:39:32 -0400 (Thu, 22 Sep 2011)
New Revision: 22731
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/AbstractAutocompleteTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteVisualState.java
Log:
RFPL-1354: test for valueChangeListener attribute (rich:autocomplete)
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/AbstractAutocompleteTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/AbstractAutocompleteTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/AbstractAutocompleteTest.java 2011-09-22
11:39:32 UTC (rev 22731)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.richAutocomplete;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.richfaces.tests.metamer.bean.Model;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.model.Autocomplete;
+import org.richfaces.tests.metamer.model.Capital;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public abstract class AbstractAutocompleteTest extends AbstractMetamerTest {
+
+ private AutocompleteAttributes attributes = new AutocompleteAttributes();
+ private Autocomplete autocomplete = new Autocomplete();
+ List<Capital> capitals = Model.unmarshallCapitals();
+
+ protected AutocompleteAttributes getAttributes() {
+ return attributes;
+ }
+
+ protected Autocomplete getAutocomplete() {
+ return autocomplete;
+ }
+
+ protected List<Capital> getCapitals() {
+ return Collections.unmodifiableList(capitals);
+ }
+
+ protected List<String> getStatesByPrefix(String prefix) {
+ List<String> states = new LinkedList<String>();
+
+ for (Capital cap : capitals) {
+ if (cap.getState().toLowerCase().startsWith(prefix)) {
+ states.add(cap.getState());
+ }
+ }
+
+ return states;
+ }
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteAttributes.java 2011-09-22
11:39:32 UTC (rev 22731)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.richAutocomplete;
+
+import static java.text.MessageFormat.format;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestAutocompleteAttributes extends AbstractAutocompleteTest {
+
+ private static final JQueryLocator PHASE_FORMAT = jq("div#phasesPanel
li:eq({0})");
+ private static final String PHASE_LISTENER_LOG_FORMAT = "*1 value changed: {0}
-> {1}";
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richAutocomplete/autocomplete.xhtml");
+ }
+
+ @Test
+ public void testValueChangeListener() {
+ getAutocomplete().type("something");
+ getAutocomplete().confirmByKeys();
+ // valueChangeListener output as 4th record
+ waitGui
+ .failWith("Expected <" + format(PHASE_LISTENER_LOG_FORMAT,
"null", "something") + ">, found <" +
selenium.getText(PHASE_FORMAT.format(3)) + ">")
+ .until(textEquals.locator(PHASE_FORMAT.format(3)).text(
+ format(PHASE_LISTENER_LOG_FORMAT, "null",
"something"))
+ );
+
+ getAutocomplete().type("something else");
+ getAutocomplete().confirmByKeys();
+ // valueChangeListener output as 4th record
+ waitGui
+ .failWith("Expected <" + format(PHASE_LISTENER_LOG_FORMAT,
"something", "something else") + ">, found <" +
selenium.getText(PHASE_FORMAT.format(3)) + ">")
+ .until(textEquals.locator(PHASE_FORMAT.format(3)).text(
+ format(PHASE_LISTENER_LOG_FORMAT, "something", "something
else"))
+ );
+ }
+
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java 2011-09-22
09:49:59 UTC (rev 22730)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java 2011-09-22
11:39:32 UTC (rev 22731)
@@ -21,23 +21,17 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richAutocomplete;
-import static org.jboss.test.selenium.RequestTypeModelGuard.guardXhr;
import static org.jboss.test.selenium.RequestTypeModelGuard.guardNoRequest;
+import static org.jboss.test.selenium.RequestTypeModelGuard.guardXhr;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URL;
-import java.util.LinkedList;
-import java.util.List;
-import org.richfaces.tests.metamer.bean.Model;
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
import org.richfaces.tests.metamer.ftest.annotations.Use;
-import org.richfaces.tests.metamer.ftest.model.Autocomplete;
-import org.richfaces.tests.metamer.model.Capital;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -46,10 +40,7 @@
* @version $Revision$
*/
@IssueTracking("https://issues.jboss.org/browse/RF-10254")
-public class TestAutocompleteByKeys extends AbstractMetamerTest {
-
- AutocompleteAttributes attributes = new AutocompleteAttributes();
- Autocomplete autocomplete = new Autocomplete();
+public class TestAutocompleteByKeys extends AbstractAutocompleteTest {
@Inject
@Use(booleans = { true, false })
@@ -59,8 +50,6 @@
@Use(booleans = { true, false })
Boolean selectFirst;
- List<Capital> capitals = Model.unmarshallCapitals();
-
StringBuilder partialInput;
@Override
@@ -70,8 +59,8 @@
@BeforeMethod
public void prepareProperties() {
- attributes.setAutofill(autofill);
- attributes.setSelectFirst(selectFirst);
+ getAttributes().setAutofill(autofill);
+ getAttributes().setSelectFirst(selectFirst);
if (autofill == null) {
autofill = false;
}
@@ -88,7 +77,7 @@
assertCompletionVisible(true);
confirm();
assertCompletionVisible(false);
-
assertTrue(autocomplete.getInputText().toLowerCase().startsWith(getExpectedStateForPrefix().toLowerCase()));
+
assertTrue(getAutocomplete().getInputText().toLowerCase().startsWith(getExpectedStateForPrefix().toLowerCase()));
}
@Test
@@ -104,35 +93,35 @@
}
private void assertCompletionVisible(boolean assertCompletionVisible) {
- assertEquals(autocomplete.isCompletionVisible(), assertCompletionVisible);
+ assertEquals(getAutocomplete().isCompletionVisible(), assertCompletionVisible);
}
public void confirm() {
- autocomplete.confirmByKeys();
- autocomplete.waitForCompletionVisible();
+ getAutocomplete().confirmByKeys();
+ getAutocomplete().waitForCompletionVisible();
}
public void deleteAll() {
partialInput = new StringBuilder();
- autocomplete.textSelectAll();
- guardNoRequest(autocomplete).pressBackspace();
+ getAutocomplete().textSelectAll();
+ guardNoRequest(getAutocomplete()).pressBackspace();
- assertEquals(autocomplete.getInputText(), getExpectedStateForPrefix());
- assertEquals(autocomplete.getSelectedOptionIndex(),
getExpectedSelectedOptionIndex());
+ assertEquals(getAutocomplete().getInputText(), getExpectedStateForPrefix());
+ assertEquals(getAutocomplete().getSelectedOptionIndex(),
getExpectedSelectedOptionIndex());
}
public void typePrefix(String wholeInput) {
- partialInput = new StringBuilder(autocomplete.getInputText());
+ partialInput = new StringBuilder(getAutocomplete().getInputText());
for (int i = 0; i < wholeInput.length(); i++) {
String chr = String.valueOf(wholeInput.charAt(i));
- guardXhr(autocomplete).typeKeys(chr);
+ guardXhr(getAutocomplete()).typeKeys(chr);
partialInput.append(chr);
- assertEquals(autocomplete.getInputText(), getExpectedStateForPrefix());
- assertEquals(autocomplete.getSelectedOptionIndex(),
getExpectedSelectedOptionIndex());
+ assertEquals(getAutocomplete().getInputText(), getExpectedStateForPrefix());
+ assertEquals(getAutocomplete().getSelectedOptionIndex(),
getExpectedSelectedOptionIndex());
}
}
@@ -147,16 +136,4 @@
public int getExpectedSelectedOptionIndex() {
return (selectFirst && partialInput.length() > 0) ? 0 : -1;
}
-
- public List<String> getStatesByPrefix(String prefix) {
- List<String> states = new LinkedList<String>();
-
- for (Capital cap : capitals) {
- if (cap.getState().toLowerCase().startsWith(prefix)) {
- states.add(cap.getState());
- }
- }
-
- return states;
- }
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteVisualState.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteVisualState.java 2011-09-22
09:49:59 UTC (rev 22730)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteVisualState.java 2011-09-22
11:39:32 UTC (rev 22731)
@@ -26,8 +26,6 @@
import java.net.URL;
import org.jboss.test.selenium.utils.URLUtils;
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
-import org.richfaces.tests.metamer.ftest.model.Autocomplete;
import org.testng.annotations.Test;
/**
@@ -39,10 +37,9 @@
* @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
* @version $Revision$
*/
-public class TestAutocompleteVisualState extends AbstractMetamerTest {
+public class TestAutocompleteVisualState extends AbstractAutocompleteTest {
AutocompleteReloadTester reloadTester = new AutocompleteReloadTester();
- Autocomplete autocomplete = new Autocomplete();
@Override
public URL getTestUrl() {
@@ -65,13 +62,13 @@
@Override
public void doRequest(String inputValue) {
// autocomplete.clearInputValue();
- autocomplete.type(inputValue);
+ getAutocomplete().type(inputValue);
waitAjax.until(textEquals.locator(pjq("span[id$=:output]")).text(inputValue));
}
@Override
public void verifyResponse(String inputValue) {
- String found = autocomplete.getInputText();
+ String found = getAutocomplete().getInputText();
assertEquals(found, inputValue);
}