[Jsptest-svn-commits] SF.net SVN: jsptest: [190] trunk
Status: Alpha
Brought to you by:
lkoskela
|
From: <lko...@us...> - 2008-01-14 06:31:41
|
Revision: 190
http://jsptest.svn.sourceforge.net/jsptest/?rev=190&view=rev
Author: lkoskela
Date: 2008-01-13 22:31:40 -0800 (Sun, 13 Jan 2008)
Log Message:
-----------
Removed dead code and unused imports
Modified Paths:
--------------
trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/JspTestCase.java
trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspCompilerImpl.java
trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/TestJspImpl.java
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-01-14 06:21:07 UTC (rev 189)
+++ trunk/jsptest-generic/jsptest-framework/src/main/java/net/sf/jsptest/JspTestCase.java 2008-01-14 06:31:40 UTC (rev 190)
@@ -92,14 +92,6 @@
requestAttributes.put(attribute, value);
}
- private Map getRequestAttributes() {
- return requestAttributes;
- }
-
- private Map getSessionAttributes() {
- return sessionAttributes;
- }
-
/**
* Simulate a HTTP GET request to the specified JSP file.
*
Modified: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspCompilerImpl.java
===================================================================
--- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspCompilerImpl.java 2008-01-14 06:21:07 UTC (rev 189)
+++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JspCompilerImpl.java 2008-01-14 06:31:40 UTC (rev 190)
@@ -1,70 +1,57 @@
package net.sf.jsptest.compiler.jsp20;
import java.io.File;
-import java.io.FileNotFoundException;
import java.util.Map;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServlet;
-
import net.sf.jsptest.compiler.JspCompilationInfo;
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.compiler.jsp20.mock.MockHttpServletRequest;
-import net.sf.jsptest.compiler.jsp20.mock.MockHttpServletResponse;
-import net.sf.jsptest.compiler.jsp20.mock.MockHttpSession;
-import net.sf.jsptest.compiler.jsp20.mock.MockServletConfig;
-import net.sf.jsptest.compiler.jsp20.mock.MockServletContext;
import net.sf.jsptest.utils.CustomClassLoader;
public class JspCompilerImpl implements JspCompiler {
- private String outputDirectory = new File(System
- .getProperty("java.io.tmpdir"), "jsptest-classes")
- .getAbsolutePath();
- private String webRoot;
+ private String outputDirectory = new File(System
+ .getProperty("java.io.tmpdir"), "jsptest-classes")
+ .getAbsolutePath();
+ private String webRoot;
- public void setOutputDirectory(String directory) {
- outputDirectory = directory;
- }
+ public void setOutputDirectory(String directory) {
+ outputDirectory = directory;
+ }
- protected String getOutputDirectory() {
- return outputDirectory;
- }
+ protected String getOutputDirectory() {
+ return outputDirectory;
+ }
- public void setWebRoot(String directory) {
- this.webRoot = directory;
- }
-
- protected String getWebRoot() {
- return webRoot;
- }
+ public void setWebRoot(String directory) {
+ this.webRoot = directory;
+ }
- public Jsp compile(final String jspPath,
- Map taglibs) {
- try {
- JasperCompiler compiler = new JasperCompiler();
- compiler.setWebRoot(getWebRoot());
- compiler.setClassOutputBaseDir(getOutputDirectory());
- JspCompilationInfo info = compiler.compile(jspPath,
- taglibs);
- final Class servletClass = compileToClass(info);
- return new JspImpl(servletClass);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ protected String getWebRoot() {
+ return webRoot;
+ }
- private Class compileToClass(JspCompilationInfo compilation)
- throws Exception, ClassNotFoundException {
- return loadJspClass(compilation.getClassName());
- }
+ public Jsp compile(final String jspPath, Map taglibs) {
+ try {
+ JasperCompiler compiler = new JasperCompiler();
+ compiler.setWebRoot(getWebRoot());
+ compiler.setClassOutputBaseDir(getOutputDirectory());
+ JspCompilationInfo info = compiler.compile(jspPath, taglibs);
+ final Class servletClass = compileToClass(info);
+ return new JspImpl(servletClass);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- private Class loadJspClass(String jspClassName)
- throws ClassNotFoundException {
- ClassLoader cl = new CustomClassLoader(getOutputDirectory());
- return cl.loadClass(jspClassName);
- }
+ private Class compileToClass(JspCompilationInfo compilation)
+ throws Exception, ClassNotFoundException {
+ return loadJspClass(compilation.getClassName());
+ }
+
+ private Class loadJspClass(String jspClassName)
+ throws ClassNotFoundException {
+ ClassLoader cl = new CustomClassLoader(getOutputDirectory());
+ return cl.loadClass(jspClassName);
+ }
}
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-01-14 06:21:07 UTC (rev 189)
+++ trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/TestJspImpl.java 2008-01-14 06:31:40 UTC (rev 190)
@@ -6,7 +6,6 @@
import java.util.HashMap;
import java.util.Map;
-import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -20,113 +19,103 @@
import net.sf.jsptest.compiler.api.JspExecution;
import net.sf.jsptest.compiler.jsp20.mock.MockJspWriter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
public class TestJspImpl extends TestCase {
- private static final Log log = LogFactory
- .getLog(TestJspImpl.class);
+ public static class FakeServlet extends javax.servlet.http.HttpServlet {
- public static class FakeServlet extends
- javax.servlet.http.HttpServlet {
+ protected void service(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ JspFactory _jspxFactory = JspFactory.getDefaultFactory();
+ resp.setContentType("text/html");
+ PageContext pageContext = _jspxFactory.getPageContext(this, req,
+ resp, null, true, 8192, true);
+ JspWriter out = pageContext.getOut();
+ // this is the way Jasper's JspServlet obtains the session
+ HttpSession session = pageContext.getSession();
- protected void service(HttpServletRequest req,
- HttpServletResponse resp) throws ServletException,
- IOException {
- JspFactory _jspxFactory = JspFactory.getDefaultFactory();
- resp.setContentType("text/html");
- PageContext pageContext = _jspxFactory.getPageContext(
- this, req, resp, null, true, 8192, true);
- JspWriter out = pageContext.getOut();
- // this is the way Jasper's JspServlet obtains the session
- HttpSession session = pageContext.getSession();
+ out.println("httpMethod=" + req.getMethod());
- out.println("httpMethod=" + req.getMethod());
+ Enumeration names = req.getAttributeNames();
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+ out.print(name);
+ out.print("=");
+ out.println(req.getAttribute(name));
+ }
- Enumeration names = req.getAttributeNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- out.print(name);
- out.print("=");
- out.println(req.getAttribute(name));
- }
+ Enumeration names2 = session.getAttributeNames();
+ while (names2.hasMoreElements()) {
+ String name = (String) names2.nextElement();
+ out.print(name);
+ out.print("=");
+ out.println(session.getAttribute(name));
+ }
- Enumeration names2 = session.getAttributeNames();
- while (names2.hasMoreElements()) {
- String name = (String) names2.nextElement();
- out.print(name);
- out.print("=");
- out.println(session.getAttribute(name));
- }
+ out.println();
+ out.flush();
+ out.close();
+ }
+ }
- out.println();
- out.flush();
- out.close();
- }
- }
+ protected File responseFile;
- protected File responseFile;
+ private JspImpl jspImpl;
- private JspImpl jspImpl;
+ private Map requestAttributes;
- private Map requestAttributes;
+ private Map sessionAttributes;
- private Map sessionAttributes;
+ private MockJspWriter mockJspWriter;
- private MockJspWriter mockJspWriter;
+ protected void setUp() throws Exception {
+ requestAttributes = new HashMap();
+ sessionAttributes = new HashMap();
+ requestAttributes.put("REQATTR", "REQVALUE");
+ sessionAttributes.put("SESATTR", "SESVALUE");
+ jspImpl = new JspImpl(FakeServlet.class) {
+ protected MockJspWriter configureJspFactory(
+ ServletContext httpContext, HttpServletRequest httpRequest,
+ HttpSession httpSession) {
+ mockJspWriter = super.configureJspFactory(httpContext,
+ httpRequest, httpSession);
+ return mockJspWriter;
+ }
+ };
+ }
- protected void setUp() throws Exception {
- requestAttributes = new HashMap();
- sessionAttributes = new HashMap();
- requestAttributes.put("REQATTR", "REQVALUE");
- sessionAttributes.put("SESATTR", "SESVALUE");
- jspImpl = new JspImpl(FakeServlet.class) {
- protected MockJspWriter configureJspFactory(
- ServletContext httpContext,
- HttpServletRequest httpRequest,
- HttpSession httpSession) {
- mockJspWriter = super.configureJspFactory(
- httpContext, httpRequest, httpSession);
- return mockJspWriter;
- }
- };
- }
+ public void testHttpMethodIsPassedToTheServletInstance() throws Exception {
+ simulateRequest("GET");
+ assertOutputContains("httpMethod=GET");
+ simulateRequest("POST");
+ assertOutputContains("httpMethod=POST");
+ }
- public void testHttpMethodIsPassedToTheServletInstance()
- throws Exception {
- simulateRequest("GET");
- assertOutputContains("httpMethod=GET");
- simulateRequest("POST");
- assertOutputContains("httpMethod=POST");
- }
+ public void testRequestAttributesArePassedToTheServletInstance()
+ throws Exception {
+ simulateRequest();
+ assertOutputContains("REQATTR=REQVALUE");
+ }
- public void testRequestAttributesArePassedToTheServletInstance()
- throws Exception {
- simulateRequest();
- assertOutputContains("REQATTR=REQVALUE");
- }
+ public void testSessionAttributesArePassedToTheServletInstance()
+ throws Exception {
+ simulateRequest();
+ assertOutputContains("SESATTR=SESVALUE");
+ }
- public void testSessionAttributesArePassedToTheServletInstance()
- throws Exception {
- simulateRequest();
- assertOutputContains("SESATTR=SESVALUE");
- }
+ private void simulateRequest() {
+ simulateRequest("GET");
+ }
- private void simulateRequest() {
- simulateRequest("GET");
- }
+ private void simulateRequest(String method) {
+ JspExecution execution = jspImpl.request(method, requestAttributes,
+ sessionAttributes);
+ responseFile = execution.getRenderedResponse();
+ }
- private void simulateRequest(String method) {
- JspExecution execution = jspImpl.request(method,
- requestAttributes, sessionAttributes);
- responseFile = execution.getRenderedResponse();
- }
-
- private void assertOutputContains(String string)
- throws IOException {
- String output = mockJspWriter.getContents();
- assertTrue("Output did not contain '" + string + "':\n["
- + output + "]", output.indexOf(string) != -1);
- }
+ private void assertOutputContains(String string) throws IOException {
+ String output = mockJspWriter.getContents();
+ assertTrue(
+ "Output did not contain '" + string + "':\n[" + output + "]",
+ output.indexOf(string) != -1);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|