SWF-1367 Add support for JSF 2 Ajax requests, update booking-faces sample (JSF 2 based Ajax, jsr-303 validation), add chained delegation to AjaxHandlers, other miscellaneous improvements
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
package org.springframework.js.ajax;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
public class AbstractAjaxHandlerTests extends TestCase {
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
public void testIsAjaxRequest() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, true);
|
||||
assertTrue(handler.isAjaxRequest(request, response));
|
||||
}
|
||||
|
||||
public void testIsNotAjaxRequest() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, false);
|
||||
assertFalse(handler.isAjaxRequest(request, response));
|
||||
}
|
||||
|
||||
public void testIsAjaxRequestViaDelegate() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(new TestAjaxHandler(null, true), false);
|
||||
assertTrue(handler.isAjaxRequest(request, response));
|
||||
}
|
||||
|
||||
public void testSendAjaxRedirect() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, true);
|
||||
handler.sendAjaxRedirect("", request, response, false);
|
||||
assertTrue(handler.wasAjaxRedirectInternalCalled);
|
||||
}
|
||||
|
||||
public void testAjaxRedirectNotSent() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(null, false);
|
||||
handler.sendAjaxRedirect("", request, response, false);
|
||||
assertFalse(handler.wasAjaxRedirectInternalCalled());
|
||||
}
|
||||
|
||||
public void testSendAjaxRedirectViaDelegate() throws Exception {
|
||||
TestAjaxHandler handler = new TestAjaxHandler(new TestAjaxHandler(null, true), false);
|
||||
handler.sendAjaxRedirect("", request, response, false);
|
||||
assertTrue(handler.wasAjaxRedirectInternalCalled());
|
||||
}
|
||||
|
||||
private final class TestAjaxHandler extends AbstractAjaxHandler {
|
||||
|
||||
private boolean isAjaxRequest;
|
||||
private boolean wasAjaxRedirectInternalCalled;
|
||||
private TestAjaxHandler delegate;
|
||||
|
||||
private TestAjaxHandler(TestAjaxHandler delegate, boolean isAjaxRequest) {
|
||||
super(delegate);
|
||||
this.delegate = delegate;
|
||||
this.isAjaxRequest = isAjaxRequest;
|
||||
}
|
||||
|
||||
protected boolean isAjaxRequestInternal(HttpServletRequest request, HttpServletResponse response) {
|
||||
return isAjaxRequest;
|
||||
}
|
||||
|
||||
protected void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request,
|
||||
HttpServletResponse response, boolean popup) throws IOException {
|
||||
wasAjaxRedirectInternalCalled = true;
|
||||
}
|
||||
|
||||
public TestAjaxHandler getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public boolean wasAjaxRedirectInternalCalled() {
|
||||
if (wasAjaxRedirectInternalCalled) {
|
||||
return true;
|
||||
} else {
|
||||
return (getDelegate() != null) ? delegate.wasAjaxRedirectInternalCalled() : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class ResourceServletTests extends TestCase {
|
||||
|
||||
public final void testExecute() throws Exception {
|
||||
|
||||
String requestPath = "/dojo/dojo.js";
|
||||
String requestPath = "/spring/Spring.js";
|
||||
request.setPathInfo(requestPath);
|
||||
servlet.doGet(request, response);
|
||||
|
||||
@@ -41,10 +41,10 @@ public class ResourceServletTests extends TestCase {
|
||||
|
||||
public final void testExecute_CombinedResources() throws Exception {
|
||||
|
||||
String requestPath = "/dojo/dojo.js";
|
||||
String requestPath = "/spring/Spring.js";
|
||||
request.setPathInfo(requestPath);
|
||||
Map params = new HashMap();
|
||||
params.put("appended", "/dijit/dijit.js,/dijit/Dialog.js");
|
||||
params.put("appended", "/spring/Spring-Dojo.js");
|
||||
request.setParameters(params);
|
||||
servlet.doGet(request, response);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ResourceServletTests extends TestCase {
|
||||
|
||||
public final void testExecute_CompressedResponse() throws Exception {
|
||||
|
||||
String requestPath = "/dojo/dojo.js";
|
||||
String requestPath = "/spring/Spring.js";
|
||||
request.setPathInfo(requestPath);
|
||||
request.addHeader("Accept-Encoding", "gzip");
|
||||
servlet.doGet(request, response);
|
||||
|
||||
Reference in New Issue
Block a user