Author: jpapouse
Date: 2011-07-27 04:48:15 -0400 (Wed, 27 Jul 2011)
New Revision: 22568
Added:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/AbstractNotifyTest.java
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotifyMoreStacks.java
Modified:
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java
modules/tests/metamer/branches/sandbox-components/application/src/main/webapp/components/notify/moreStacks.xhtml
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java
Log:
RFPL-1504: inserted test for two stacks
Modified:
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java 2011-07-26
11:26:58 UTC (rev 22567)
+++
modules/tests/metamer/branches/sandbox-components/application/src/main/java/org/richfaces/tests/metamer/bean/NotifyBean.java 2011-07-27
08:48:15 UTC (rev 22568)
@@ -161,11 +161,9 @@
int messageCount =
Integer.valueOf((String)attributesBean.get("messageCount").getValue());
String text = (String) attributesBean.get("messageText").getValue();
String detail = (String)
attributesBean.get("messageDetail").getValue();
- logger.info("starting message production (" + messageCount +
")[" + severity + "][" + text + "].");
for(int i=0; i<messageCount; i++) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity,
text, detail));
}
- logger.info("finishing message production (" + messageCount +
")[" + severity + "][" + text + "].");
}
private Attributes getGeneralAttributes() {
Modified:
modules/tests/metamer/branches/sandbox-components/application/src/main/webapp/components/notify/moreStacks.xhtml
===================================================================
---
modules/tests/metamer/branches/sandbox-components/application/src/main/webapp/components/notify/moreStacks.xhtml 2011-07-26
11:26:58 UTC (rev 22567)
+++
modules/tests/metamer/branches/sandbox-components/application/src/main/webapp/components/notify/moreStacks.xhtml 2011-07-27
08:48:15 UTC (rev 22568)
@@ -160,13 +160,13 @@
styleClass="#{notifyBean.attributesNotifyStackSecond['styleClass'].value}"
/>
- <h:outputLabel for="number1" value="Number for Stack
1"/>
+ <h:outputLabel for="number1" value="Number for Stack 1
(from 5 to 10)"/>
<h:inputText id="number1" required="true">
<f:validateLongRange minimum="5"
maximum="10"/>
<a4j:ajax event="change" execute="@form"/>
</h:inputText>
<br />
- <h:outputLabel for="number2" value="Number for Stack
2"/>
+ <h:outputLabel for="number2" value="Number for Stack 2
(from 5 to 10)"/>
<h:inputText id="number2" required="true">
<f:validateLongRange minimum="5"
maximum="10"/>
<a4j:ajax event="change" execute="@form"/>
@@ -184,8 +184,6 @@
<metamer:attributes
value="#{notifyBean.attributesNotifyStackFirst}"
id="attributesNotifyStack1" render="panel"/>
<h2>Attributes - Notify Stack 2</h2>
<metamer:attributes
value="#{notifyBean.attributesNotifyStackSecond}"
id="attributesNotifyStack2" render="panel"/>
- <h2>Attributes - Bean</h2>
- <metamer:attributes value="#{notifyBean.attributesBean}"
id="attributesBean" render="panel"/>
</ui:define>
</ui:composition>
Added:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/AbstractNotifyTest.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/AbstractNotifyTest.java
(rev 0)
+++
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/AbstractNotifyTest.java 2011-07-27
08:48:15 UTC (rev 22568)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.notify;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+
+/**
+ * Abstract test case for pages faces/components/notify/
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public abstract class AbstractNotifyTest extends AbstractMetamerTest {
+
+ protected JQueryLocator notify = jq("div.rf-ny");
+ protected JQueryLocator notifyError = jq("div.rf-ny-error");
+ protected JQueryLocator notifyFatal = jq("div.rf-ny-fatal");
+ protected JQueryLocator notifyInfo = jq("div.rf-ny-info");
+ protected JQueryLocator notifyWarn = jq("div.rf-ny-warn");
+
+ protected void close(final JQueryLocator locator) {
+ final int before = selenium.getCount(locator);
+ selenium.click(getFirstCloseButton(locator));
+ waitGui
+ .failWith("Message " + locator.getRawLocator() + " can't
be closed.")
+ .until(countEquals.locator(locator).count(before - 1));
+ }
+
+ protected void delay(int ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING, e.toString());
+ }
+ }
+
+ protected JQueryLocator getCloseButton(JQueryLocator message) {
+ return jq(message.getRawLocator() + " > div.rf-ny-co > div.rf-ny-cl
> span.rf-ny-cl-ic");
+ }
+
+ protected JQueryLocator getFirstCloseButton(JQueryLocator message) {
+ return jq(getCloseButton(message).getRawLocator() + ":first");
+ }
+
+ protected int getNumberOfNotifies() {
+ return selenium.getCount(notify) - (selenium.getCount(notifyError) +
selenium.getCount(notifyFatal) + selenium.getCount(notifyInfo) +
selenium.getCount(notifyWarn));
+ }
+
+ protected void produceMessage(final JQueryLocator message, String type, final int
expected) {
+ final int before = selenium.getCount(message);
+ selenium.click(pjq("input[id$=produce" + type + "]"));
+ waitGui
+ .failWith("Number of produced messages has been set to <" +
expected + "> but <" + selenium.getCount(message) + "> " +
type + " messages is present.")
+ .until(countEquals.locator(message).count(expected + before));
+ }
+
+}
Modified:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java 2011-07-26
11:26:58 UTC (rev 22567)
+++
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotify.java 2011-07-27
08:48:15 UTC (rev 22568)
@@ -26,39 +26,27 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertEquals;
import static org.jboss.test.selenium.locator.LocatorFactory.jq;
-
import org.jboss.test.selenium.css.CssProperty;
import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.waiting.NegationCondition;
import org.jboss.test.selenium.waiting.selenium.SeleniumCondition;
-import org.junit.Ignore;
import org.richfaces.tests.metamer.bean.NotifyBean;
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
- * Abstract test case for pages faces/components/notify/simple.xhtml
+ * Test case for pages faces/components/notify/simple.xhtml
*
* @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
*/
-public class TestNotify extends AbstractMetamerTest {
+public class TestNotify extends AbstractNotifyTest {
- private JQueryLocator notify = jq("div.rf-ny");
- private JQueryLocator notifyError = jq("div.rf-ny-error");
- private JQueryLocator notifyFatal = jq("div.rf-ny-fatal");
- private JQueryLocator notifyInfo = jq("div.rf-ny-info");
- private JQueryLocator notifyWarn = jq("div.rf-ny-warn");
- private JQueryLocator notifyStack = jq("div.rf-ny");
+ private JQueryLocator notifyStack = jq("div.rf-ny");
private Map<String, JQueryLocator> messages = new HashMap<String,
JQueryLocator>();
@BeforeClass
@@ -76,14 +64,14 @@
@Test
public void testAttributeDelay() {
- JQueryLocator attribute =
pjq("input[name*='attributesNotify:delayInput']");
+ JQueryLocator attribute =
pjq("input[id$='attributesNotify:delayInput']");
selenium.type(attribute, "1000");
selenium.fireEvent(attribute, Event.BLUR);
selenium.waitForPageToLoad();
delay(500);
- assertFalse(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some little waiting the notify is still present.");
+ assertFalse(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some little waiting the notify shouldn't be present.");
delay(1000);
- assertTrue(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some waiting the notify is not present.");
+ assertTrue(selenium.isElementPresent(notify), "The delay is set to 1000 and
after some waiting the notify should be present.");
}
@Test
@@ -99,6 +87,39 @@
selenium.waitForPageToLoad();
assertTrue(selenium.getStyle(jq(notify.getRawLocator() + " > div.rf-ny-co
> div.rf-ny-cl"), new
CssProperty("visibility")).contains("hidden"), "The
showCloseButton is set to <false> and therefore the close button shouldn't be
displayed.");
}
+
+ @Test
+ public void testAttributeShowHistory() {
+ JQueryLocator history = jq("div.rf-ny-hc");
+ assertFalse(selenium.isElementPresent(history), "The showHistory is set to
<false> and there shouldn't be any history menu.");
+
selenium.click(pjq("input[type=radio][name*='attributesNotify:showHistory'][value=true]"));
+ selenium.waitForPageToLoad();
+ assertTrue(selenium.isElementPresent(history), "The showHistory is set to
<true> and one notify is present, but there is no history menu.");
+ close(notify);
+ produceMessage(notifyError, "Error", 1);
+ close(notify);
+ close(notify);
+ selenium.click(jq("button.rf-ny-ha"));
+ waitModel
+ .failWith("After clicking on <All> in history menu there should be
all notifies. Expected <2>, found <" + getNumberOfNotifies() +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return getNumberOfNotifies() == 2;
+ }
+ });
+ close(notify);
+ close(notify);
+ selenium.click(jq("button.rf-ny-hl"));
+ waitModel
+ .failWith("After clicking on <Last> in history menu there should
be last notify. Expected <1>, found <" + getNumberOfNotifies() +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return getNumberOfNotifies() == 1;
+ }
+ });
+ }
@Test
public void testAttributesStayTime() {
@@ -127,16 +148,16 @@
@Test(enabled=false)
public void testAttributeMessagesDelay() {
- JQueryLocator attribute =
pjq("input[name*='attributesNotifyMessages:delayInput']");
+ JQueryLocator attribute =
jq("input[id$='attributesNotifyMessages:delayInput']");
selenium.type(attribute, "1000");
selenium.fireEvent(attribute, Event.BLUR);
selenium.waitForPageToLoad();
for(String type : messages.keySet()) {
selenium.click(pjq("input[id$=produce" + type + "]"));
delay(500);
- assertFalse(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some little waiting the " + type + " message is still
present.");
+ assertFalse(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some little waiting the " + type + " message shouldn't
be present.");
delay(1000);
- assertTrue(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some waiting the " + type + " message is not
present.");
+ assertTrue(selenium.isElementPresent(messages.get(type)), "The delay is
set to 1000 and after some waiting the " + type + " message should be
present.");
}
}
@@ -145,9 +166,9 @@
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:rendered'][value=false]"));
selenium.waitForPageToLoad();
for(String type : messages.keySet()) {
+ String before = selenium.getText(jq("span[id=requestTime]"));
selenium.click(pjq("input[id$=produce" + type + "]"));
- String before = selenium.getText(jq("span[id=requestTime]"));
-
waitGui.until(textEquals.locator(jq("span[id=requestTime]")).text(before));
+
waitGui.until(NegationCondition.getInstance().condition(textEquals.locator(jq("span[id=requestTime]")).text(before)));
assertFalse(selenium.isElementPresent(messages.get(type)), "The
attribute rendered is set to <false> but the " + type + " message is still
present.");
}
}
@@ -176,6 +197,43 @@
}
@Test
+ public void testAttributeMessagesShowHistory() {
+ close(notify);
+ JQueryLocator history = jq("div.rf-ny-hc");
+ assertFalse(selenium.isElementPresent(history), "The showHistory is set to
<false> and there shouldn't be any history menu.");
+
selenium.click(pjq("input[type=radio][name*='attributesNotifyMessages:showHistory'][value=true]"));
+ selenium.waitForPageToLoad();
+ assertFalse(selenium.isElementPresent(history), "The showHistory is set to
<true>, but there is no message, so there shouldn't be any history
menu.");
+ for(String type : messages.keySet()) {
+ produceMessage(messages.get(type), type, 1);
+ close(notify);
+ close(notify);
+ }
+ selenium.click(jq("button.rf-ny-ha"));
+ final int expected = messages.size();
+ waitModel
+ .failWith("After clicking on <All> in history menu there should be
all messages. Expected <" + expected + ">, found <" +
selenium.getCount(notify) + ">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return selenium.getCount(notify) == expected;
+ }
+ });
+ for(int i=0; i<expected; i++) {
+ close(notify);
+ }
+ selenium.click(jq("button.rf-ny-hl"));
+ waitModel
+ .failWith("After clicking on <Last> in history menu there should
be last message. Expected <1>, found <" + selenium.getCount(notify) +
">")
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return selenium.getCount(notify) == 1;
+ }
+ });
+ }
+
+ @Test
public void testAttributeMessagesStayTime() {
for(String type : messages.keySet()) {
produceMessage(messages.get(type), type, 1);
@@ -280,40 +338,4 @@
close(message);
}
}
-
- private void close(final JQueryLocator locator) {
- final int before = selenium.getCount(locator);
- selenium.click(getFirstCloseButton(locator));
- waitGui
- .failWith("Message " + locator.getRawLocator() + " can't
be closed.")
- .until(countEquals.locator(locator).count(before - 1));
- }
-
- private void delay(int ms) {
- try {
- Thread.sleep(ms);
- } catch (InterruptedException e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING, e.toString());
- }
- }
-
- private JQueryLocator getCloseButton(JQueryLocator message) {
- return jq(message.getRawLocator() + " > div.rf-ny-co > div.rf-ny-cl
> span.rf-ny-cl-ic");
- }
-
- private JQueryLocator getFirstCloseButton(JQueryLocator message) {
- return jq(getCloseButton(message).getRawLocator() + ":first");
- }
-
- private int getNumberOfNotifies() {
- return selenium.getCount(notify) - (selenium.getCount(notifyError) +
selenium.getCount(notifyFatal) + selenium.getCount(notifyInfo) +
selenium.getCount(notifyWarn));
- }
-
- private void produceMessage(final JQueryLocator message, String type, final int
expected) {
- final int before = selenium.getCount(message);
- selenium.click(pjq("input[id$=produce" + type + "]"));
- waitGui
- .failWith("Number of produced messages has been set to <" +
expected + "> but <" + selenium.getCount(notifyError) + "> "
+ type + " messages is present.")
- .until(countEquals.locator(message).count(expected + before));
- }
}
Added:
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotifyMoreStacks.java
===================================================================
---
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotifyMoreStacks.java
(rev 0)
+++
modules/tests/metamer/branches/sandbox-components/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/notify/TestNotifyMoreStacks.java 2011-07-27
08:48:15 UTC (rev 22568)
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * 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.notify;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertEquals;
+import java.net.URL;
+import java.util.logging.Logger;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.annotations.Test;
+
+
+/**
+ * Test case for pages faces/components/notify/moreStacks.xhtml
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestNotifyMoreStacks extends AbstractNotifyTest {
+
+ private JQueryLocator stack1 = jq("div.topRight");
+ private JQueryLocator stack2 = jq("div.bottomRight");
+ private JQueryLocator number1 = pjq("input[id$=number1]");
+ private JQueryLocator number2 = pjq("input[id$=number2]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/notify/moreStacks.xhtml");
+ }
+
+ @Test
+ public void testInit() {
+ assertTrue(selenium.isElementPresent(stack1), "The first stack is not
present.");
+ assertTrue(selenium.isElementPresent(stack2), "The second stack is not
present.");
+ assertTrue(selenium.isElementPresent(inStack(stack1, notify)), "The notify
in the first stack is not present.");
+ assertTrue(selenium.isElementPresent(inStack(stack2, notify)), "The notify
in the second stack is not present.");
+ assertEquals(1, getNumberOfNotifies(stack1), "The initial number of notifies
in the first stack should be <1>, found <" + getNumberOfNotifies(stack1) +
">.");
+ assertEquals(1, getNumberOfNotifies(stack2), "The initial number of notifies
in the second stack should be <1>, found <" + getNumberOfNotifies(stack2) +
">.");
+ }
+
+ @Test
+ public void testValidationError() {
+ close(inStack(stack1, notify));
+ close(inStack(stack2, notify));
+ JQueryLocator message1 = inStack(stack1, notify);
+ JQueryLocator message2 = inStack(stack2, notify);
+
+ selenium.type(number1, "1");
+ selenium.fireEvent(number1, Event.BLUR);
+ delay(1000);
+ waitGui
+ .failWith("After wrong filling the first form field the number of
messages in the first stack should be <1>, found <" +
selenium.getCount(message1) + ">")
+ .until(countEquals.locator(message1).count(1));
+ waitGui
+ .failWith("After wrong filling the first form field the number of
messages in the second stack should be <0>, found <" +
selenium.getCount(message2) + ">")
+ .until(countEquals.locator(message1).count(0));
+
+ close(message1);
+ close(message2);
+
+ selenium.type(number2, "1");
+ selenium.fireEvent(number2, Event.BLUR);
+ delay(1000);
+ waitGui
+ .failWith("After wrong filling the second form field the number of
messages in the second stack should be <1>, found <" +
selenium.getCount(message2) + ">")
+ .until(countEquals.locator(message1).count(1));
+ waitGui
+ .failWith("After wrong filling the second form field the number of
messages in the first stack should be <0>, found <" +
selenium.getCount(message1) + ">")
+ .until(countEquals.locator(message1).count(0));
+ }
+
+ private int getNumberOfNotifies(JQueryLocator stack) {
+ return selenium.getCount(inStack(stack, notify)) -
(selenium.getCount(inStack(stack, notifyError)) + selenium.getCount(inStack(stack,
notifyFatal)) + selenium.getCount(inStack(stack, notifyInfo)) +
selenium.getCount(inStack(stack, notifyWarn)));
+ }
+
+ private JQueryLocator inStack(JQueryLocator stack, JQueryLocator message) {
+ // FIXME
+ String[] splittedMessageLocator = message.getAsString().split("\\.");
+ String[] splittedStackLocator = stack.getAsString().split("\\.");
+ String locator = null;
+ if (splittedMessageLocator[splittedMessageLocator.length -
1].equals("rf-ny")) {
+ locator = "div[class*=" +
splittedMessageLocator[splittedMessageLocator.length - 1] + " " +
splittedStackLocator[splittedStackLocator.length - 1] + "]";
+ }
+ else {
+ locator = "div[class*=" +
splittedStackLocator[splittedStackLocator.length - 1] + " " +
splittedMessageLocator[splittedMessageLocator.length - 1] + "]";
+ }
+ return jq(locator);
+ }
+
+}