Browse Source

MockHttpServletResponse supports multiple includes (SPR-7188)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3323 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
9fa9615409
  1. 25
      org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java
  2. 4
      org.springframework.test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java

25
org.springframework.test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -98,7 +98,7 @@ public class MockHttpServletResponse implements HttpServletResponse { @@ -98,7 +98,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
private String forwardedUrl;
private String includedUrl;
private final List<String> includedUrls = new ArrayList<String>();
//---------------------------------------------------------------------
@ -443,11 +443,28 @@ public class MockHttpServletResponse implements HttpServletResponse { @@ -443,11 +443,28 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
public void setIncludedUrl(String includedUrl) {
this.includedUrl = includedUrl;
this.includedUrls.clear();
if (includedUrl != null) {
this.includedUrls.add(includedUrl);
}
}
public String getIncludedUrl() {
return this.includedUrl;
int count = this.includedUrls.size();
if (count > 1) {
throw new IllegalStateException(
"More than 1 URL included - check getIncludedUrls instead: " + this.includedUrls);
}
return (count == 1 ? this.includedUrls.get(0) : null);
}
public void addIncludedUrl(String includedUrl) {
Assert.notNull(includedUrl, "Included URL must not be null");
this.includedUrls.add(includedUrl);
}
public List<String> getIncludedUrls() {
return this.includedUrls;
}

4
org.springframework.test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -68,7 +68,7 @@ public class MockRequestDispatcher implements RequestDispatcher { @@ -68,7 +68,7 @@ public class MockRequestDispatcher implements RequestDispatcher {
public void include(ServletRequest request, ServletResponse response) {
Assert.notNull(request, "Request must not be null");
Assert.notNull(response, "Response must not be null");
getMockHttpServletResponse(response).setIncludedUrl(this.url);
getMockHttpServletResponse(response).addIncludedUrl(this.url);
if (logger.isDebugEnabled()) {
logger.debug("MockRequestDispatcher: including URL [" + this.url + "]");
}

Loading…
Cancel
Save