Running functional routing tests for play-mini yields "Cannot init the Global object [null]"

250 views
Skip to first unread message

SP

unread,
Feb 28, 2012, 2:42:14 AM2/28/12
to Akka User List
Hi,

I am attempting to write functional tests to validate the routes of an
play-mini(ied) application. It looks like the following:

package my.awesome.package
import com.typesafe.play.mini.{POST, GET, DELETE, Path,
Application => PlayApplication}
//.... whole lot of other play.api imports ...

object BlaServiceApi extends PlayApplication {
def route = {
case POST(Path("/bla")) => Action { .... }
case GET(Path("/bla")) => Action { .... }
}
}

in my default package scope Global.scala I have:

import com.typesafe.play.mini.Setup
object Global extends Setup(my.awesome.package.BlaServiceApi)


So far so good. I can run this great (after I fixed my version
dependencies last week). Awesome.

Now the router functional tests I am writing look like this:

package my.awesome.package
import org.specs2.mutable._
import play.api.test.{Helpers => PlayHelpers, _}
import play.api.test.Helpers.{GET, POST, PUT, DELETE}

class BlaServiceApi extends SpecificationWithJUnit {
"GET /bla" should {
"respond with a success (OK)" in {
PlayHelpers.running(FakeApplication()) {
val result = PlayHelpers.routeAndCall(FakeRequest(GET, "/
bla")).get
PlayHelpers.status(result) must equalTo(PlayHelpers.OK)
}
}
}
}

Now the test compiles, but when running the test it yells at me with
this lovely stack trace (oh, how I forgot your lovely stack traces
Java/JVM):

java.lang.Exception: Cannot init the Global object
[null]
at play.api.PlayException$.apply(Exceptions.scala:
122)
at play.api.Application$$anonfun$3.apply(Application.scala:
71)
at play.api.Application$$anonfun$3.apply(Application.scala:
67)
at play.utils.Threads$.withContextClassLoader(Threads.scala:
17)
at play.api.Application.<init>(Application.scala:
66)
at play.api.test.FakeApplication.<init>(Fakes.scala:
93)
at my.awesome.package.BlaServiceApiSpec$$anonfun$1$$anonfun
$apply$3.apply(BlaServiceApiSpec.scala:
18)
at my.awesome.package.BlaServiceApiSpec$$anonfun$1$$anonfun
$apply$3.apply(BlaServiceApiSpec.scala:
18)
at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:
35)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:
115)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:
97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at org.apache.maven.surefire.booter.ProviderFactory
$ClassLoaderProxy.invoke(ProviderFactory.java:
103)
at $Proxy0.invoke(Unknown
Source)
at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:
150)
at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:
91)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:
69)
at Global$.<init>(Global.scala:
3)
at Global
$.<clinit>(Global.scala)
at sun.misc.Unsafe.ensureClassInitialized(Native
Method)
at
sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:
25)
at play.api.Application.liftedTree2$1(Application.scala:
52)
at play.api.Application.play$api$Application$
$scalaGlobal(Application.scala:51)
at play.api.Application$$anonfun$3$$anonfun$apply
$2.apply(Application.scala:68)
at play.api.Application$$anonfun$3$$anonfun$apply
$2.apply(Application.scala:68)
at play.api.Application$$anonfun$3.apply(Application.scala:
68)
at play.api.Application$$anonfun$3.apply(Application.scala:
67)
at play.utils.Threads$.withContextClassLoader(Threads.scala:
17)
at play.api.Application.<init>(Application.scala:
66)
at play.api.test.FakeApplication.<init>(Fakes.scala:
93)
at my.awesome.package.BlaServiceApiSpec$$anonfun$1$$anonfun
$apply$3.apply(BlaServiceApiSpec.scala:
18)
at my.awesome.package.BlaServiceApiSpec$$anonfun$1$$anonfun
$apply$3.apply(BlaServiceApiSpec.scala:
18)

Should I be setting things up with something other than an instance of
play.api.test.FakeApplication as argument to the running Play test
helper method that is special to play-mini wrapper code?

Is there any documentation on this so far? I have been using the Akka
HTTP module documentation section of the PDF for reference (v2.0-RC2)
on the main code and the Play 2.0 GitHub wiki page for the functional
test code:
https://github.com/playframework/Play20/wiki/JavaFunctionalTest

Any pointers to play-mini functional test examples would be fantastic.

Thanks,
SP

Henrik Engström

unread,
Feb 28, 2012, 6:29:52 AM2/28/12
to akka...@googlegroups.com
Hi,
There's no documentation on this topic so far.
I have not tested it, but will try it out and we will get back to you asap.
Cheers
//Henrik

> --
> You received this message because you are subscribed to the Google Groups "Akka User List" group.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
>

Reply all
Reply to author
Forward
0 new messages