Skip to content

Commit

Permalink
Add a test for servletSpec := "3.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
earldouglas committed Nov 2, 2024
1 parent 42f98c2 commit 748ea9d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/sbt-test/plugins/webapp-components/servlet-3.0/servlet.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package runners

import com.typesafe.scalalogging.LazyLogging
import javax.servlet.annotation.WebServlet
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class CountServlet extends HttpServlet with Main:

import java.sql.Connection
import java.sql.DriverManager

override lazy val c: Connection =
Class.forName("org.h2.Driver")
val connection: Connection =
DriverManager.getConnection("jdbc:h2:mem:", "sa", "")
connection.setAutoCommit(false)
connection

override def init(): Unit =
super.init()

override def destroy(): Unit =
super.destroy()

override def doGet(
req: HttpServletRequest,
res: HttpServletResponse
): Unit =
res.addHeader("Content-Type", "application/json")
res.getWriter().write(unsafeIncrementAndGetAsJson())

@WebServlet(urlPatterns = Array("/hello"))
class HelloServlet extends HttpServlet with LazyLogging:

override def doGet(
request: HttpServletRequest,
response: HttpServletResponse
): Unit =
logger.info("doGet")
response.setCharacterEncoding("UTF-8")
response.setContentType("text/html")
response.getWriter.write("""<h1>Hello, world!</h1>""")
9 changes: 9 additions & 0 deletions src/sbt-test/plugins/webapp-components/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
> reload

> check

$ copy-file servlet-3.0/servlet.scala src/main/scala/04-runners/servlet.scala

# fail to compile with an incompatible Servlet spec
-> check

# use the correct Servlet spec
> set servletSpec := "3.0"
> check

0 comments on commit 748ea9d

Please sign in to comment.