Author: andrei_exadel
Date: 2008-11-03 10:21:44 -0500 (Mon, 03 Nov 2008)
New Revision: 11002
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/contextMenu/contextMenuAutoTest.xhtml
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ContextMenuTestBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/contextMenu/contextMenu.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ContextMenuTest.java
Log:
ContextMenu test
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ContextMenuTestBean.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ContextMenuTestBean.java 2008-11-03
12:53:13 UTC (rev 11001)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ContextMenuTestBean.java 2008-11-03
15:21:44 UTC (rev 11002)
@@ -21,13 +21,20 @@
package org.ajax4jsf.bean;
+import java.util.Date;
+
import javax.faces.event.ActionEvent;
public class ContextMenuTestBean {
+
+ static final String attachTo = "attachToLink";
+ String status;
private String value;
private int value2;
-
+ private String submitMode = "none";
+ private Boolean attached = false;
+ private String attacheTo = "";
public ContextMenuTestBean() {
value = "";
@@ -35,9 +42,33 @@
}
public void actionListener(ActionEvent event) {
- this.value = event.getComponent().getId();
+ status = "ActionListener";
}
+ public String testServerSubmitMode() {
+ submitMode = "server";
+ status = null;
+ return null;
+ }
+
+ public String testAjaxSubmitMode() {
+ submitMode = "ajax";
+ status = null;
+ return null;
+ }
+
+ public String testAttached() {
+ attached = true;
+ attacheTo = null;
+ return null;
+ }
+
+ public String testAttachTo() {
+ attacheTo = attachTo;
+ attached = true;
+ return null;
+ }
+
public String getValue() {
return value;
}
@@ -45,9 +76,9 @@
public void setValue(String value) {
this.value = value;
}
-
+
public String action() {
- if (4 == value2 ) {
+ if (4 == value2) {
value2 = 1;
} else {
value2++;
@@ -55,6 +86,17 @@
return null;
}
+ public String getTime() {
+ return String.valueOf(new Date().getTime());
+ }
+
+ public void reset() {
+ submitMode = "none";
+ attached = false;
+ attacheTo = "";
+ status = null;
+ }
+
public int getValue2() {
return value2;
}
@@ -62,14 +104,70 @@
public void setValue2(int value2) {
this.value2 = value2;
}
-
+
public String getMessage3() {
return "Menu3";
}
-
+
public String getMessage4() {
return "Menu4";
}
+ /**
+ * @return the submitMode
+ */
+ public String getSubmitMode() {
+ return submitMode;
+ }
+ /**
+ * @param submitMode
+ * the submitMode to set
+ */
+ public void setSubmitMode(String submitMode) {
+ this.submitMode = submitMode;
+ }
+
+ /**
+ * @return the attached
+ */
+ public Boolean getAttached() {
+ return attached;
+ }
+
+ /**
+ * @param attached the attached to set
+ */
+ public void setAttached(Boolean attached) {
+ this.attached = attached;
+ }
+
+ /**
+ * @return the attacheTo
+ */
+ public String getAttacheTo() {
+ return attacheTo;
+ }
+
+ /**
+ * @param attacheTo the attacheTo to set
+ */
+ public void setAttacheTo(String attacheTo) {
+ this.attacheTo = attacheTo;
+ }
+
+ /**
+ * @return the status
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * @param status the status to set
+ */
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/contextMenu/contextMenu.xhtml
===================================================================
(Binary files differ)
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/contextMenu/contextMenuAutoTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/contextMenu/contextMenuAutoTest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/contextMenu/contextMenuAutoTest.xhtml 2008-11-03
15:21:44 UTC (rev 11002)
@@ -0,0 +1,34 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition template="#{templateBean.autoTestTemplate}">
+ <ui:define name="component">
+ <rich:contextMenu id="componentId"
+ immediate="#{autoTestBean.immediate}"
+ ajaxSingle="#{autoTestBean.ajaxSingle}"
+ reRender="#{autoTestBean.reRender}"
+ limitToList="#{autoTestBean.limitToList}"
+ bypassUpdates="#{autoTestBean.bypassUpdate}"
+ rendered="#{autoTestBean.rendered}"
+ oncomplete="#{autoTestBean.oncomplete}"
+ submitMode="#{contextMenuBean.submitMode}"
+ >
+ <rich:menuItem id="item1"
actionListener="#{autoTestBean.actionListener}" value="Item1" />
+ <f:param name="parameter1" value="value1" />
+ </rich:contextMenu>
+ <a href="#" id="showMenu" onclick="$(getParentId() +
'autoTestForm:componentId').component.show(event)">Show</a>
+ <a href="#" onclick="$(getParentId() +
'autoTestForm:componentId').component.hide()">Hide</a>
+ </ui:define>
+ <ui:define name="customControls">
+ <h:form id="controls">
+ <h:commandButton id="testServerSubmit"
action="#{contextMenuBean.testServerSubmitMode}"
value="testServerSubmit"></h:commandButton>
+ <h:commandButton id="testAjaxSubmit"
action="#{contextMenuBean.testAjaxSubmitMode}"
value="testAjaxSubmit"></h:commandButton>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ContextMenuTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ContextMenuTest.java 2008-11-03
12:53:13 UTC (rev 11001)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ContextMenuTest.java 2008-11-03
15:21:44 UTC (rev 11002)
@@ -27,10 +27,13 @@
import org.testng.annotations.Test;
public class ContextMenuTest extends SeleniumTestBase {
-
+
static final String FORMID = "_form:";
+ static final String CONTROL_FORMID = "_controls:";
static final String UNATTACHED_CONTEXTMENU = "contextMenu";
+ static final String RESET_METHOD = "#{contextMenuBean.reset}";
+
String linkShowId;
String linkHideId;
String componentControlShowLinkId;
@@ -38,7 +41,7 @@
String contextMenuId;
String autoCreatedId;
String contextMenuBody;
-
+
void initIds(String parentId, String contextMenuId) {
parentId = getParentId() + FORMID;
linkShowId = "showMenu";
@@ -48,38 +51,133 @@
contextMenuId = parentId + contextMenuId;
autoCreatedId = contextMenuId + ":_auto_created";
contextMenuBody = contextMenuId + "_menu";
+ this.contextMenuId = contextMenuId;
}
+ @Override
+ public String getAutoTestUrl() {
+ return "pages/contextMenu/contextMenuAutoTest.xhtml";
+ }
+
+
@Test
+ public void testActionListener(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId(), UNATTACHED_CONTEXTMENU);
+ String statusId = getParentId() + FORMID + "status";
+
+ clickById(linkShowId);
+ waitForMenuShow(contextMenuId);
+ String itemId = getParentId() + FORMID + "item2";
+ clickById(itemId);
+ pause(200, contextMenuId);
+ AssertTextEquals(statusId, "", "No action listener should be passed for
submitMode = none");
+
+ String controlId = getParentId() + CONTROL_FORMID + "testServerMode";
+ clickCommandAndWait(controlId);
+ clickById(linkShowId);
+ waitForMenuShow(contextMenuId);
+ clickCommandAndWait(itemId);
+ AssertTextEquals(statusId, "ActionListener", "Action listener skipped
for SubmitMode = server ");
+
+ controlId = getParentId() + CONTROL_FORMID + "testAjaxMode";
+ clickCommandAndWait(controlId);
+ clickById(linkShowId);
+ waitForMenuShow(contextMenuId);
+ clickAjaxCommandAndWait(itemId);
+ AssertTextEquals(statusId, "ActionListener", "Action listener skipped
for SubmitMode = ajax ");
+
+ }
+
+ @Test
+ public void testAttachedAndAttachedTo(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId(), UNATTACHED_CONTEXTMENU);
+
+ String controlId = getParentId() + CONTROL_FORMID + "testAttached";
+ clickCommandAndWait(controlId);
+
+ String attachedLink = getParentId() + FORMID + "parentLink";
+ clickById(attachedLink);
+ waitForMenuShow(contextMenuId, "Attached = true does not work");
+ AssertPresent(contextMenuBody, "Context menu has not been shown");
+
+
+ controlId = getParentId() + CONTROL_FORMID + "testAttachTo";
+ clickCommandAndWait(controlId);
+
+ String attachedTo = "attachToLink";
+ clickById(attachedTo);
+ waitForMenuShow(contextMenuId, "AttachTo does not work");
+ AssertPresent(contextMenuBody, "Context menu has not been shown");
+ }
+
+ @Test
+ public void testSubmitMode(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId(), UNATTACHED_CONTEXTMENU);
+
+ String controlId = getParentId() + CONTROL_FORMID + "testServerMode";
+ String timeId = getParentId() + FORMID + "time";
+ String time = getTextById(timeId);
+ String itemId = getParentId() + FORMID + "item1";
+
+ writeStatus("Test server submit mode");
+ /** test server submit mode */
+ clickCommandAndWait(controlId);
+ clickById(linkShowId);
+ waitForMenuShow(contextMenuId);
+ clickById(itemId);
+ waitForPageToLoad();
+ AssertTextNotEquals(timeId, time, "Server submit mode does not work");
+
+ writeStatus("Test server submit mode");
+ /** test ajax submit mode */
+ controlId = getParentId() + CONTROL_FORMID + "testAjaxMode";
+ clickCommandAndWait(controlId);
+ time = getTextById(timeId);
+ clickById(linkShowId);
+ waitForMenuShow(contextMenuId);
+ clickAjaxCommandAndWait(itemId);
+ AssertTextNotEquals(timeId, time, "Ajax submit mode does not work");
+
+ }
+
+ @Test
public void testContextMenuRendering(Template template) {
- renderPage(template);
+ renderPage(template, RESET_METHOD);
String parentId = getParentId();
String menuId = parentId + FORMID + "contextMenu2";
String menuBody = menuId + "_menu";
String autoCreatedId = menuId + ":_auto_created";
-
+
String showId = "showContext2";
String hideId = "hideContext2";
-
- //show menu
+
+ // show menu
clickById(showId);
-
+
waitForMenuShow(menuId);
-
+
AssertPresent(menuBody, "Context menu has not been displayed");
AssertPresent(autoCreatedId, "Context menu has not been displayed");
-
+
String menuGroupId = parentId + FORMID + "menuGroup";
String itemId = parentId + FORMID + "g5";
AssertPresent(menuGroupId, "Context menu group has not been displayed");
AssertPresent(itemId, "Menu item has not been displayed");
- int separatorCount =
selenium.getXpathCount("//div[@id='"+menuBody+"']/div/div[@class='dr-menu-separator
rich-menu-separator']").intValue();
+ int separatorCount = selenium
+ .getXpathCount(
+ "//div[@id='"
+ + menuBody
+ + "']/div/div[@class='dr-menu-separator
rich-menu-separator']")
+ .intValue();
Assert.assertTrue(separatorCount == 1, "Separators count is invalid");
-
+
menuBody = parentId + FORMID + "menuGroup_menu";
-
+
AssertPresent(menuBody);
itemId = parentId + FORMID + "g1";
AssertTextEquals(itemId, "Item1", "Item label is invalid");
@@ -92,163 +190,117 @@
itemId = parentId + FORMID + "g4";
AssertTextEquals(itemId, "Item3", "Item label is invalid");
AssertPresent(itemId, "Menu item has not been displayed");
-
- separatorCount =
selenium.getXpathCount("//div[@id='"+menuBody+"']/div/div[@class='dr-menu-separator
rich-menu-separator']").intValue();
+
+ separatorCount = selenium
+ .getXpathCount(
+ "//div[@id='"
+ + menuBody
+ + "']/div/div[@class='dr-menu-separator
rich-menu-separator']")
+ .intValue();
Assert.assertTrue(separatorCount == 1, "Separators count is invalid");
-
+
clickById(hideId);
clickById(showId);
-
+
menuId = parentId + FORMID + "menuGroup";
fireMouseEvent(menuId, "mouseover", 10, 10, false);
waitForMenuShow(menuId);
-
+
String top = runScript(getElementById(menuBody) + ".style.top");
String left = runScript(getElementById(menuBody) + ".style.left");
-
+
Assert.assertTrue(top != null && top.length() > 0);
Assert.assertTrue(left != null && left.length() > 0);
-
+
AssertTextEquals(menuId, "Group1", "Group label is invalid");
-
-
+
}
-
+
private void waitForMenuShow(String id) {
String bodyId = id + "_menu";
if (!selenium.isElementPresent(bodyId)) {
waiteForCondition(getElementById(bodyId), 5000);
}
- waiteForCondition(getElementById(bodyId) + ".style.display !=
'none'", 5000);
+ waiteForCondition(getElementById(bodyId) + ".style.display !=
'none'",
+ 5000);
}
-
-
- //@Test
+
+ private void waitForMenuShow(String id, String message) {
+ try {
+ waitForMenuShow(id);
+ } catch (Exception e) {
+ Assert.fail(message + e.getMessage());
+ }
+ }
+
+ @Test
public void testContextMenuStandAlone(Template template) {
- renderPage(template);
+ renderPage(template, RESET_METHOD);
initIds(getParentId(), UNATTACHED_CONTEXTMENU);
-
+
String menuItemId = getParentId() + FORMID + "item2";
-
+
AssertNotPresent(menuItemId, "Context menu should be hidden");
AssertNotPresent(autoCreatedId, "Context menu should be hidden");
-
+
clickById(linkShowId);
-
+
AssertPresent(menuItemId, "Context menu has not been shown");
AssertPresent(autoCreatedId, "Context menu has not been shown");
- AssertTextEquals(menuItemId, "Menu2", "Context menu displays
incorrect.");
-
+ AssertTextEquals(menuItemId, "Menu2",
+ "Context menu displays incorrect.");
+
clickById(linkHideId);
-
+
AssertNotVisible(contextMenuBody, "Context menu has not been hidden");
}
-
- //@Test
+
+ @Test
public void testComponentControlManagement(Template template) {
- renderPage(template);
+ renderPage(template, RESET_METHOD);
initIds(getParentId(), UNATTACHED_CONTEXTMENU);
-
+
String menuItemId = getParentId() + FORMID + "item2";
-
AssertNotPresent(menuItemId, "Context menu should be hidden");
AssertNotPresent(autoCreatedId, "Context menu should be hidden");
-
+
clickById(componentControlShowLinkId);
-
+
AssertPresent(menuItemId, "Context menu has not been shown");
AssertPresent(autoCreatedId, "Context menu has not been shown");
- AssertTextEquals(menuItemId, "Menu2", "Context menu displays
incorrect.");
-
+ AssertTextEquals(menuItemId, "Menu2",
+ "Context menu displays incorrect.");
+
clickById(componentControlHideLinkId);
-
+
AssertNotVisible(contextMenuBody, "Context menu has not been hidden");
}
-
- //@Test
+
+ @Test
public void testMacrodefinitions(Template template) {
- renderPage(template);
+ renderPage(template, RESET_METHOD);
initIds(getParentId(), UNATTACHED_CONTEXTMENU);
String menuItemId = getParentId() + FORMID + "item1";
-
+
clickById(linkShowId);
-
- AssertTextEquals(menuItemId, "Menu1", "Macrosubstitution does not
work.");
-
+
+ AssertTextEquals(menuItemId, "Menu1",
+ "Macrosubstitution does not work.");
+
clickById(componentControlShowLinkId);
menuItemId = getParentId() + FORMID + "item3";
- AssertTextEquals(menuItemId, "Menu3", "Macrosubstitution does not
work.");
+ AssertTextEquals(menuItemId, "Menu3",
+ "Macrosubstitution does not work.");
menuItemId = getParentId() + FORMID + "item4";
- AssertTextEquals(menuItemId, "Menu4", "Macrosubstitution does not
work.");
-
+ AssertTextEquals(menuItemId, "Menu4",
+ "Macrosubstitution does not work.");
+
}
- //@Test
- public void testContextMenuComponent(Template template) {
- renderPage(template);
+ public String getTestUrl() {
+ return "pages/contextMenu/contextMenu.xhtml";
+ }
- String parentId = getParentId() + "_form:";
- String inputId = parentId + "input";
- String input2Id = parentId + "input2";
- String outputId = parentId + "_value2";
- String menuId = parentId + "menu_input_menu";
- String menu2Id = parentId + "menu_input2_menu";
-
- String menu1_item_ajax = parentId + "menu1_item1";
- String menu1_item_server = parentId + "menu1_item2";
- String menu2_item_ajax = parentId + "menu2_item1";
- String menu2_item_server = parentId + "menu2_item2";
-
- writeStatus("Click on first input");
- clickById(inputId);
- antifast(menuId);
- Assert.assertTrue(isVisibleById(menuId));
-
- writeStatus("Click on second input");
- clickById(input2Id);
- antifast(menu2Id);
- Assert.assertFalse(isVisibleById(menuId));
- Assert.assertTrue(isVisibleById(menu2Id));
-
- writeStatus("Click on first input again");
- clickById(inputId);
- antifast(menuId);
- Assert.assertTrue(isVisibleById(menuId));
- Assert.assertFalse(isVisibleById(menu2Id));
-
- writeStatus("Click on ajax item in first menu");
- clickAjaxCommandAndWait(menu1_item_ajax);
- AssertValueEquals(inputId, "menu1_item1");
- AssertTextEquals(outputId, "1");
-
- writeStatus("Click on server item in first menu");
- clickCommandAndWait(menu1_item_server);
- AssertValueEquals(inputId, "menu1_item2");
- AssertTextEquals(outputId, "2");
-
- writeStatus("Click on second input again");
- clickById(input2Id);
- antifast(menu2Id);
- Assert.assertTrue(isVisibleById(menu2Id));
-
- writeStatus("Click on ajax item in first menu");
- clickAjaxCommandAndWait(menu2_item_ajax);
- AssertValueEquals(inputId, "menu2_item1");
- AssertTextEquals(outputId, "3");
-
- writeStatus("Click on server item in second menu");
- clickCommandAndWait(menu2_item_server);
- AssertValueEquals(inputId, "menu2_item2");
- AssertTextEquals(outputId, "4");
- }
-
- public String getTestUrl() {
- return "pages/contextMenu/contextMenu.xhtml";
- }
-
- private void antifast(String id) {
- waiteForCondition("document.getElementById('" + id + "')
!= undefined", 500);
- }
-
+
}