mirror of https://github.com/sbt/sbt.git
test case for running webapps directly out of src/main/webapp
This commit is contained in:
parent
ad40d7f34f
commit
e110d4028b
|
|
@ -0,0 +1,20 @@
|
|||
package test
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
class MyServlet extends HttpServlet {
|
||||
|
||||
val html = <HTML>
|
||||
<HEAD><TITLE>Hello, Scala 2!</TITLE></HEAD>
|
||||
<BODY>Hello, Scala 2! This is a servlet.</BODY>
|
||||
</HTML>
|
||||
|
||||
override def doGet(req:HttpServletRequest, resp:HttpServletResponse) {
|
||||
resp.setContentType("text/html")
|
||||
resp.getWriter().print(html.toString)
|
||||
}
|
||||
def check28(f: Int = 3) = f
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
project.organization=tester
|
||||
project.name=sbtweb
|
||||
project.version=1.0
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import sbt._
|
||||
|
||||
class WebappBuild(info: ProjectInfo) extends DefaultWebProject(info) {
|
||||
|
||||
val servlet_api = "org.mortbay.jetty" % "servlet-api-2.5" % "6.1.14" % "provided->default"
|
||||
val jetty_servlet = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test->default"
|
||||
|
||||
def indexURL = new java.net.URL("http://localhost:8080")
|
||||
def indexFile = new java.io.File("index.html")
|
||||
import Process._
|
||||
lazy val getPage = execTask { indexURL #> indexFile }
|
||||
lazy val checkPage = task { args => task { checkHelloWorld(args.mkString(" ")) } dependsOn getPage }
|
||||
|
||||
override def jettyWebappPath = webappPath
|
||||
|
||||
private def checkHelloWorld(checkString: String) =
|
||||
{
|
||||
val value = xsbt.FileUtilities.read(indexFile)
|
||||
if(value.contains(checkString)) None else Some("index.html did not contain '" + checkString + "' :\n" +value)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package test
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
class MyServlet extends HttpServlet {
|
||||
|
||||
val html = <HTML>
|
||||
<HEAD><TITLE>Hello, Scala!</TITLE></HEAD>
|
||||
<BODY>Hello, Scala! This is a servlet.</BODY>
|
||||
</HTML>
|
||||
|
||||
override def doGet(req:HttpServletRequest, resp:HttpServletResponse) {
|
||||
resp.setContentType("text/html")
|
||||
resp.getWriter().print(html.toString)
|
||||
}
|
||||
def check28(f: Int = 3) = f
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE web-app PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd" >
|
||||
|
||||
<web-app>
|
||||
<display-name>Archetype Created Web Application</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Home</servlet-name>
|
||||
<servlet-class>test.MyServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Home</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
> ++2.8.0.Beta1-RC6
|
||||
> update
|
||||
> jetty-run
|
||||
$ pause
|
||||
> check-page "Hello, Scala!"
|
||||
|
||||
$ copy-file changes/MyServlet.scala src/main/scala/test/MyServlet.scala
|
||||
|
||||
> prepare-webapp
|
||||
> jetty-reload
|
||||
> check-page "Hello, Scala 2!"
|
||||
|
||||
> jetty-stop
|
||||
-> check-page "Hello World 2!"
|
||||
Loading…
Reference in New Issue