added getContentAsByteArray() and getContentAsString() methods (SPR-8575); actually implemented forward, include and handlePageException methods
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.mock.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -314,24 +315,37 @@ public class MockPageContext extends PageContext {
|
||||
return this.servletContext;
|
||||
}
|
||||
|
||||
public void forward(String url) throws ServletException, IOException {
|
||||
throw new UnsupportedOperationException("forward");
|
||||
public void forward(String path) throws ServletException, IOException {
|
||||
this.request.getRequestDispatcher(path).forward(this.request, this.response);
|
||||
}
|
||||
|
||||
public void include(String url) throws ServletException, IOException {
|
||||
throw new UnsupportedOperationException("include");
|
||||
public void include(String path) throws ServletException, IOException {
|
||||
this.request.getRequestDispatcher(path).include(this.request, this.response);
|
||||
}
|
||||
|
||||
public void include(String url, boolean flush) throws ServletException, IOException {
|
||||
throw new UnsupportedOperationException("include");
|
||||
public void include(String path, boolean flush) throws ServletException, IOException {
|
||||
this.request.getRequestDispatcher(path).include(this.request, this.response);
|
||||
if (flush) {
|
||||
this.response.flushBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getContentAsByteArray() {
|
||||
Assert.isTrue(this.response instanceof MockHttpServletResponse);
|
||||
return ((MockHttpServletResponse) this.response).getContentAsByteArray();
|
||||
}
|
||||
|
||||
public String getContentAsString() throws UnsupportedEncodingException {
|
||||
Assert.isTrue(this.response instanceof MockHttpServletResponse);
|
||||
return ((MockHttpServletResponse) this.response).getContentAsString();
|
||||
}
|
||||
|
||||
public void handlePageException(Exception ex) throws ServletException, IOException {
|
||||
throw new UnsupportedOperationException("handlePageException");
|
||||
throw new ServletException("Page exception", ex);
|
||||
}
|
||||
|
||||
public void handlePageException(Throwable ex) throws ServletException, IOException {
|
||||
throw new UnsupportedOperationException("handlePageException");
|
||||
throw new ServletException("Page exception", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user