Author: andrei_exadel
Date: 2008-10-03 09:20:20 -0400 (Fri, 03 Oct 2008)
New Revision: 10659
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotestsetup.xhtml
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/web.xml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
Log:
autotest for standard HTML & events components
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestContext.java 2008-10-03
13:20:20 UTC (rev 10659)
@@ -0,0 +1,43 @@
+package org.ajax4jsf.autotest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AutoTestContext {
+
+ String component;
+
+ List<String> events = new ArrayList<String>();
+
+ String rendered;
+
+ public AutoTestContext(String component) {
+ this.component = component;
+ }
+
+ public void addEvent(String ev) {
+ events.add(ev);
+ }
+
+ /**
+ * @return the component
+ */
+ public String getComponent() {
+ return component;
+ }
+
+ /**
+ * @return the events
+ */
+ public List<String> getEvents() {
+ return events;
+ }
+
+ /**
+ * @return the rendered
+ */
+ public String getRendered() {
+ return rendered;
+ }
+
+}
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/autotest/AutoTestServlet.java 2008-10-03
13:20:20 UTC (rev 10659)
@@ -0,0 +1,82 @@
+/*
+ * MyServlet.java Date created: 03.10.2008
+ * Last modified by: $Author$
+ * $Revision$ $Date$
+ */
+
+package org.ajax4jsf.autotest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * TODO Class description goes here.
+ * @author Andrey
+ *
+ */
+public class AutoTestServlet extends HttpServlet {
+
+ private static final String COMPONENT_PARAMETER_NAME = "c";
+
+ private static final String EVENT_PARAMETER_NAME = "ev";
+
+ private static final String CONTEXT_NAME = "SeleniumAutoTestContext";
+
+ String header = "<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\">";
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ AutoTestContext context =
(AutoTestContext)getServletContext().getAttribute(CONTEXT_NAME);
+ if (context == null) {
+ throw new NullPointerException("Test context is null");
+ }
+
+ PrintWriter writer = resp.getWriter();
+ writer.write(header);
+
+ writer.write("<");
+ writer.write(context.getComponent());
+ writer.write(" ");
+ writer.write("id=\"test\" ");
+
+ for (String ev : context.getEvents()) {
+ writer.write(ev + "=\"EventQueue.fire('"+ev+"')\"
");
+ }
+
+ writer.write(">");
+ writer.write("</" + context.getComponent() + ">");
+
+ writer.write("</html>");
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ String component = req.getParameter(COMPONENT_PARAMETER_NAME);
+ String [] events = req.getParameterValues(EVENT_PARAMETER_NAME);
+
+ AutoTestContext context = new AutoTestContext(component);
+ for (String event: events) {
+ context.addEvent(event);
+ }
+
+ getServletContext().setAttribute(CONTEXT_NAME, context);
+
+ resp.sendRedirect("/richfaces/faces/NEKO/pages/_autotest/autotest.xhtml");
+
+ }
+
+
+
+}
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/web.xml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/web.xml 2008-10-03
12:22:47 UTC (rev 10658)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/web.xml 2008-10-03
13:20:20 UTC (rev 10659)
@@ -96,6 +96,11 @@
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>Auto Test Servlet</servlet-name>
+ <servlet-class>org.ajax4jsf.autotest.AutoTestServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
@@ -103,6 +108,10 @@
<url-pattern>/faces/TIDY/*</url-pattern>
<url-pattern>/faces/NONE/*</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Auto Test Servlet</servlet-name>
+ <url-pattern>/autotest/*</url-pattern>
+ </servlet-mapping>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/faces/error.xhtml</location>
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotest.xhtml 2008-10-03
13:20:20 UTC (rev 10659)
@@ -0,0 +1,17 @@
+<!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.template}">
+ <ui:define name="style">
+
+ </ui:define>
+ <ui:define name="component">
+ <ui:include
src="http://#{facesContext.externalContext.request.localName}:#{facesContext.externalContext.request.localPort}/#{facesContext.externalContext.request.contextPath}/autotest/test"></ui:include>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotestsetup.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotestsetup.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/_autotest/autotestsetup.xhtml 2008-10-03
13:20:20 UTC (rev 10659)
@@ -0,0 +1,33 @@
+<html>
+<head>
+ <script type="text/javascript">
+ function setComponent(c) {
+ $('c').value = c;
+ }
+
+ function addEvent(ev) {
+ var d = $('events');
+ var i = document.createElement('input');
+ i.name = "ev";
+ i.type="hidden";
+ i.value = ev;
+ d.appendChild(i);
+ }
+
+ function $(id) {
+ return document.getElementById(id);
+ }
+
+ function submitForm() {
+ $('f').submit();
+ }
+ </script>
+</head>
+<body>
+<form id="f" method="post"
action="#{facesContext.externalContext.request.contextPath}/autotest/test">
+<input id="c" type="hidden" name="c" value=""
/>
+<div id="events" />
+</form>
+Loading...
+</body>
+</html>
\ No newline at end of file
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-03
12:22:47 UTC (rev 10658)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-03
13:20:20 UTC (rev 10659)
@@ -974,4 +974,31 @@
Assert.fail(message);
}
}
+
+ public void autoTest(Template template, String component, List<String> events)
{
+ selenium.open(protocol + "://" + host + ":" + port +
"/" + APPLICATION_NAME + filterPrefix +
"/pages/_autotest/autotestsetup.xhtml");
+ waitForPageToLoad();
+
+ runScript("setComponent('"+component+"');", false);
+
+ for (String ev : events) {
+ runScript("addEvent('"+ev+"');", false);
+ }
+
+ runScript("submitForm();", false);
+ waitForPageToLoad();
+
+ runScript("loadTemplate('" + template + "');", false);
+ waitForPageToLoad();
+
+ String id = template.getPrefix() + "test";
+ for (String ev : events) {
+ if ("onclick".equals(ev)) {
+ clickById(id);
+ }
+
+ }
+
+ assertEvents(events);
+ }
}