Author: lfryc(a)redhat.com
Date: 2009-09-14 10:25:43 -0400 (Mon, 14 Sep 2009)
New Revision: 15555
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dragSupport/DragSupportTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/locators.properties
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/messages.properties
Log:
- refactored Drag Support test cases to follow conventions
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dragSupport/DragSupportTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dragSupport/DragSupportTestCase.java 2009-09-14
14:04:14 UTC (rev 15554)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dragSupport/DragSupportTestCase.java 2009-09-14
14:25:43 UTC (rev 15555)
@@ -1,3 +1,24 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.jboss.richfaces.integrationTest.dragSupport;
import java.util.regex.Pattern;
@@ -2,3 +23,3 @@
-import junit.framework.Assert;
+import static org.testng.Assert.*;
@@ -8,6 +29,7 @@
import org.jboss.test.selenium.actions.Drag;
import org.jboss.test.selenium.waiting.Condition;
import org.jboss.test.selenium.waiting.Wait;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
@@ -15,70 +37,85 @@
* @version $Revision$
*/
public class DragSupportTestCase extends AbstractSeleniumRichfacesTestCase {
- {
- // each test will be ran in separated browser session
- setCleanSessionForEachMethod(true);
- }
-
+
+ private final String LOC_FIELDSET_HEADER = getLoc("FIELDSET_HEADER");
+ private final String LOC_DIV_DRAG_INDICATOR = getLoc("DIV_DRAG_INDICATOR");
+ private final String LOC_CLASS_DRAG_INDICATOR =
getLoc("CLASS_DRAG_INDICATOR");
+ private final String LOC_IMGSRC_DRAG_INDICATOR =
getLoc("IMGSRC_DRAG_INDICATOR");
+ private final String LOC_CHOICES_OF_DIV_TARGETS =
getLoc("CHOICES_OF_DIV_TARGETS");
+ private final String LOC_DIV_FIRST_INSERTED_ITEM_RELATIVE =
getLoc("DIV_FIRST_INSERTED_ITEM_RELATIVE");
+ private final String LOC_DIV_DRAGGED_ITEM_PREFORMATTED =
getLoc("DIV_DRAGGED_ITEM_PREFORMATTED");
+
+ private final String MSG_CHOICES_FRAMEWORKS = getMsg("CHOICES_FRAMEWORKS");
+ private final String MSG_REGEXP_CLASS_OF_MOVING =
getMsg("REGEXP_CLASS_OF_MOVING");
+ private final String MSG_REGEXP_IMGSRC_OF_MOVING =
getMsg("REGEXP_IMGSRC_OF_MOVING");
+ private final String MSG_REGEXP_CLASS_OF_ACCEPTING =
getMsg("REGEXP_CLASS_OF_ACCEPTING");
+ private final String MSG_REGEXP_IMGSRC_OF_ACCEPTING =
getMsg("REGEXP_IMGSRC_OF_ACCEPTING");
+ private final String MSG_REGEXP_CLASS_OF_REJECTING =
getMsg("REGEXP_CLASS_OF_REJECTING");
+ private final String MSG_REGEXP_IMGSRC_OF_REJECTING =
getMsg("REGEXP_IMGSRC_OF_REJECTING");
+
/**
- * Opens specified page
+ * Drag item to accepting target and checks that drag indicator is present
+ * before start dragging and has 'display: none'. Then start drag and checks
+ * that indicator goes displayed and checks that image source of dragged
+ * item and its class is as expecting.
*/
- private void openPage() {
- selenium.open(contextPath
- + "/richfaces/dragSupport.jsf?c=dragSupport&tab=usage");
- scrollIntoView(header, true);
- }
-
- private String header = getLoc("drag-support--header");
- private String indicator = getLoc("drag-support--div--indicator");
- private String classIndicator = getLoc("drag-support--class--indicator");
- private String imageSourceIndicator =
getLoc("drag-support--image-source--indicator");
- private String itemTexts = getMess("drag-support--text--items");
- private String itemPattern = getLoc("drag-support--div--item");
- private String targets = getLoc("drag-support--div--targets");
- private String relativeFirstInsertedItem =
getLoc("drag-support--relative--first-inserted-item");
- private String regexpMovingClass =
getMess("drag-support--regexp--moving--class");
- private String regexpMovingImageSource =
getMess("drag-support--regexp--moving--image-source");
- private String regexpAcceptingClass =
getMess("drag-support--regexp--accepting--class");
- private String regexpAcceptingImageSource =
getMess("drag-support--regexp--accepting--image-source");
- private String regexpRejectingClass =
getMess("drag-support--regexp--rejecting--class");
- private String regexpRejectingImageSource =
getMess("drag-support--regexp--rejecting--image-source");
-
@Test
public void testMoving() {
accepting(0);
}
+ /**
+ * Drag item to accepting target. Checks that when enter target item the
+ * indicator changed class and image's src to accepting ones (as
+ * predefined).
+ */
@Test
public void testAcceptingEnter() {
accepting(1);
}
+ /**
+ * Drag item to accepting target. Checks that when item entered target, the
+ * first item is still in framework list, and when dropped, wait for drag
+ * indicator disappear, then checks that dragged item already disappeared
+ * from framework list and also appeared in drag target (box).
+ */
@Test
public void testAcceptingDrop() {
accepting(2);
}
+ /**
+ * Drad item to rejecting target. Checks that when item entered rejecting
+ * target, the drag indicator (check its img-src and class) changes to
+ * rejecting one.
+ */
@Test
public void testRejectingEnter() {
rejecting(1);
}
+ /**
+ * Drag item to rejecting target. Checks that when item dropped on rejecting
+ * target, no item will appear in target and no item disappear from
+ * framework list.
+ */
@Test
public void testRejectingDrop() {
rejecting(2);
}
private void accepting(int phase) {
- openPage();
+ String itemText = format(MSG_CHOICES_FRAMEWORKS, 1);
+ String item = format(LOC_DIV_DRAGGED_ITEM_PREFORMATTED, itemText);
+ String target = format(LOC_CHOICES_OF_DIV_TARGETS, 1);
- String itemText = format(itemTexts, 1);
- String item = format(itemPattern, itemText);
- String target = format(targets, 1);
-
if (phase == 0) {
- Assert.assertTrue(selenium.isElementPresent(indicator));
- Assert.assertEquals("none", getStyle(indicator, "display"));
+ assertTrue(selenium.isElementPresent(LOC_DIV_DRAG_INDICATOR),
+ "Drag indicator isn't present (in DOM) at initial state");
+ assertEquals(getStyle(LOC_DIV_DRAG_INDICATOR, "display"), "none",
+ "Drag indicator is displayed as not expected");
}
Drag drag = new Drag(selenium, item, target);
@@ -86,64 +123,71 @@
drag.move();
if (phase == 0) {
- Wait.until(new Condition() {
+ Wait.failWith("Drag indicator never get displayed").until(new Condition() {
public boolean isTrue() {
- return "block".equals(getStyle(indicator, "display"));
+ return "block".equals(getStyle(LOC_DIV_DRAG_INDICATOR,
"display"));
}
});
- Assert.assertTrue(Pattern.matches(regexpMovingClass, selenium
- .getAttribute(classIndicator)));
- Assert.assertTrue(Pattern.matches(regexpMovingImageSource, selenium
- .getAttribute(imageSourceIndicator)));
+ String actual = selenium.getAttribute(LOC_CLASS_DRAG_INDICATOR);
+ assertTrue(Pattern.matches(MSG_REGEXP_CLASS_OF_MOVING, actual), format(
+ "The class of indicator '{0}' doesn't match '{1}'",
actual, MSG_REGEXP_CLASS_OF_MOVING));
+
+ actual = selenium.getAttribute(LOC_IMGSRC_DRAG_INDICATOR);
+ assertTrue(Pattern.matches(MSG_REGEXP_IMGSRC_OF_MOVING, actual), format(
+ "The image source of indicator '{0}' doesn't match '{1}",
actual, MSG_REGEXP_IMGSRC_OF_MOVING));
}
drag.enter();
if (phase == 1) {
- Wait.until(new Condition() {
+ Wait.failWith("Drag indicator wasn't displayed").until(new Condition()
{
public boolean isTrue() {
- return "block".equals(getStyle(indicator, "display"));
+ return "block".equals(getStyle(LOC_DIV_DRAG_INDICATOR,
"display"));
}
});
- Assert.assertEquals("block", getStyle(indicator, "display"));
- Assert.assertTrue(Pattern.matches(regexpAcceptingClass, selenium
- .getAttribute(classIndicator)));
- Assert.assertTrue(Pattern.matches(regexpAcceptingImageSource,
- selenium.getAttribute(imageSourceIndicator)));
+ String actual = selenium.getAttribute(LOC_CLASS_DRAG_INDICATOR);
+ assertTrue(Pattern.matches(MSG_REGEXP_CLASS_OF_ACCEPTING, actual), format(
+ "The class of indicator '{0}' doesn't match '{1}'",
actual, MSG_REGEXP_CLASS_OF_ACCEPTING));
+
+ actual = selenium.getAttribute(LOC_IMGSRC_DRAG_INDICATOR);
+ assertTrue(Pattern.matches(MSG_REGEXP_IMGSRC_OF_ACCEPTING, actual), format(
+ "The image source of indicator '{0}' doesn't match '{1}",
actual, MSG_REGEXP_IMGSRC_OF_ACCEPTING));
}
- String firstInsertedItem = format(relativeFirstInsertedItem, target);
+ String firstInsertedItem = format(LOC_DIV_FIRST_INSERTED_ITEM_RELATIVE, target);
if (phase == 2) {
- Assert.assertFalse(selenium.isElementPresent(firstInsertedItem));
+ assertFalse(selenium.isElementPresent(firstInsertedItem),
+ "There was one item inserted to target, but there was expected no item");
}
drag.drop();
if (phase == 2) {
- Wait.until(new Condition() {
+ Wait.failWith("Drag indicator never disappeared when item
dropped").until(new Condition() {
public boolean isTrue() {
- return "none".equals(getStyle(indicator, "display"));
+ return "none".equals(getStyle(LOC_DIV_DRAG_INDICATOR,
"display"));
}
});
- Assert.assertTrue(selenium.isElementPresent(firstInsertedItem));
- Assert.assertFalse(selenium.isElementPresent(item));
+ assertTrue(selenium.isElementPresent(firstInsertedItem),
+ "There was no item inserted in target after drop of accepting item");
+ assertFalse(selenium.isElementPresent(item),
+ "The dragged item was still in framework list after drop to accepting
target");
String actual = selenium.getText(firstInsertedItem);
- Assert.assertEquals(itemText, actual);
+ assertEquals(itemText, actual,
+ "The text of first inserted item to target and previously dragged item
isn't same");
}
}
private void rejecting(int phase) {
- openPage();
+ String itemText = format(MSG_CHOICES_FRAMEWORKS, 1);
+ String item = format(LOC_DIV_DRAGGED_ITEM_PREFORMATTED, itemText);
+ String target = format(LOC_CHOICES_OF_DIV_TARGETS, 2);
- String itemText = format(itemTexts, 1);
- String item = format(itemPattern, itemText);
- String target = format(targets, 2);
-
Drag drag = new Drag(selenium, item, target);
drag.move();
drag.enter();
@@ -151,33 +195,47 @@
if (phase == 1) {
Wait.until(new Condition() {
public boolean isTrue() {
- return "block".equals(getStyle(indicator, "display"));
+ return "block".equals(getStyle(LOC_DIV_DRAG_INDICATOR,
"display"));
}
});
- Assert.assertTrue(Pattern.matches(regexpRejectingClass, selenium
- .getAttribute(classIndicator)));
- Assert.assertTrue(Pattern.matches(regexpRejectingImageSource,
- selenium.getAttribute(imageSourceIndicator)));
+ String actual = selenium.getAttribute(LOC_CLASS_DRAG_INDICATOR);
+ assertTrue(Pattern.matches(MSG_REGEXP_CLASS_OF_REJECTING, actual), format(
+ "The class of indicator '{0}' doesn't match '{1}'",
actual, MSG_REGEXP_CLASS_OF_REJECTING));
+
+ actual = selenium.getAttribute(LOC_IMGSRC_DRAG_INDICATOR);
+ assertTrue(Pattern.matches(MSG_REGEXP_IMGSRC_OF_REJECTING, actual), format(
+ "The image source of indicator '{0}' doesn't match '{1}",
actual, MSG_REGEXP_IMGSRC_OF_REJECTING));
}
- String firstInsertedItem = format(relativeFirstInsertedItem, target);
+ String firstInsertedItem = format(LOC_DIV_FIRST_INSERTED_ITEM_RELATIVE, target);
if (phase == 2) {
- Assert.assertFalse(selenium.isElementPresent(firstInsertedItem));
+ assertFalse(selenium.isElementPresent(firstInsertedItem),
+ "There was one item inserted to target, but no item expected");
}
drag.drop();
if (phase == 2) {
- Wait.until(new Condition() {
+ Wait.failWith("Drag indicator never disappeared when item
dropped").until(new Condition() {
public boolean isTrue() {
- return "none".equals(getStyle(indicator, "display"));
+ return "none".equals(getStyle(LOC_DIV_DRAG_INDICATOR,
"display"));
}
});
- Assert.assertFalse(selenium.isElementPresent(firstInsertedItem));
- Assert.assertTrue(selenium.isElementPresent(item));
+ assertFalse(selenium.isElementPresent(firstInsertedItem),
+ "There was item inserted in target but no item expected when dropped to
rejecting target");
+ assertTrue(selenium.isElementPresent(item),
+ "The dragged item disappeared as not expected when dropped to rejecting
target");
}
}
+
+ @SuppressWarnings("unused")
+ @BeforeMethod
+ private void loadPage() {
+ openComponent("Drag Support");
+ scrollIntoView(LOC_FIELDSET_HEADER, true);
+ selenium.allowNativeXpath("true");
+ }
}
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/locators.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/locators.properties 2009-09-14
14:04:14 UTC (rev 15554)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/locators.properties 2009-09-14
14:25:43 UTC (rev 15555)
@@ -1,7 +1,7 @@
-drag-support--header=//legend[text()\='Drag-n-Drop example']
-drag-support--div--targets=//div[text()\='{0,choice,1\#PHP
Frameworks|2\#.NET
Frameworks|3\#ColdFusion Frameworks}']/../../div
-drag-support--div--item=//table[contains(@id,'src')]//div[text()\='{0}']
-drag-support--div--indicator=//*[@id\='indicator']
-drag-support--class--indicator=//*[@id\='indicator']/@class
-drag-support--image-source--indicator=//*[@id\='indicator']//td[1]/img/@src
-drag-support--relative--first-inserted-item={0}/*[2]/*[2]/*/*/*[1]
+FIELDSET_HEADER=//legend[text()\='Drag-n-Drop example']
+CHOICES_OF_DIV_TARGETS=//div[text()\='{0,choice,1\#PHP
Frameworks|2\#.NET
Frameworks|3\#ColdFusion Frameworks}']/../../div
+DIV_DRAGGED_ITEM_PREFORMATTED=//table[contains(@id,'src')]//div[text()\='{0}']
+DIV_DRAG_INDICATOR=//*[@id\='indicator']
+CLASS_DRAG_INDICATOR=//*[@id\='indicator']/@class
+IMGSRC_DRAG_INDICATOR=//*[@id\='indicator']//td[1]/img/@src
+DIV_FIRST_INSERTED_ITEM_RELATIVE={0}/*[2]/*[2]/*/*/*[1]
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/messages.properties
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/messages.properties 2009-09-14
14:04:14 UTC (rev 15554)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/resources/org/jboss/richfaces/integrationTest/dragSupport/messages.properties 2009-09-14
14:25:43 UTC (rev 15555)
@@ -1,7 +1,7 @@
-drag-support--regexp--moving--image-source=.*/default\\.gif\\.jsf$
-drag-support--regexp--moving--class=.*(^|\\s+)drgind_default($|\\s+).*
-drag-support--regexp--accepting--image-source=.*/accept\\.gif\\.jsf$
-drag-support--regexp--accepting--class=.*(^|\\s+)drgind_accept($|\\s+).*
-drag-support--regexp--rejecting--image-source=.*/reject\\.gif\\.jsf$
-drag-support--regexp--rejecting--class=.*(^|\\s+)drgind_reject($|\\s+).*
-drag-support--text--items={0,choice,1\#Flexible
Ajax|2\#ajaxCFC|3\#AJAXEngine|4\#AjaxAC|5\#MonoRail|6\#wddxAjax|7\#AJAX
AGENT|8\#FastPane|9\#JSMX|10\#PAJAJ|11\#Symfony|12\#PowerWEB}
+REGEXP_IMGSRC_OF_MOVING=.*/default\\.gif\\.jsf$
+REGEXP_CLASS_OF_MOVING=.*(^|\\s+)drgind_default($|\\s+).*
+REGEXP_IMGSRC_OF_ACCEPTING=.*/accept\\.gif\\.jsf$
+REGEXP_CLASS_OF_ACCEPTING=.*(^|\\s+)drgind_accept($|\\s+).*
+REGEXP_IMGSRC_OF_REJECTING=.*/reject\\.gif\\.jsf$
+REGEXP_CLASS_OF_REJECTING=.*(^|\\s+)drgind_reject($|\\s+).*
+CHOICES_FRAMEWORKS={0,choice,1\#Flexible
Ajax|2\#ajaxCFC|3\#AJAXEngine|4\#AjaxAC|5\#MonoRail|6\#wddxAjax|7\#AJAX
AGENT|8\#FastPane|9\#JSMX|10\#PAJAJ|11\#Symfony|12\#PowerWEB}