Author: jjamrich
Date: 2011-04-29 09:10:52 -0400 (Fri, 29 Apr 2011)
New Revision: 22456
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageComponentAttributes.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/AbstractRichMessageTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageAttributes.java
Log:
Add tests for remaining rich:message attributes
Implemented tests for rendered, ajaxRendered, showDetail and showSummary
attributes.
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/AbstractRichMessageTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/AbstractRichMessageTest.java 2011-04-29
00:08:15 UTC (rev 22455)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/AbstractRichMessageTest.java 2011-04-29
13:10:52 UTC (rev 22456)
@@ -28,14 +28,12 @@
import static org.testng.Assert.assertTrue;
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.AttributeLocator;
import org.jboss.test.selenium.locator.ElementLocator;
import org.jboss.test.selenium.locator.ExtendedLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.waiting.EventFiredCondition;
-import org.jboss.test.selenium.waiting.ajax.JavaScriptCondition;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,6 +49,8 @@
private static Logger logger =
LoggerFactory.getLogger(AbstractRichMessageTest.class);
+ protected RichMessageComponentAttributes attributes = new
RichMessageComponentAttributes();
+
// controls
protected JQueryLocator wrongValuesBtn =
pjq("input[type=button][id$=setWrongValuesButton]");
protected JQueryLocator correctValuesBtn =
pjq("input[type=button][id$=setCorrectValuesButton]");
@@ -73,7 +73,7 @@
selenium.waitForPageToLoad();
// generate validation message
- generateValidationMessages();
+ generateValidationMessages(false);
assertTrue(selenium.getAttribute(attr).contains(value), "Attribute " +
attribute + " should contain \"" + value
+ "\".");
@@ -96,7 +96,7 @@
guardHttp(selenium).type(eventInput, value);
// generate validation messages
- generateValidationMessages();
+ generateValidationMessages(false);
selenium.fireEvent(element, event);
@@ -119,25 +119,35 @@
selenium.type(ref(attributesRoot, "input[id$=" + attribute +
"Input]"), styleClass);
selenium.waitForPageToLoad();
- generateValidationMessages();
+ generateValidationMessages(false);
JQueryLocator elementWhichHasntThatClass = jq(element.getRawLocator() +
":not(.{0})").format(styleClass);
assertTrue(selenium.isElementPresent(element));
assertFalse(selenium.isElementPresent(elementWhichHasntThatClass));
}
- public void generateValidationMessages() {
+ /**
+ * Set wrong values into appropriate inputs and generate validation
+ * messages by submitting form.
+ *
+ * There are 2 possible ways how to submit: by h:commandButton
+ * or by a4j:commandButton. Switch between them is done by 'byAjax' param
+ *
+ * @param Boolean <b>byAjax</b> - use to choose submit button type used
to submit form
+ */
+ public void generateValidationMessages(Boolean byAjax) {
waitModel.until(elementPresent.locator(wrongValuesBtn));
- selenium.click(wrongValuesBtn);
- waitModel.until(elementPresent.locator(hCommandBtn));
- selenium.click(hCommandBtn);
+ selenium.click(wrongValuesBtn);
+ if (byAjax) {
+ waitModel.until(elementPresent.locator(a4jCommandBtn));
+ selenium.click(a4jCommandBtn);
+ } else {
+ waitModel.until(elementPresent.locator(hCommandBtn));
+ selenium.click(hCommandBtn);
+ }
selenium.waitForPageToLoad();
}
- private AttributeLocator<?> getAttributeLocator(RichMessageAttributes
attribute) {
- return mainMessage.getAttribute(new Attribute(attribute.toString()));
- }
-
private JQueryLocator getInput4Attribute(RichMessageAttributes attribute) {
return pjq("input[id$=" + attribute + "Input]");
}
@@ -154,14 +164,14 @@
// firstly, remove value from attribute for and generate message
selenium.type(getInput4Attribute(RichMessageAttributes.FOR), "");
selenium.waitForPageToLoad();
- generateValidationMessages();
+ generateValidationMessages(false);
// assertFalse(selenium.isElementPresent(mainMessage));
waitGui.until(isNotDisplayed.locator(mainMessage));
// now set for attribute back to "simpleInput2"
selenium.type(getInput4Attribute(RichMessageAttributes.FOR),
"simpleInput2");
selenium.waitForPageToLoad();
- generateValidationMessages();
+ generateValidationMessages(false);
waitGui.until(elementPresent.locator(mainMessage));
}
@@ -172,13 +182,32 @@
@Test
public void testAjaxRendered(){
// with set to false, element with id$=simpleInputMsg shouldn't appear
+
+ // by default is ajaxRendered set to true
+ generateValidationMessages(true);
+ waitGui.until(elementPresent.locator(mainMessage));
+
+ // then disable ajaxRendered
+ attributes.setAjaxRendered(Boolean.FALSE);
+ generateValidationMessages(true);
+ waitGui.until(isNotDisplayed.locator(mainMessage));
}
/**
* This attribute could disable displaying message
*/
+ @Test
public void testRendered(){
// with set to false, element with id$=simpleInputMsg shouldn't appear
+
+ attributes.setRendered(Boolean.TRUE);
+ generateValidationMessages(false);
+ waitGui.until(elementPresent.locator(mainMessage));
+
+ // now disable rendering message
+ attributes.setRendered(Boolean.FALSE);
+ generateValidationMessages(false);
+ waitGui.until(isNotDisplayed.locator(mainMessage));
}
/**
@@ -187,6 +216,14 @@
@Test
public void testShowSummary() {
// span with class=rf-msg-sum should appear when set to true
+
+ JQueryLocator summary = mainMessage.getChild(pjq("span.rf-msg-sum"));
+
+ attributes.setShowSummary(Boolean.TRUE);
+ waitGui.until(elementPresent.locator(summary));
+
+ attributes.setShowSummary(Boolean.FALSE);
+ waitGui.until(isNotDisplayed.locator(summary));
}
/**
@@ -194,7 +231,15 @@
*/
@Test
public void testShowDetail() {
- // span with class=rf-msg-det should appear when set to true
+ // span with class=rf-msg-det should appear when set to true
+
+ JQueryLocator detail = mainMessage.getChild(pjq("span.rf-msg-det"));
+
+ attributes.setShowDetail(Boolean.TRUE);
+ waitGui.until(elementPresent.locator(detail));
+
+ attributes.setShowDetail(Boolean.FALSE);
+ waitGui.until(isNotDisplayed.locator(detail));
}
@Test
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageAttributes.java 2011-04-29
00:08:15 UTC (rev 22455)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageAttributes.java 2011-04-29
13:10:52 UTC (rev 22456)
@@ -10,8 +10,9 @@
* @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
* @version $Revision$
*/
-public enum RichMessageAttributes {
+public enum RichMessageAttributes {
AJAX_RENDERED ("ajaxRendered"),
+ RENDERED ("rendered"),
DIR ("dir"),
FOR ("for"),
LANG ("lang"),
@@ -30,5 +31,4 @@
public String toString() {
return value;
}
-}
-
+}
\ No newline at end of file
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageComponentAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageComponentAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richMessage/RichMessageComponentAttributes.java 2011-04-29
13:10:52 UTC (rev 22456)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.richMessage;
+
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * Component attributes for rich:message
+ *
+ * @author <a href="mailto:jjamrich@redhat.com">Jan Jamrich</a>
+ * @version $Revision$
+ */
+public class RichMessageComponentAttributes extends AbstractComponentAttributes {
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+
+ public void setAjaxRendered(Boolean rendered) {
+ setProperty("ajaxRendered", rendered);
+ }
+
+ public void setShowDetail(Boolean showDetail){
+ setProperty("showDetail", showDetail);
+ }
+
+ public void setShowSummary(Boolean showSummary){
+ setProperty("showSummary", showSummary);
+ }
+
+}