Author: julien(a)jboss.com
Date: 2007-04-22 12:19:56 -0400 (Sun, 22 Apr 2007)
New Revision: 7019
Added:
trunk/common/src/main/org/jboss/portal/common/util/MapBuilder.java
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/FormPartialRefreshWindowTest.java
Modified:
trunk/common/src/main/org/jboss/portal/common/util/CollectionBuilder.java
trunk/theme/src/bin/portal-ajax-war/dyna/dyna.js
trunk/theme/src/main/org/jboss/portal/test/theme/TestServlet.java
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/LinkPartialRefreshWindowTest.java
Log:
- added test case for partial refresh with forms
Modified: trunk/common/src/main/org/jboss/portal/common/util/CollectionBuilder.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/CollectionBuilder.java 2007-04-22
14:39:07 UTC (rev 7018)
+++ trunk/common/src/main/org/jboss/portal/common/util/CollectionBuilder.java 2007-04-22
16:19:56 UTC (rev 7019)
@@ -36,6 +36,7 @@
public class CollectionBuilder
{
+ /** . */
private ArrayList collection;
public CollectionBuilder()
Added: trunk/common/src/main/org/jboss/portal/common/util/MapBuilder.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/MapBuilder.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/util/MapBuilder.java 2007-04-22 16:19:56
UTC (rev 7019)
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.common.util;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+/**
+ * An helper to build collection of object in a simple manner.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class MapBuilder
+{
+
+ /** . */
+ private HashMap map;
+
+ public MapBuilder()
+ {
+ this.map = new HashMap();
+ }
+
+ /**
+ * Add the object to the collection.
+ *
+ * @param key the key
+ * @param value the value
+ * @return the builder
+ */
+ public MapBuilder put(Object key, Object value)
+ {
+ map.put(key, value);
+ return this;
+ }
+
+ /**
+ * Add all the objects to the collection.
+ *
+ * @param all the entries to add
+ * @return the builder
+ */
+ public MapBuilder putAll(Map all)
+ {
+ map.putAll(all);
+ return this;
+ }
+
+ /**
+ * Return a set build from the collection.
+ *
+ * @return a set
+ */
+ public HashMap toHashMap()
+ {
+ return map;
+ }
+
+ /**
+ * Return a list build from the collection.
+ *
+ * @return a list
+ */
+ public LinkedHashMap toLinkedHashMap()
+ {
+ return new LinkedHashMap(map);
+ }
+}
Modified: trunk/theme/src/bin/portal-ajax-war/dyna/dyna.js
===================================================================
--- trunk/theme/src/bin/portal-ajax-war/dyna/dyna.js 2007-04-22 14:39:07 UTC (rev 7018)
+++ trunk/theme/src/bin/portal-ajax-war/dyna/dyna.js 2007-04-22 16:19:56 UTC (rev 7019)
@@ -37,6 +37,33 @@
}
}
+// Check that the URL starts with the provided prefix
+function isURLAccepted(url) {
+ if (url.indexOf("http://") == 0)
+ {
+ var indexOfSlash = url.indexOf("/", "http://".length);
+ if (indexOfSlash < 0)
+ {
+ return false;
+ }
+ else if (indexOfSlash > 0)
+ {
+ var path = url.substring(indexOfSlash);
+ if (path.indexOf(server_base_url) != 0)
+ {
+ return false;
+ }
+ }
+ }
+ else if (url.indexOf(server_base_url) != 0)
+ {
+ return false;
+ }
+
+ //
+ return true;
+}
+
function bilto(event)
{
@@ -54,13 +81,19 @@
//
if (source.nodeName == "A")
{
- url = source.href;
- // We have a get
- options.method = "get"
+ // Check we can handle this URL
+ if (isURLAccepted(source.href)) {
- // We don't block
- options.asynchronous = false;
+ // Set URL
+ url = source.href;
+
+ // We have a get
+ options.method = "get"
+
+ // We don't block
+ options.asynchronous = false;
+ }
}
else if (source.nodeName == "INPUT" && source.type ==
"submit")
{
@@ -77,50 +110,25 @@
// We don't handle file upload for now
if (enctype != "multipart/form-data") {
- // Set URL
- url = current.action;
- // Set the specified enctype
- options.enctype = enctype;
+ // Check it is a POST
+ if (current.method.toLowerCase() == "post") {
- // Action blocks
- options.asynchronous = false;
+ // Check we can handle this URL
+ if (isURLAccepted(current.action)) {
- // Add body if needed
- if (current.method.toLowerCase() == "post") {
- options.method = "post"
- options.postBody = Form.serialize(current);
- }
- else {
- options.method = "get"
- }
- }
- }
- }
+ // Set URL
+ url = current.action;
- // Check that the URL starts with the provided prefix
- if (url != null)
- {
- if (url.indexOf("http://") == 0)
- {
- var indexOfSlash = url.indexOf("/", "http://".length);
- if (indexOfSlash < 0)
- {
- url = null;
- }
- else if (indexOfSlash > 0)
- {
- var path = url.substring(indexOfSlash);
- if (path.indexOf(server_base_url) != 0)
- {
- url = null;
+ // Set the specified enctype
+ options.enctype = enctype;
+ options.asynchronous = false;
+ options.method = "post"
+ options.postBody = Form.serialize(current);
+ }
}
}
}
- else if (url.indexOf(server_base_url) != 0)
- {
- url = null;
- }
}
// Handle links here
Modified: trunk/theme/src/main/org/jboss/portal/test/theme/TestServlet.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/test/theme/TestServlet.java 2007-04-22 14:39:07
UTC (rev 7018)
+++ trunk/theme/src/main/org/jboss/portal/test/theme/TestServlet.java 2007-04-22 16:19:56
UTC (rev 7019)
@@ -26,7 +26,7 @@
import org.jboss.mx.util.MBeanProxy;
import org.jboss.portal.common.test.driver.TestDriverContainer;
import org.jboss.portal.test.theme.model.WindowObject;
-import org.jboss.portal.test.theme.dyna.tests.refresh.LinkPartialRefreshWindowTest;
+import org.jboss.portal.test.theme.dyna.tests.refresh.FormPartialRefreshWindowTest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -54,17 +54,26 @@
MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
testServer = (TestDriverContainer)MBeanProxy.get(TestDriverContainer.class, new
ObjectName("portal.test:service=TestDriverServer"), mbeanServer);
- addTest(new LinkPartialRefreshWindowTest("A", Boolean.TRUE,
Boolean.TRUE, true));
- addTest(new LinkPartialRefreshWindowTest("B", Boolean.TRUE,
Boolean.FALSE, false));
- addTest(new LinkPartialRefreshWindowTest("C", Boolean.TRUE, null,
true));
+// addTest(new LinkPartialRefreshWindowTest("A", Boolean.TRUE,
Boolean.TRUE, true));
+// addTest(new LinkPartialRefreshWindowTest("B", Boolean.TRUE,
Boolean.FALSE, false));
+// addTest(new LinkPartialRefreshWindowTest("C", Boolean.TRUE, null,
true));
+// addTest(new LinkPartialRefreshWindowTest("D", Boolean.FALSE,
Boolean.TRUE, false));
+// addTest(new LinkPartialRefreshWindowTest("E", Boolean.FALSE,
Boolean.FALSE, false));
+// addTest(new LinkPartialRefreshWindowTest("F", Boolean.FALSE, null,
false));
+// addTest(new LinkPartialRefreshWindowTest("G", null, Boolean.TRUE,
true));
+// addTest(new LinkPartialRefreshWindowTest("H", null, Boolean.FALSE,
false));
+// addTest(new LinkPartialRefreshWindowTest("I", null, null, false));
- addTest(new LinkPartialRefreshWindowTest("D", Boolean.FALSE,
Boolean.TRUE, false));
- addTest(new LinkPartialRefreshWindowTest("E", Boolean.FALSE,
Boolean.FALSE, false));
- addTest(new LinkPartialRefreshWindowTest("F", Boolean.FALSE, null,
false));
-
- addTest(new LinkPartialRefreshWindowTest("G", null, Boolean.TRUE,
true));
- addTest(new LinkPartialRefreshWindowTest("H", null, Boolean.FALSE,
false));
- addTest(new LinkPartialRefreshWindowTest("I", null, null, false));
+ // todo use test parametrization
+ addTest(new FormPartialRefreshWindowTest("A", Boolean.TRUE,
Boolean.TRUE, true));
+ addTest(new FormPartialRefreshWindowTest("B", Boolean.TRUE,
Boolean.FALSE, false));
+ addTest(new FormPartialRefreshWindowTest("C", Boolean.TRUE, null,
true));
+ addTest(new FormPartialRefreshWindowTest("D", Boolean.FALSE,
Boolean.TRUE, false));
+ addTest(new FormPartialRefreshWindowTest("E", Boolean.FALSE,
Boolean.FALSE, false));
+ addTest(new FormPartialRefreshWindowTest("F", Boolean.FALSE, null,
false));
+ addTest(new FormPartialRefreshWindowTest("G", null, Boolean.TRUE,
true));
+ addTest(new FormPartialRefreshWindowTest("H", null, Boolean.FALSE,
false));
+ addTest(new FormPartialRefreshWindowTest("I", null, null, false));
}
catch (Exception e)
{
Added:
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/FormPartialRefreshWindowTest.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/FormPartialRefreshWindowTest.java
(rev 0)
+++
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/FormPartialRefreshWindowTest.java 2007-04-22
16:19:56 UTC (rev 7019)
@@ -0,0 +1,152 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.test.theme.dyna.tests.refresh;
+
+import org.jboss.portal.test.theme.DynaTest;
+import org.jboss.portal.test.theme.DynaTestContext;
+import org.jboss.portal.test.theme.RequestContext;
+import org.jboss.portal.test.theme.TestPhase;
+import org.jboss.portal.test.theme.ObjectURL;
+import org.jboss.portal.test.theme.model.PageObject;
+import org.jboss.portal.test.theme.model.RegionObject;
+import org.jboss.portal.test.theme.model.WindowObject;
+import org.jboss.portal.test.theme.model.RenderedObject;
+import org.jboss.portal.test.framework.driver.web.response.PerformClickResponse;
+import org.jboss.portal.theme.impl.render.dynamic.DynaRenderOptions;
+import org.jboss.portal.common.test.driver.DriverResponse;
+import org.jboss.portal.common.test.driver.response.EndTestResponse;
+import org.jboss.portal.common.util.MapBuilder;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FormPartialRefreshWindowTest extends DynaTest
+{
+
+ /** . */
+ private DynaTestContext dynaTestContext;
+
+ /** . */
+ private final Boolean regionPartialRefresh;
+
+ /** . */
+ private final Boolean windowPartialRefresh;
+
+ /** . */
+ private final boolean async;
+
+ public FormPartialRefreshWindowTest(
+ String id,
+ Boolean regionPartialRefresh,
+ Boolean windowPartialRefresh,
+ boolean async)
+ {
+ super(id);
+
+ //
+ this.regionPartialRefresh = regionPartialRefresh;
+ this.windowPartialRefresh = windowPartialRefresh;
+ this.async = async;
+ }
+
+ public void init(DynaTestContext dynaTestContext)
+ {
+ PageObject page = dynaTestContext.getPage();
+
+ //
+ RegionObject regionA = page.createRegion("RegionA");
+ regionA.setRenderOptions(DynaRenderOptions.getOptions(null,
regionPartialRefresh));
+
+ //
+ WindowObject window0 = regionA.addWindow("0");
+ window0.setRenderOptions(DynaRenderOptions.getOptions(null,
windowPartialRefresh));
+
+ //
+ this.dynaTestContext = dynaTestContext;
+ }
+
+ public DriverResponse invoke(RequestContext requestContext)
+ {
+ TestPhase phase = requestContext.getPhase();
+ if (phase.getLifeCycle() == TestPhase.RENDER_LIFE_CYCLE)
+ {
+ switch(phase.getCount())
+ {
+ case 0:
+ WindowObject window = dynaTestContext.getPage().getWindow("0");
+ ObjectURL url = requestContext.createURL(window);
+ url.setParameter("bar", "bar_value_1");
+ String markup = "<form action=\"" + url + "\"
method=\"post\">" +
+ "<input type=\"hidden\" name=\"foo\"
value=\"foo_value_1\">" +
+ "<input id=\"link\"
type=\"submit\">" +
+ "</form>";
+ window.setMarkup(markup);
+ return new PerformClickResponse("link");
+ case 1:
+ window = dynaTestContext.getPage().getWindow("0");
+ url = requestContext.createURL(window);
+ url.setParameter("bar", "bar_value_2");
+ markup = "<form action=\"" + url + "\"
method=\"post\">" +
+ "<input type=\"hidden\" name=\"foo\"
value=\"foo_value_2\">" +
+ "<input id=\"link\"
type=\"submit\">" +
+ "</form>";
+ window.setMarkup(markup);
+ return new PerformClickResponse("link");
+ case 2:
+ return new EndTestResponse();
+ default:
+ fail();
+ }
+ }
+ else
+ {
+ switch(phase.getCount())
+ {
+ case 1:
+ RenderedObject target = requestContext.getTarget();
+ assertNotNull(target);
+ assertTrue(target instanceof WindowObject);
+ WindowObject window = (WindowObject)target;
+ assertEquals("0", window.getId());
+ assertEquals(async, requestContext.isAsync());
+ assertEquals(new MapBuilder().put("foo",
"foo_value_1").put("bar", "bar_value_1").toHashMap(),
requestContext.getParameterMap());
+ return null;
+ case 2:
+ target = requestContext.getTarget();
+ assertNotNull(target);
+ assertTrue(target instanceof WindowObject);
+ window = (WindowObject)target;
+ assertEquals("0", window.getId());
+ assertEquals(async, requestContext.isAsync());
+ assertEquals(new MapBuilder().put("foo",
"foo_value_2").put("bar", "bar_value_2").toHashMap(),
requestContext.getParameterMap());
+ return null;
+ default:
+ fail();
+ }
+ }
+
+ //
+ return new EndTestResponse();
+ }
+}
Modified:
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/LinkPartialRefreshWindowTest.java
===================================================================
---
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/LinkPartialRefreshWindowTest.java 2007-04-22
14:39:07 UTC (rev 7018)
+++
trunk/theme/src/main/org/jboss/portal/test/theme/dyna/tests/refresh/LinkPartialRefreshWindowTest.java 2007-04-22
16:19:56 UTC (rev 7019)
@@ -97,14 +97,14 @@
case 0:
WindowObject window = dynaTestContext.getPage().getWindow("0");
ObjectURL url = requestContext.createURL(window);
- url.setParameter("abc", "def");
+ url.setParameter("foo", "foo_value_1");
String markup = "<a id=\"link\" href=\"" + url
+ "\">Click Me</a>";
window.setMarkup(markup);
return new PerformClickResponse("link");
case 1:
window = dynaTestContext.getPage().getWindow("0");
url = requestContext.createURL(window);
- url.setParameter("abc", "ghi");
+ url.setParameter("foo", "foo_value_2");
markup = "<a id=\"link\" href=\"" + url +
"\">Click Me</a>";
window.setMarkup(markup);
return new PerformClickResponse("link");
@@ -125,7 +125,7 @@
WindowObject window = (WindowObject)target;
assertEquals("0", window.getId());
assertEquals(async, requestContext.isAsync());
- assertEquals(Collections.singletonMap("abc", "def"),
requestContext.getParameterMap());
+ assertEquals(Collections.singletonMap("foo",
"foo_value_1"), requestContext.getParameterMap());
return null;
case 2:
target = requestContext.getTarget();
@@ -134,7 +134,7 @@
window = (WindowObject)target;
assertEquals("0", window.getId());
assertEquals(async, requestContext.isAsync());
- assertEquals(Collections.singletonMap("abc", "ghi"),
requestContext.getParameterMap());
+ assertEquals(Collections.singletonMap("foo",
"foo_value_2"), requestContext.getParameterMap());
return null;
default:
fail();