unit test uses fake JSP
This commit is contained in:
parent
98146f2ca2
commit
c4e77feefa
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.jsp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class FakeJspServlet extends HttpServlet
|
||||
{
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
String path = req.getServletPath();
|
||||
URL url =getServletContext().getResource(path);
|
||||
if (url==null)
|
||||
{
|
||||
response.sendError(404);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File file=new File(url.toURI());
|
||||
if (file.exists())
|
||||
{
|
||||
response.sendError(200,"fake JSP response");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
response.sendError(404);
|
||||
}
|
||||
|
||||
}
|
|
@ -34,6 +34,7 @@ import org.eclipse.jetty.security.HashLoginService;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.NoJspServlet;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
|
@ -106,7 +107,8 @@ public class JspAndDefaultWithAliasesTest
|
|||
defaultServHolder.setInitParameter("aliases","true"); // important! must be TRUE
|
||||
|
||||
// add jsp
|
||||
ServletHolder jsp = context.addServlet(JspServlet.class,"*.jsp");
|
||||
ServletHolder jsp = new ServletHolder(new FakeJspServlet());
|
||||
context.addServlet(jsp,"*.jsp");
|
||||
jsp.setInitParameter("classpath",context.getClassPath());
|
||||
|
||||
// add context
|
||||
|
@ -157,6 +159,9 @@ public class JspAndDefaultWithAliasesTest
|
|||
return;
|
||||
}
|
||||
|
||||
if (conn.getResponseCode()!=404)
|
||||
System.err.println(conn.getResponseMessage());
|
||||
|
||||
// Of other possible paths, only 404 Not Found is expected
|
||||
Assert.assertThat("Response Code",conn.getResponseCode(),is(404));
|
||||
}
|
||||
|
|
|
@ -106,7 +106,8 @@ public class JspAndDefaultWithoutAliasesTest
|
|||
defaultServHolder.setInitParameter("aliases","false"); // important! must be FALSE
|
||||
|
||||
// add jsp
|
||||
ServletHolder jsp = context.addServlet(JspServlet.class,"*.jsp");
|
||||
ServletHolder jsp = new ServletHolder(new FakeJspServlet());
|
||||
context.addServlet(jsp,"*.jsp");
|
||||
jsp.setInitParameter("classpath",context.getClassPath());
|
||||
|
||||
// add context
|
||||
|
|
Loading…
Reference in New Issue