[Jsptest-svn-commits] SF.net SVN: jsptest: [222] trunk
Status: Alpha
Brought to you by:
lkoskela
From: <lko...@us...> - 2008-04-16 18:05:58
|
Revision: 222 http://jsptest.svn.sourceforge.net/jsptest/?rev=222&view=rev Author: lkoskela Date: 2008-04-16 11:05:56 -0700 (Wed, 16 Apr 2008) Log Message: ----------- No longer writing the rendering output into a temp file Modified Paths: -------------- trunk/jsptest-generic/jsptest-compiler-api/src/main/java/net/sf/jsptest/compiler/api/JspExecution.java trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/HtmlTestCase.java trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/JspTestCase.java trunk/jsptest-generic/jsptest-framework/src/test/java/net/sf/jsptest/compiler/dummy/FakeJspCompiler.java trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspExecutionImpl.java trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspImpl.java trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/TestJspImpl.java Modified: trunk/jsptest-generic/jsptest-compiler-api/src/main/java/net/sf/jsptest/compiler/api/JspExecution.java =================================================================== --- trunk/jsptest-generic/jsptest-compiler-api/src/main/java/net/sf/jsptest/compiler/api/JspExecution.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-generic/jsptest-compiler-api/src/main/java/net/sf/jsptest/compiler/api/JspExecution.java 2008-04-16 18:05:56 UTC (rev 222) @@ -1,8 +1,6 @@ package net.sf.jsptest.compiler.api; -import java.io.File; - public interface JspExecution { - File getRenderedResponse(); + String getRenderedResponse(); } Modified: trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/HtmlTestCase.java =================================================================== --- trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/HtmlTestCase.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/HtmlTestCase.java 2008-04-16 18:05:56 UTC (rev 222) @@ -19,6 +19,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -29,6 +30,7 @@ import net.sf.jsptest.assertion.FormAssertion; import net.sf.jsptest.assertion.NameChooser; import net.sf.jsptest.assertion.PageAssertion; +import net.sf.jsptest.utils.IO; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -43,118 +45,117 @@ */ public abstract class HtmlTestCase extends JspTestCase { - private Document renderedDocument; + private Document renderedDocument; - private String renderedDocumentPath; + private String renderedDocumentPath; - private Tidy tidy; + private Tidy tidy; - private DocumentBuilder documentBuilder; + private DocumentBuilder documentBuilder; - /** - * Simulate an HTTP request to a JSP, parsing the rendered output as HTML. - * - * @param path - * The path to the JSP to execute. - * @param httpMethod - * "GET" or "POST". - */ - protected void request(String path, String httpMethod) - throws Exception { - super.request(path, httpMethod); - parseRenderedHtml(); - } + /** + * Simulate an HTTP request to a JSP, parsing the rendered output as HTML. + * + * @param path + * The path to the JSP to execute. + * @param httpMethod + * "GET" or "POST". + */ + protected void request(String path, String httpMethod) throws Exception { + super.request(path, httpMethod); + parseRenderedHtml(); + } - /** - * Returns the rendered HTML as an <tt>org.w3c.dom.Document</tt>. - */ - protected Document getRenderedHtml() { - return renderedDocument; - } + /** + * Returns the rendered HTML as an <tt>org.w3c.dom.Document</tt>. + */ + protected Document getRenderedHtml() { + return renderedDocument; + } - /** - * Returns the path to the rendered (and pretty-printed) HTML document. - */ - protected String getRenderedHtmlPath() { - return renderedDocumentPath; - } + /** + * Returns the path to the rendered (and pretty-printed) HTML document. + */ + protected String getRenderedHtmlPath() { + return renderedDocumentPath; + } - private void parseRenderedHtml() { - File original = getRenderedResponse(); - File tidyHtml = new File(original.getAbsolutePath() - + ".tidy.html"); - parseRenderedOutput(original, tidyHtml); - } + private void parseRenderedHtml() { + try { + File original = File.createTempFile("renderedHtml", ".html"); + IO.write(getRenderedResponse(), original); + File tidyHtml = new File(original.getAbsolutePath() + ".tidy.html"); + parseRenderedOutput(original, tidyHtml); + } catch (IOException e) { + throw new RuntimeException(e); + } + } - private void parseRenderedOutput(File html, File prettyPrinted) { - try { - configureTidy().parse(new FileInputStream(html), - new FileOutputStream(prettyPrinted)); - DocumentBuilder db = configureDocumentBuilder(); - renderedDocument = db.parse(prettyPrinted); - renderedDocumentPath = prettyPrinted.getAbsolutePath(); - } catch (Throwable e) { - throw new RuntimeException(e.getMessage() + " (" - + html.getAbsolutePath() + ")", e); - } - } + private void parseRenderedOutput(File html, File prettyPrinted) { + try { + configureTidy().parse(new FileInputStream(html), + new FileOutputStream(prettyPrinted)); + DocumentBuilder db = configureDocumentBuilder(); + renderedDocument = db.parse(prettyPrinted); + renderedDocumentPath = prettyPrinted.getAbsolutePath(); + } catch (Throwable e) { + throw new RuntimeException(e.getMessage() + " (" + + html.getAbsolutePath() + ")", e); + } + } - private synchronized DocumentBuilder configureDocumentBuilder() - throws ParserConfigurationException { - if (documentBuilder == null) { - DocumentBuilderFactory dbf = DocumentBuilderFactory - .newInstance(); - documentBuilder = dbf.newDocumentBuilder(); - } - return documentBuilder; - } + private synchronized DocumentBuilder configureDocumentBuilder() + throws ParserConfigurationException { + if (documentBuilder == null) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + documentBuilder = dbf.newDocumentBuilder(); + } + return documentBuilder; + } - private synchronized Tidy configureTidy() { - if (tidy == null) { - tidy = new Tidy(); - tidy.setMakeClean(true); - tidy.setXmlOut(true); - tidy.setTidyMark(false); - tidy.setQuiet(true); - tidy.setShowWarnings(false); - tidy.setUpperCaseTags(true); - tidy.setUpperCaseAttrs(true); - } - return tidy; - } + private synchronized Tidy configureTidy() { + if (tidy == null) { + tidy = new Tidy(); + tidy.setMakeClean(true); + tidy.setXmlOut(true); + tidy.setTidyMark(false); + tidy.setQuiet(true); + tidy.setShowWarnings(false); + tidy.setUpperCaseTags(true); + tidy.setUpperCaseAttrs(true); + } + return tidy; + } - /** - * Returns a handle for making assertions about the specified HTML form. - */ - public FormAssertion form(String name) { - return new FormAssertion(getRenderedHtml(), new NameChooser( - name)); - } + /** + * Returns a handle for making assertions about the specified HTML form. + */ + public FormAssertion form(String name) { + return new FormAssertion(getRenderedHtml(), new NameChooser(name)); + } - /** - * Returns a handle for making assertions about an HTML form. - */ - public FormAssertion form() { - return new FormAssertion(getRenderedHtml(), - new ElementChooser() { - public boolean accept(Element element) { - return true; - } - }); - } + /** + * Returns a handle for making assertions about an HTML form. + */ + public FormAssertion form() { + return new FormAssertion(getRenderedHtml(), new ElementChooser() { + public boolean accept(Element element) { + return true; + } + }); + } - /** - * Returns a handle for making assertions about the rendered HTML page. - */ - public PageAssertion page() { - return new PageAssertion(getRenderedHtml()); - } + /** + * Returns a handle for making assertions about the rendered HTML page. + */ + public PageAssertion page() { + return new PageAssertion(getRenderedHtml()); + } - /** - * Returns a handle for making assertions about the specified HTML element. - */ - public ElementAssertion element(String xpathExpression) { - return new ElementAssertion(getRenderedHtml(), - xpathExpression); - } + /** + * Returns a handle for making assertions about the specified HTML element. + */ + public ElementAssertion element(String xpathExpression) { + return new ElementAssertion(getRenderedHtml(), xpathExpression); + } } Modified: trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/JspTestCase.java =================================================================== --- trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/JspTestCase.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/JspTestCase.java 2008-04-16 18:05:56 UTC (rev 222) @@ -17,20 +17,18 @@ package net.sf.jsptest; import java.io.File; -import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; - import junit.framework.TestCase; import net.sf.jsptest.assertion.OutputAssertion; import net.sf.jsptest.compiler.api.Jsp; import net.sf.jsptest.compiler.api.JspCompiler; import net.sf.jsptest.compiler.api.JspCompilerFactory; import net.sf.jsptest.compiler.api.JspExecution; -import net.sf.jsptest.utils.IO; +import org.apache.log4j.Logger; + /** * An abstract base class to be extended by the user. The <tt>JspTestCase</tt> * class provides a facility for rendering a JSP and a set of assertion methods @@ -40,150 +38,142 @@ */ public abstract class JspTestCase extends TestCase { - private Logger log; + private Logger log; - private Map requestAttributes; + private Map requestAttributes; - private Map sessionAttributes; + private Map sessionAttributes; - private Map substituteTaglibs; + private Map substituteTaglibs; - private JspExecution execution; + private JspExecution execution; - public JspTestCase() { - log = Logger.getLogger(getClass()); - } + public JspTestCase() { + log = Logger.getLogger(getClass()); + } - /** - * The standard JUnit <tt>setUp()</tt> method. <b>Remember to invoke - * <tt>super.setUp()</tt> if you override this!</b> - */ - protected void setUp() throws Exception { - requestAttributes = new HashMap(); - sessionAttributes = new HashMap(); - substituteTaglibs = new HashMap(); - } + /** + * The standard JUnit <tt>setUp()</tt> method. <b>Remember to invoke + * <tt>super.setUp()</tt> if you override this!</b> + */ + protected void setUp() throws Exception { + requestAttributes = new HashMap(); + sessionAttributes = new HashMap(); + substituteTaglibs = new HashMap(); + } - /** - * Override this method to tell the JSP compiler where the "web" files are - * located. Defaults to the current working directory. - */ - protected String getWebRoot() { - return "."; - } + /** + * Override this method to tell the JSP compiler where the "web" files are + * located. Defaults to the current working directory. + */ + protected String getWebRoot() { + return "."; + } - /** - * Sets a session attribute for the current session. - * - * @param attribute - * Name of the attribute. - * @param value - * Value for the attribute. - */ - protected void setSessionAttribute(String attribute, Object value) { - sessionAttributes.put(attribute, value); - } + /** + * Sets a session attribute for the current session. + * + * @param attribute + * Name of the attribute. + * @param value + * Value for the attribute. + */ + protected void setSessionAttribute(String attribute, Object value) { + sessionAttributes.put(attribute, value); + } - /** - * Sets a request attribute for the next request. - * - * @param attribute - * Name of the attribute. - * @param value - * Value for the attribute. - */ - protected void setRequestAttribute(String attribute, Object value) { - requestAttributes.put(attribute, value); - } + /** + * Sets a request attribute for the next request. + * + * @param attribute + * Name of the attribute. + * @param value + * Value for the attribute. + */ + protected void setRequestAttribute(String attribute, Object value) { + requestAttributes.put(attribute, value); + } - /** - * Simulate a HTTP GET request to the specified JSP file. - * - * @param path - * The JSP file to render. The path should start with a "/" - * and is interpreted to be relative to the web root - * specified by <tt>getWebRoot</tt>. - */ - protected void get(String path) throws Exception { - request(path, "GET"); - } + /** + * Simulate a HTTP GET request to the specified JSP file. + * + * @param path + * The JSP file to render. The path should start with a "/" and + * is interpreted to be relative to the web root specified by + * <tt>getWebRoot</tt>. + */ + protected void get(String path) throws Exception { + request(path, "GET"); + } - /** - * Simulate a HTTP POST request to the specified JSP file. - * - * @param path - * The JSP file to render. The path should start with a "/" - * and is interpreted to be relative to the web root - * specified by <tt>getWebRoot</tt>. - */ - protected void post(String path) throws Exception { - request(path, "POST"); - } + /** + * Simulate a HTTP POST request to the specified JSP file. + * + * @param path + * The JSP file to render. The path should start with a "/" and + * is interpreted to be relative to the web root specified by + * <tt>getWebRoot</tt>. + */ + protected void post(String path) throws Exception { + request(path, "POST"); + } - /** - * Simulate an HTTP request to a JSP. - * - * @param path - * The path to the JSP to execute. - * @param httpMethod - * "GET" or "POST". - */ - protected void request(String path, String httpMethod) - throws Exception { - validatePath(path); - JspCompiler compiler = JspCompilerFactory.newInstance(); - log.debug("Using compiler " + compiler.getClass().getName() - + " and webroot " - + new File(getWebRoot()).getAbsolutePath()); - compiler.setWebRoot(getWebRoot()); - compiler.setOutputDirectory(getOutputDirectory()); - Jsp jsp = compiler.compile(path, substituteTaglibs); - log.debug("Simulating a request to " + path); - execution = jsp.request(httpMethod, requestAttributes, - sessionAttributes); - } + /** + * Simulate an HTTP request to a JSP. + * + * @param path + * The path to the JSP to execute. + * @param httpMethod + * "GET" or "POST". + */ + protected void request(String path, String httpMethod) throws Exception { + validatePath(path); + JspCompiler compiler = JspCompilerFactory.newInstance(); + log.debug("Using compiler " + compiler.getClass().getName() + + " and webroot " + new File(getWebRoot()).getAbsolutePath()); + compiler.setWebRoot(getWebRoot()); + compiler.setOutputDirectory(getOutputDirectory()); + Jsp jsp = compiler.compile(path, substituteTaglibs); + log.debug("Simulating a request to " + path); + execution = jsp.request(httpMethod, requestAttributes, + sessionAttributes); + } - private void validatePath(String path) { - if (!path.startsWith("/")) { - throw new IllegalArgumentException( - "The JSP path must start with a \"/\""); - } - } + private void validatePath(String path) { + if (!path.startsWith("/")) { + throw new IllegalArgumentException( + "The JSP path must start with a \"/\""); + } + } - private String getOutputDirectory() { - return "target/jsptest"; - } + private String getOutputDirectory() { + return "target/jsptest"; + } - /** - * Returns a handle to a file containing the rendered output. - */ - protected File getRenderedResponse() { - return execution.getRenderedResponse(); - } + /** + * Returns the rendered output. + */ + protected String getRenderedResponse() { + return execution.getRenderedResponse(); + } - /** - * Returns a handle for making assertions about the rendered content. - */ - public OutputAssertion output() { - try { - return new OutputAssertion(IO - .readToString(getRenderedResponse())); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + /** + * Returns a handle for making assertions about the rendered content. + */ + public OutputAssertion output() { + return new OutputAssertion(getRenderedResponse()); + } - /** - * Invoke this method to substitute the specified taglib with the given - * implementation. - * - * @param name - * The name of the taglib to replace. - * @param newImplementation - * The new (substitute) implementation to use. - */ - protected void substituteTaglib(String name, - Class newImplementation) { - substituteTaglibs.put(name, newImplementation); - } + /** + * Invoke this method to substitute the specified taglib with the given + * implementation. + * + * @param name + * The name of the taglib to replace. + * @param newImplementation + * The new (substitute) implementation to use. + */ + protected void substituteTaglib(String name, Class newImplementation) { + substituteTaglibs.put(name, newImplementation); + } } Modified: trunk/jsptest-generic/jsptest-framework/src/test/java/net/sf/jsptest/compiler/dummy/FakeJspCompiler.java =================================================================== --- trunk/jsptest-generic/jsptest-framework/src/test/java/net/sf/jsptest/compiler/dummy/FakeJspCompiler.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-generic/jsptest-framework/src/test/java/net/sf/jsptest/compiler/dummy/FakeJspCompiler.java 2008-04-16 18:05:56 UTC (rev 222) @@ -1,71 +1,60 @@ package net.sf.jsptest.compiler.dummy; -import java.io.File; -import java.io.IOException; import java.util.Map; import net.sf.jsptest.compiler.api.Jsp; import net.sf.jsptest.compiler.api.JspCompiler; import net.sf.jsptest.compiler.api.JspExecution; -import net.sf.jsptest.utils.IO; public class FakeJspCompiler implements JspCompiler { - private static StringBuffer fakedOutput = new StringBuffer(2000); + private static StringBuffer fakedOutput = new StringBuffer(2000); - private static String lastCompiledPath; + private static String lastCompiledPath; - private static String lastCompiledWebRoot; + private static String lastCompiledWebRoot; - private String webRoot; + private String webRoot; - public void setWebRoot(String directory) { - this.webRoot = directory; - } + public void setWebRoot(String directory) { + this.webRoot = directory; + } - protected String getWebRoot() { - return webRoot; - } + protected String getWebRoot() { + return webRoot; + } - public static void cleanOutput() { - fakedOutput.setLength(0); - } + public static void cleanOutput() { + fakedOutput.setLength(0); + } - public static void appendOutput(String content) { - fakedOutput.append(content); - } + public static void appendOutput(String content) { + fakedOutput.append(content); + } - public Jsp compile(String path, Map taglibs) { - lastCompiledWebRoot = getWebRoot(); - lastCompiledPath = path; - return new Jsp() { - public JspExecution request(String httpMethod, - Map requestAttributes, Map sessionAttributes) { - return new JspExecution() { - public File getRenderedResponse() { - try { - File file = File.createTempFile( - "dummyOutput", ".html"); - file.deleteOnExit(); - IO.write(fakedOutput.toString(), file); - return file; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }; - } - }; - } + public Jsp compile(String path, Map taglibs) { + lastCompiledWebRoot = getWebRoot(); + lastCompiledPath = path; + return new Jsp() { + public JspExecution request(String httpMethod, + Map requestAttributes, Map sessionAttributes) { + return new JspExecution() { + public String getRenderedResponse() { + return fakedOutput.toString(); + } + }; + } + }; + } - public static String lastCompiledPath() { - return lastCompiledPath; - } + public static String lastCompiledPath() { + return lastCompiledPath; + } - public static String lastCompiledWebRoot() { - return lastCompiledWebRoot; - } + public static String lastCompiledWebRoot() { + return lastCompiledWebRoot; + } - public void setOutputDirectory(String directory) { - } + public void setOutputDirectory(String directory) { + } } Modified: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspExecutionImpl.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspExecutionImpl.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspExecutionImpl.java 2008-04-16 18:05:56 UTC (rev 222) @@ -1,18 +1,16 @@ package net.sf.jsptest.compiler.jsp20; -import java.io.File; - import net.sf.jsptest.compiler.api.JspExecution; public class JspExecutionImpl implements JspExecution { - private final File renderedOutput; + private final String renderedOutput; - public JspExecutionImpl(File renderedOutput) { - this.renderedOutput = renderedOutput; - } + public JspExecutionImpl(String output) { + this.renderedOutput = output; + } - public File getRenderedResponse() { - return renderedOutput; - } + public String getRenderedResponse() { + return renderedOutput; + } } Modified: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspImpl.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspImpl.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspImpl.java 2008-04-16 18:05:56 UTC (rev 222) @@ -1,7 +1,5 @@ package net.sf.jsptest.compiler.jsp20; -import java.io.File; -import java.io.IOException; import java.util.Map; import javax.servlet.ServletConfig; @@ -12,9 +10,6 @@ import javax.servlet.http.HttpSession; import javax.servlet.jsp.JspFactory; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import net.sf.jsptest.compiler.api.Jsp; import net.sf.jsptest.compiler.api.JspExecution; import net.sf.jsptest.compiler.jsp20.mock.MockHttpServletRequest; @@ -25,137 +20,78 @@ import net.sf.jsptest.compiler.jsp20.mock.MockPageContext; import net.sf.jsptest.compiler.jsp20.mock.MockServletConfig; import net.sf.jsptest.compiler.jsp20.mock.MockServletContext; -import net.sf.jsptest.utils.IO; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + public class JspImpl implements Jsp { - private static final Log log = LogFactory.getLog(JspImpl.class); + private static final Log log = LogFactory.getLog(JspImpl.class); - private final Class servletClass; + private final Class servletClass; - private MockPageContext pageContext; + private MockPageContext pageContext; - public JspImpl(Class servletClass) { - this.servletClass = servletClass; - } + public JspImpl(Class servletClass) { + this.servletClass = servletClass; + } - public JspExecution request(String httpMethod, - Map requestAttributes, Map sessionAttributes) { - ServletContext servletContext = new MockServletContext(); - ServletConfig servletConfig = new MockServletConfig( - servletContext); + public JspExecution request(String httpMethod, Map requestAttributes, + Map sessionAttributes) { + ServletContext servletContext = new MockServletContext(); + ServletConfig servletConfig = new MockServletConfig(servletContext); - MockHttpSession httpSession = new MockHttpSession(); - httpSession.setAttributes(sessionAttributes); + MockHttpSession httpSession = new MockHttpSession(); + httpSession.setAttributes(sessionAttributes); - MockHttpServletRequest request = new MockHttpServletRequest(); - request.setSession(httpSession); - request.setMethod(httpMethod); - request.setAttributes(requestAttributes); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setSession(httpSession); + request.setMethod(httpMethod); + request.setAttributes(requestAttributes); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); - MockJspWriter jspWriter = configureJspFactory(servletContext, - request, httpSession); + MockJspWriter jspWriter = configureJspFactory(servletContext, request, + httpSession); - initializeAndInvokeJsp(servletClass, servletConfig, request, - response); + initializeAndInvokeJsp(servletClass, servletConfig, request, response); - return writeOutputToTempFile(jspWriter.getContents()); - } + return createExecutionResult(jspWriter.getContents()); + } - protected MockJspWriter configureJspFactory( - ServletContext httpContext, - HttpServletRequest httpRequest, HttpSession httpSession) { - pageContext = new MockPageContext(); - pageContext.setRequest(httpRequest); - pageContext.setServletContext(httpContext); - pageContext.setSession(httpSession); - MockJspWriter jspWriter = new MockJspWriter(); - pageContext.setJspWriter(jspWriter); - JspFactory.setDefaultFactory(new MockJspFactory(pageContext)); - return jspWriter; - } + protected MockJspWriter configureJspFactory(ServletContext httpContext, + HttpServletRequest httpRequest, HttpSession httpSession) { + pageContext = new MockPageContext(); + pageContext.setRequest(httpRequest); + pageContext.setServletContext(httpContext); + pageContext.setSession(httpSession); + MockJspWriter jspWriter = new MockJspWriter(); + pageContext.setJspWriter(jspWriter); + JspFactory.setDefaultFactory(new MockJspFactory(pageContext)); + return jspWriter; + } - protected void initializeAndInvokeJsp(Class jspClass, - ServletConfig servletConfig, HttpServletRequest request, - HttpServletResponse response) { - try { - log.debug("Instantiating Servlet: " + jspClass.getName()); - HttpServlet servlet = (HttpServlet) jspClass - .newInstance(); - log.debug("Initializing Servlet: " + jspClass.getName()); - servlet.init(servletConfig); - log.debug("Invoking Servlet: " + jspClass.getName()); - servlet.service(request, response); - if (pageContext.getException() != null) { - log.debug("An exception was stored into PageContext. Rethrowing it..."); - throw new RuntimeException(pageContext.getException()); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } + protected void initializeAndInvokeJsp(Class jspClass, + ServletConfig servletConfig, HttpServletRequest request, + HttpServletResponse response) { + try { + log.debug("Instantiating Servlet: " + jspClass.getName()); + HttpServlet servlet = (HttpServlet) jspClass.newInstance(); + log.debug("Initializing Servlet: " + jspClass.getName()); + servlet.init(servletConfig); + log.debug("Invoking Servlet: " + jspClass.getName()); + servlet.service(request, response); + if (pageContext.getException() != null) { + log + .debug("An exception was stored into PageContext. Rethrowing it..."); + throw new RuntimeException(pageContext.getException()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } - protected JspExecution writeOutputToTempFile(String output) { - try { - File temp = File.createTempFile("generated_html_", - ".html"); - temp.createNewFile(); - log.debug("Writing " + output.length() + " bytes to " - + temp.getAbsolutePath()); - IO.write(output, temp); - return new JspExecutionImpl(temp); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - // public JspExecution request(String httpMethod, - // Map requestAttributes, Map sessionAttributes) { - // try { - // final File responseFile = File.createTempFile( - // "jsptest-response", ".txt"); - // HttpServlet servlet = (HttpServlet) servletClass - // .newInstance(); - // servlet.init(new MockServletConfig( - // new MockServletContext())); - // - // ServletRequest request = createServletRequest(httpMethod, - // requestAttributes, sessionAttributes); - // ServletResponse response = createServletResponse(responseFile); - // - // servlet.service(request, response); - // - // response.flushBuffer(); - // - // return createJspExecution(responseFile); - // } catch (Exception e) { - // throw new RuntimeException(e); - // } - // } - // - // protected JspExecution createJspExecution(final File responseFile) { - // return new JspExecution() { - // public File getRenderedResponse() { - // return responseFile; - // } - // }; - // } - // - // protected ServletResponse createServletResponse(File output) - // throws FileNotFoundException { - // return new MockHttpServletResponse(output); - // } - // - // private ServletRequest createServletRequest(String httpMethod, - // Map requestAttributes, Map sessionAttributes) { - // MockHttpSession session = new MockHttpSession(); - // session.setAttributes(sessionAttributes); - // MockHttpServletRequest request = new MockHttpServletRequest(); - // request.setMethod(httpMethod); - // request.setAttributes(requestAttributes); - // request.setSession(session); - // return request; - // } + protected JspExecution createExecutionResult(String output) { + return new JspExecutionImpl(output); + } } Modified: trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/TestJspImpl.java =================================================================== --- trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/TestJspImpl.java 2008-04-16 17:56:48 UTC (rev 221) +++ trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/TestJspImpl.java 2008-04-16 18:05:56 UTC (rev 222) @@ -1,6 +1,5 @@ package net.sf.jsptest.compiler.jsp20; -import java.io.File; import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; @@ -57,7 +56,7 @@ } } - protected File responseFile; + protected String responseOutput; private JspImpl jspImpl; @@ -109,7 +108,7 @@ private void simulateRequest(String method) { JspExecution execution = jspImpl.request(method, requestAttributes, sessionAttributes); - responseFile = execution.getRenderedResponse(); + responseOutput = execution.getRenderedResponse(); } private void assertOutputContains(String string) throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |