Following scalatra-slick tutorial causes unit test error

27 views
Skip to first unread message

Jordan Bethea

unread,
Jul 25, 2020, 11:12:44 PM7/25/20
to scalatra-user
Hi, I'm just learning scalatra, and am going through some of the tutorials on the website, and I've been following the one about slick:

But, it seems like following this breaks the auto generated servlet unit test:

class MyScalatraServletTests extends ScalatraFunSuite {
 
 addServlet
(classOf[MyScalatraServlet], "/*")

 test
("GET / on MyScalatraServlet should return status 200") {
 
get("/") {
 status should equal
(200)
 
}
 
}

}

I get the following error in the console:
Caused by: java.lang.NoSuchMethodException: com.github.jordanbethea.app.MyScalatraServlet.<init>()
        at java
.lang.Class.getConstructor0(Class.java:3082)
        at java
.lang.Class.getDeclaredConstructor(Class.java:2178)
        at org
.eclipse.jetty.server.handler.ContextHandler$StaticContext.createInstance(ContextHandler.java:2787)
        at org
.eclipse.jetty.servlet.ServletContextHandler$Context.createInstance(ServletContextHandler.java:1280)
        at org
.eclipse.jetty.server.handler.ContextHandler$StaticContext.createServlet(ContextHandler.java:2804)
        at org
.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:1159)
        at org
.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:570)
       
... 25 common frames omitted
22:58:14.246 [pool-12-thread-1] INFO  o.e.jetty.server.AbstractConnector - Stopped ServerConnector@4c4558e1{HTTP/1.1, (http/1.1)}{0.0.0.0:0}
22:58:14.246 [pool-12-thread-1] INFO  org.eclipse.jetty.server.session - node0 Stopped scavenging
22:58:14.250 [pool-12-thread-1] INFO  o.e.j.server.handler.ContextHandler - Stopped o.e.j.s.ServletContextHandler@2da8c2e1{/,file:///Users/jordanbethea/Development/vote-science/src/main/webapp/,UNAVAILABLE}
[info] MyScalatraServletTests:
[info] - GET / on MyScalatraServlet should return status 200 *** FAILED ***
[info]   500 did not equal 200 (MyScalatraServletTests.scala:14)
[info] Run completed in 1 second, 755 milliseconds.


I'm not sure why it's looking for an init function in the servlet, as the example code puts the init and destroy functions in the bootstrap class.

I still get this error even if I don't do anything with the db parameter, just as long as I actually pass the parameter into the servlet, this error appears. I've gone through the code a couple times and it looks like it follows the pattern from the example, though I've simplified it down to try to find the error. Can someone explain what this error might mean?

If someone wants the full stack trace or to see my other classes, let me know.
Reply all
Reply to author
Forward
0 new messages