Author: lfryc(a)redhat.com
Date: 2011-01-28 08:09:13 -0500 (Fri, 28 Jan 2011)
New Revision: 21301
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/DragIndicatorAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Draggable.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Droppable.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Indicator.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/TestDragIndicator.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/RequestTypeModelGuard.java
Log:
rich:dragIndicator - covered simple sample (RFPL-992)
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/RequestTypeModelGuard.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/RequestTypeModelGuard.java 2011-01-28
12:00:47 UTC (rev 21300)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/RequestTypeModelGuard.java 2011-01-28
13:09:13 UTC (rev 21301)
@@ -86,8 +86,8 @@
* where should be registered regular HTTP request guard
* @return the selenium guarded to use regular HTTP requests
*/
- public static <T extends Model> T guardHttp(T selenium) {
- return guard(selenium, RequestType.HTTP, false);
+ public static <T extends Model> T guardHttp(T model) {
+ return guard(model, RequestType.HTTP, false);
}
/**
@@ -97,8 +97,8 @@
* where should be registered no request guard
* @return the selenium guarded to use no request during interaction
*/
- public static <T extends Model> T guardNoRequest(T selenium) {
- return guard(selenium, RequestType.NONE, false);
+ public static <T extends Model> T guardNoRequest(T model) {
+ return guard(model, RequestType.NONE, false);
}
/**
@@ -108,8 +108,8 @@
* where should be the guard registered
* @return the selenium waiting for interception of XHR type request
*/
- public static <T extends Model> T waitXhr(T selenium) {
- return guard(selenium, RequestType.XHR, true);
+ public static <T extends Model> T waitXhr(T model) {
+ return guard(model, RequestType.XHR, true);
}
/**
@@ -119,8 +119,8 @@
* selenium where should be the guard registered
* @return the selenium waitinf for interception of HTTP type request
*/
- public static <T extends Model> T waitHttp(T selenium) {
- return guard(selenium, RequestType.HTTP, true);
+ public static <T extends Model> T waitHttp(T model) {
+ return guard(model, RequestType.HTTP, true);
}
public interface Model {
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/DragIndicatorAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/DragIndicatorAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/DragIndicatorAttributes.java 2011-01-28
13:09:13 UTC (rev 21301)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richDragIndicator;
+
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class DragIndicatorAttributes extends AbstractComponentAttributes {
+ public void setAcceptClass(String acceptClass) {
+ setProperty("acceptClass", acceptClass);
+ }
+
+ public void setDraggingClass(String draggingClass) {
+ setProperty("draggingClass", draggingClass);
+ }
+
+ public void setRejectClass(String rejectClass) {
+ setProperty("rejectClass", rejectClass);
+ }
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Draggable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Draggable.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Draggable.java 2011-01-28
13:09:13 UTC (rev 21301)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richDragIndicator;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.model.AbstractModel;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class Draggable extends AbstractModel<JQueryLocator> {
+
+ public Draggable(String name, JQueryLocator root) {
+ super(name, root);
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Droppable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Droppable.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Droppable.java 2011-01-28
13:09:13 UTC (rev 21301)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richDragIndicator;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.model.AbstractModel;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class Droppable extends AbstractModel<JQueryLocator> {
+
+ public Droppable(String name, JQueryLocator root) {
+ super(name, root);
+ }
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Indicator.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Indicator.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/Indicator.java 2011-01-28
13:09:13 UTC (rev 21301)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richDragIndicator;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.model.AbstractModel;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class Indicator extends AbstractModel<JQueryLocator> {
+
+ private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ private String acceptClass;
+ private String rejectClass;
+ private String draggingClass;
+
+ public Indicator(String name, JQueryLocator root) {
+ super(name, root);
+ }
+
+ public void setAcceptClass(String acceptClass) {
+ this.acceptClass = acceptClass;
+ }
+
+ public void setRejectClass(String rejectClass) {
+ this.rejectClass = rejectClass;
+ }
+
+ public void setDraggingClass(String draggingClass) {
+ this.draggingClass = draggingClass;
+ }
+
+ public boolean isVisible() {
+ return selenium.isVisible(this);
+ }
+
+ public boolean belongsClass(String className) {
+ if (className == null) {
+ return false;
+ }
+ return selenium.belongsClass(this, className);
+ }
+
+ public boolean isAccepting() {
+ return isVisible() && selenium.belongsClass(this,
"rf-ind-acpt");
+ }
+
+ public boolean isDragging() {
+ return isVisible() && selenium.belongsClass(this,
"rf-ind-drag");
+ }
+
+ public boolean isRejecting() {
+ return isVisible() && selenium.belongsClass(this,
"rf-ind-rejt");
+ }
+
+ public void verifyState(IndicatorState state) {
+ switch (state) {
+ case HIDDEN:
+ assertFalse(isVisible());
+ break;
+ case DRAGGING:
+ assertTrue(isVisible());
+ assertTrue(isDragging());
+ assertFalse(isAccepting());
+ assertFalse(isRejecting());
+ verifyCustomClass(draggingClass, true);
+ verifyCustomClass(acceptClass, false);
+ verifyCustomClass(rejectClass, false);
+ break;
+ case ACCEPTING:
+ assertTrue(isVisible());
+ assertTrue(isDragging());
+ assertTrue(isAccepting());
+ assertFalse(isRejecting());
+ verifyCustomClass(draggingClass, true);
+ verifyCustomClass(acceptClass, true);
+ verifyCustomClass(rejectClass, false);
+ break;
+ case REJECTING:
+ assertTrue(isVisible());
+ assertTrue(isDragging());
+ assertFalse(isAccepting());
+ assertTrue(isRejecting());
+ verifyCustomClass(draggingClass, true);
+ verifyCustomClass(acceptClass, false);
+ verifyCustomClass(rejectClass, true);
+ break;
+ }
+ }
+
+ private void verifyCustomClass(String customClass, boolean shouldBePresent) {
+ if (customClass == null) {
+ return;
+ }
+ assertEquals(belongsClass(customClass), shouldBePresent);
+ }
+
+ public enum IndicatorState {
+ HIDDEN, DRAGGING, ACCEPTING, REJECTING;
+ }
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/TestDragIndicator.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/TestDragIndicator.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDragIndicator/TestDragIndicator.java 2011-01-28
13:09:13 UTC (rev 21301)
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richDragIndicator;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.actions.Drag;
+import org.jboss.test.selenium.request.RequestType;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.richDragIndicator.Indicator.IndicatorState;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestDragIndicator extends AbstractMetamerTest {
+
+ private final static String ACCEPT_CLASS = "sample-accept-class";
+ private final static String REJECT_CLASS = "sample-reject-class";
+ private final static String DRAGGING_CLASS = "sample-dragging-class";
+
+ Draggable drg1 = new Draggable("drg1", pjq("[id$=draggable1]"));
+ Draggable drg2 = new Draggable("drg2", pjq("[id$=draggable2]"));
+ Draggable drg3 = new Draggable("drg3", pjq("[id$=draggable3]"));
+
+ Droppable drop1 = new Droppable("drop1",
pjq("[id$=droppable1]"));
+ Droppable drop2 = new Droppable("drop2",
pjq("[id$=droppable2]"));
+
+ Indicator indicator = new Indicator("ind",
jq("div.rf-ind[id$=indicator]"));
+
+ DragIndicatorAttributes attributes = new DragIndicatorAttributes();
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richDragIndicator/simple.xhtml");
+ }
+
+ @BeforeMethod
+ public void setup() {
+ attributes.setDraggingClass(DRAGGING_CLASS);
+ attributes.setAcceptClass(ACCEPT_CLASS);
+ attributes.setRejectClass(REJECT_CLASS);
+ indicator.setDraggingClass(DRAGGING_CLASS);
+ indicator.setAcceptClass(ACCEPT_CLASS);
+ indicator.setRejectClass(REJECT_CLASS);
+ }
+
+ @Test
+ public void testRendered() {
+ attributes.setRendered(false);
+
+ selenium.getPageExtensions().install();
+ selenium.getRequestInterceptor().clearRequestTypeDone();
+
+ Drag drag = new Drag(drg1, drop1);
+ drag.start();
+ assertFalse(selenium.isElementPresent(indicator));
+ drag.enter();
+ assertFalse(selenium.isElementPresent(indicator));
+
+ drag.drop();
+
+ waitModel.timeout(5000).waitForTimeout();
+ assertEquals(selenium.getRequestInterceptor().getRequestTypeDone(),
RequestType.NONE);
+ }
+
+ @Test
+ public void testDragging() {
+ Drag drag = new Drag(drg1, drg2);
+ indicator.verifyState(IndicatorState.HIDDEN);
+
+ drag.start();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.mouseOut();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.enter();
+ indicator.verifyState(IndicatorState.DRAGGING);
+ }
+
+ @Test
+ public void testAccepting() {
+ Drag drag = new Drag(drg1, drop1);
+ indicator.verifyState(IndicatorState.HIDDEN);
+
+ drag.start();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.mouseOut();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.enter();
+ indicator.verifyState(IndicatorState.ACCEPTING);
+ }
+
+ @Test
+ public void testRejecting() {
+ Drag drag = new Drag(drg1, drop2);
+ indicator.verifyState(IndicatorState.HIDDEN);
+
+ drag.start();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.mouseOut();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.enter();
+ indicator.verifyState(IndicatorState.REJECTING);
+ }
+
+ @Test
+ public void testMovingOverDifferentStates() {
+ Drag drag = new Drag(drg1, drop2);
+ drag.enter();
+ indicator.verifyState(IndicatorState.REJECTING);
+
+ drag.setDropTarget(drop1);
+ drag.enter();
+ indicator.verifyState(IndicatorState.ACCEPTING);
+
+ drag.setDropTarget(drg1);
+ drag.enter();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.setDropTarget(drop1);
+ drag.enter();
+ indicator.verifyState(IndicatorState.ACCEPTING);
+
+ drag.setDropTarget(drg2);
+ drag.enter();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.setDropTarget(drop2);
+ drag.enter();
+ indicator.verifyState(IndicatorState.REJECTING);
+
+ drag.setDropTarget(drg2);
+ drag.enter();
+ indicator.verifyState(IndicatorState.DRAGGING);
+
+ drag.setDropTarget(drop1);
+ drag.enter();
+ indicator.verifyState(IndicatorState.ACCEPTING);
+
+ drag.setDropTarget(drop2);
+ drag.enter();
+ indicator.verifyState(IndicatorState.REJECTING);
+ }
+
+}