Author: dsvyatobatsko
Date: 2008-08-19 13:37:04 -0400 (Tue, 19 Aug 2008)
New Revision: 10144
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JHTMLCommandLinkTestBean.java
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxHTMLCommandLink/ajaxHTMLLinkTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxHTMLCommandLinkTest.java
Log:
ajaxHTMLCommandLinkTest refactored
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JHTMLCommandLinkTestBean.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JHTMLCommandLinkTestBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JHTMLCommandLinkTestBean.java 2008-08-19
17:37:04 UTC (rev 10144)
@@ -0,0 +1,54 @@
+package org.ajax4jsf.bean;
+
+import javax.faces.event.ActionEvent;
+
+public class A4JHTMLCommandLinkTestBean {
+
+ private boolean rendered = false;
+ private boolean isListenerInvoked = false;
+ private boolean isActionInvoked = false;
+
+ private String value;
+
+ public boolean isRendered() {
+ return rendered;
+ }
+
+ public void setRendered(boolean rendered) {
+ this.rendered = rendered;
+ }
+
+ public String action() {
+ setActionInvoked(true);
+ return null;
+ }
+
+ public void actionListener (ActionEvent event) {
+ setListenerInvoked(true);
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public boolean isListenerInvoked() {
+ return isListenerInvoked;
+ }
+
+ public void setListenerInvoked(boolean isListenerInvoked) {
+ this.isListenerInvoked = isListenerInvoked;
+ }
+
+ public boolean isActionInvoked() {
+ return isActionInvoked;
+ }
+
+ public void setActionInvoked(boolean isActionInvoked) {
+ this.isActionInvoked = isActionInvoked;
+ }
+
+}
Property changes on:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/bean/A4JHTMLCommandLinkTestBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-08-19
16:05:59 UTC (rev 10143)
+++
trunk/test-applications/seleniumTest/src/main/webapp/WEB-INF/faces-config.xml 2008-08-19
17:37:04 UTC (rev 10144)
@@ -210,8 +210,13 @@
<managed-bean-name>modalPanelBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.bean.ModalPanelTestBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>a4jHtmlCommandLinkBean</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.bean.A4JHTMLCommandLinkTestBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
- <navigation-rule>
+ <navigation-rule>
<from-view-id>/pages/ajaxInclude/step1.xhtml</from-view-id>
<navigation-case>
<from-outcome>next</from-outcome>
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxHTMLCommandLink/ajaxHTMLLinkTest.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxHTMLCommandLinkTest.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxHTMLCommandLinkTest.java 2008-08-19
16:05:59 UTC (rev 10143)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxHTMLCommandLinkTest.java 2008-08-19
17:37:04 UTC (rev 10144)
@@ -2,11 +2,16 @@
import org.ajax4jsf.template.Template;
import org.richfaces.SeleniumTestBase;
-import org.testng.Assert;
import org.testng.annotations.Test;
public class AjaxHTMLCommandLinkTest extends SeleniumTestBase {
+ private final static String IS_ACTION_INVOKED = "_form:_action";
+
+ private final static String IS_LISTENER_INVOKED = "_form:_listener";
+
+ private final static String SUBMITTED_VALUE = "_form:_submittedValue";
+
@Test
public void testAjaxHTMLCommandLinkComponent(Template template) {
renderPage(template);
@@ -14,74 +19,63 @@
String parentId = getParentId() + "_form:";
String linkId = parentId + "l1";
- boolean immediate = false;
writeStatus("Click link 1");
- setValidation(true);
- clickById(linkId);
- waitForAjaxCompletion();
- waitForOnCompleteHndler();
- checkButton(linkId, true, immediate, true, true, true);
+ clickCommandAndWait(linkId);
+ assertValueSubmitted(true);
+ assertActionInvoked(true);
+ assertListenerInvoked(true);
linkId = parentId + "l2";
- immediate = false;
writeStatus("Click link 2");
- setValidation(false);
- clickById(linkId);
- waitForAjaxCompletion();
- waitForOnCompleteHndler();
- checkButton(linkId, false, immediate, false, false, false);
+ clickCommandAndWait(linkId);
+ assertValueSubmitted(false);
+ assertActionInvoked(false);
+ assertListenerInvoked(false);
linkId = parentId + "l3";
- immediate = true;
writeStatus("Click link 3");
- setValidation(true);
- clickById(linkId);
- waitForAjaxCompletion();
- waitForOnCompleteHndler();
- checkButton(linkId, true, immediate, true, true, false);
+ clickCommandAndWait(linkId);
+ assertValueSubmitted(false);
+ assertActionInvoked(true);
+ assertListenerInvoked(true);
linkId = parentId + "l4";
- immediate = true;
writeStatus("Click link 4");
- setValidation(false);
- clickById(linkId);
- waitForAjaxCompletion();
- waitForOnCompleteHndler();
- checkButton(linkId, true, immediate, true, true, false);
+ clickCommandAndWait(linkId);
+ assertValueSubmitted(false);
+ assertActionInvoked(true);
+ assertListenerInvoked(true);
}
- private void setValidation(boolean success) {
- StringBuffer buffer = new StringBuffer("setValidation(");
- buffer.append(success);
- buffer.append(");");
- runScript(buffer.toString());
+ private void assertValueSubmitted(boolean submitted) {
+ if (submitted) {
+ writeStatus("Check that a new value is submitted");
+ AssertTextEquals(getParentId() + SUBMITTED_VALUE, "text", "A
new value is not submitted");
+ } else {
+ writeStatus("Check that a new value is not submitted");
+ AssertTextEquals(getParentId() + SUBMITTED_VALUE, "", "A new
value is submitted");
+ }
}
- private void waitForOnCompleteHndler() {
- waiteForCondition("_onCompleteHandler == true;", 3000);
- runScript("_onCompleteHandler = false;");
+ private void assertActionInvoked(boolean invoked) {
+ if(invoked) {
+ writeStatus("Check that action is invoked");
+ AssertTextEquals(getParentId() + IS_ACTION_INVOKED, "true",
"An action is not invoked");
+ } else {
+ writeStatus("Check that action is not invoked");
+ AssertTextEquals(getParentId() + IS_ACTION_INVOKED, "false",
"An action is invoked");
+ }
}
- private void checkButton(String id, boolean testData, boolean immediate, boolean
testAction, boolean testFListener,
- boolean testInput) {
- writeStatus("Checking link...");
- StringBuffer buffer = new StringBuffer("checkLink('");
- buffer.append(id);
- buffer.append("',");
- buffer.append(testData);
- buffer.append(",");
- buffer.append(testAction);
- buffer.append(",");
- buffer.append(testFListener);
- buffer.append(",");
- buffer.append(testInput);
- buffer.append(");");
- String result = runScript(buffer.toString());
- if (result != null && result.length() > 0) {
- Assert.fail("<a4j:htmlCommandLink> [immediate=" + immediate +
"] test failure caused by " + result);
+ private void assertListenerInvoked(boolean invoked) {
+ if(invoked) {
+ writeStatus("Check that listener is invoked");
+ AssertTextEquals(getParentId() + IS_LISTENER_INVOKED, "true",
"A listener is not invoked");
+ } else {
+ writeStatus("Check that listener is not invoked");
+ AssertTextEquals(getParentId() + IS_LISTENER_INVOKED, "false",
"A listener is invoked");
}
-
}
@Override