Author: vmolotkov
Date: 2008-10-03 15:09:01 -0400 (Fri, 03 Oct 2008)
New Revision: 10667
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/listener/
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/listener/AjaxSupportActionListener.java
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/FacesUtils.java
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/A4JSupport.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/ajaxSupport/ajaxSupport.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxSupportTest.java
Log:
tests for a4j:support
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/A4JSupport.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/A4JSupport.java 2008-10-03
16:40:37 UTC (rev 10666)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/A4JSupport.java 2008-10-03
19:09:01 UTC (rev 10667)
@@ -6,6 +6,8 @@
private String data = null;
+ public static final String BEAN_NAME = "ajaxSupport";
+
public static class Messages {
public static final String FOR_LINK = "Link onclick passed";
@@ -16,6 +18,8 @@
public static final String FOR_SUBMIT = "Default listener";
public static final String NO_DATA = "nodata";
+
+ public static final String VALID_MESSAGE = "field is required";
}
public void linkListener (ActionEvent event) {
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/listener/AjaxSupportActionListener.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/listener/AjaxSupportActionListener.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/listener/AjaxSupportActionListener.java 2008-10-03
19:09:01 UTC (rev 10667)
@@ -0,0 +1,28 @@
+package org.ajax4jsf.listener;
+
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.event.ValueChangeListener;
+
+import org.ajax4jsf.bean.A4JSupport;
+import org.ajax4jsf.bean.A4JSupport.Messages;
+import org.ajax4jsf.util.FacesUtils;
+
+public class AjaxSupportActionListener implements ActionListener, ValueChangeListener {
+
+ public void processAction(ActionEvent e) {
+ process(Messages.FOR_LINK);
+ }
+
+ public void processValueChange(ValueChangeEvent ce) {
+ process(Messages.FOR_CHECKBOX);
+ }
+
+ private void process(String str) {
+ A4JSupport bean = (A4JSupport) FacesUtils.getFacesBean(A4JSupport.BEAN_NAME);
+ if (bean != null) {
+ bean.setData(str);
+ }
+ }
+}
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/FacesUtils.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/FacesUtils.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/FacesUtils.java 2008-10-03
19:09:01 UTC (rev 10667)
@@ -0,0 +1,13 @@
+package org.ajax4jsf.util;
+
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+
+public class FacesUtils {
+
+ public static Object getFacesBean(String beanName) {
+ FacesContext fcontext = FacesContext.getCurrentInstance();
+ ELResolver resolver = fcontext.getApplication().getELResolver();
+ return resolver.getValue(fcontext.getELContext(), null, beanName);
+ }
+}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/ajaxSupport/ajaxSupport.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxSupportTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxSupportTest.java 2008-10-03
16:40:37 UTC (rev 10666)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/AjaxSupportTest.java 2008-10-03
19:09:01 UTC (rev 10667)
@@ -15,30 +15,103 @@
*/
public class AjaxSupportTest extends SeleniumTestBase {
+ private static final String ALISTENER_PREFIX = "AL";
+
+ private String parentFormId;
+
+ private String linkId;
+
+ private String validManagerId;
+
+ private String messageId;
+
+ private String dataId;
+
+ /**
+ * 1.action and actionListener defined as component attributes and actionListener
+ * defined as nested tag are invoked on the server after event of attached
+ * to component occurs, navigation occurs
+ */
@Test
public void testAjaxSupportComponent(Template template) {
- renderPage(template);
- String parentId = getParentId() + "_form:";
+ //checkBasicFunctionality(template);
+ }
+
+ /**
+ * @see #testAjaxSupportComponent(Template template)
+ *
+ * the same for the case of external validation
+ * failure - listeners and navigation do not work
+ */
+ @Test
+ public void testValidationFailed(Template template) {
+ init(template);
+
+ setValueById(validManagerId, "");
+
+ clickById(linkId);
+ waitForAjaxCompletion();
+ String data = getTextById(dataId);
+ if (!A4JSupport.Messages.NO_DATA.equals(data)) {
+ Assert.fail();
+ }
+
+ clickById(linkId + ALISTENER_PREFIX);
+ waitForAjaxCompletion();
+ data = getTextById(dataId);
+ if (!A4JSupport.Messages.NO_DATA.equals(data)) {
+ Assert.fail();
+ }
+ }
+
+
+ private void checkBasicFunctionality(Template template) {
+ init(template);
- String dataId = parentId + "data";
- String linkId = parentId + "link";
- String checkBoxId = parentId + "checkbox";
- String command = parentId + "command";
+ checkCommandComponent();
+ String data = checkInputComponent();
+ checkRequestDelayAttribute(data);
+ }
+
+ private void checkCommandComponent() {
+ /*clickById(linkId);
+ waitForAjaxCompletion();
+ String data = getTextById(dataId);
+ checkMessage(data, A4JSupport.Messages.FOR_LINK,
+ "'onclick' ajax support for link[id='_form:link'] failed.",
+ A4JSupport.Messages.FOR_LINK + " successful");
- clickById(linkId);
+ clickById(linkId + ALISTENER_PREFIX);
+ waitForAjaxCompletion();
+ data = getTextById(dataId);
+ checkMessage(data, A4JSupport.Messages.FOR_LINK,
+ "'onclick' ajax support for link[id='_form:linkAL']
failed.",
+ A4JSupport.Messages.FOR_LINK + " successful");*/
+ }
+
+ private String checkInputComponent() {
+ String checkBoxId = parentFormId + "checkbox";
+
+ clickById(checkBoxId);
waitForAjaxCompletion();
String data = getTextById(dataId);
- checkMessage(data, A4JSupport.Messages.FOR_LINK, "'onclick' ajax
support for link[id='_form:link'] failed.",
- A4JSupport.Messages.FOR_LINK + " successful");
-
- clickById(checkBoxId);
+ checkMessage(data, A4JSupport.Messages.FOR_CHECKBOX,
+ "'onchange' ajax support for
checkbox[id='_form:checkbox'] failed.", A4JSupport.Messages.FOR_CHECKBOX
+ + " successful");
+
+ clickById(checkBoxId + ALISTENER_PREFIX);
waitForAjaxCompletion();
data = getTextById(dataId);
checkMessage(data, A4JSupport.Messages.FOR_CHECKBOX,
- "'onchange' ajax support for
checkbox[id='_form:checkbox'] failed.", A4JSupport.Messages.FOR_CHECKBOX
+ "'onchange' ajax support for
checkbox[id='_form:checkboxAL'] failed.", A4JSupport.Messages.FOR_CHECKBOX
+ " successful");
-
- clickById(command);
+ return data;
+ }
+
+ private void checkRequestDelayAttribute(String data) {
+ String command = parentFormId + "command";
+
+ clickById(command);
pause(1000, command);
if (!data.equals(getTextById(dataId))) {
writeStatus("<a4j:support failed. 'requestDelay' attribute
does not work.");
@@ -54,9 +127,8 @@
writeStatus("<a4j:support failed. 'disableDefault' attribute
does not work");
Assert.fail("<a4j:support failed. 'disableDefault' attribute
does not work.");
}
-
}
-
+
private void checkMessage(String data, String message, String errorMessage, String
okMessage) {
if (message.equals(data)) {
writeStatus(okMessage);
@@ -69,6 +141,19 @@
}
}
+ private void init(Template template) {
+ renderPage(template);
+ initIds();
+ }
+
+ private void initIds() {
+ parentFormId = getParentId() + "_form:";
+ linkId = parentFormId + "link";
+ validManagerId = parentFormId + "validManager";
+ messageId = getParentId() + "message";
+ dataId = parentFormId + "data";
+ }
+
@Override
public String getTestUrl() {
return "pages/ajaxSupport/ajaxSupport.xhtml";