0

Could someone please help. I have Play2 project in which I need to test some DAO code. I used documentaion from http://www.playframework.org/documentation/2.0.2/ScalaTest. The test is very simple:

import models.Calendar
import org.specs2.mutable._

import play.api.test._
import play.api.test.Helpers._

class CalendarSpec extends Specification {
"Calendar model" should {

  "be retrieved by id" in {

    val fakeApp = FakeApplication()
    running(fakeApp) {

      lazy val calendarId= Calendar.addCalendar(
        Calendar(subject="test",
          upAccount = "mytest",
          masterId = 1,
          calendarType = 1,
          isAllDayEvent = false,
          hasAttachment = false,
          category = "test",
          instanceType = 1,
        upName = "test" ))
      lazy val Some(calendar) = Calendar.getCalendar(calendarId.get)

      calendar.upAccount must equalTo("mytest")
    }
  }
}
}

And when I run 'sbt test' I get strange error:

[info] Calendar model should
[error] ! Fragment evaluation error
[error]     ThrowableException: play.api.test.Helpers$.play$api$http$HeaderNames$_setter_$ACCESS_CONTROL_ALLOW_ORIGIN_$eq(Ljava/lang/String;)V (TraversableLike.scala:194)
[error] play.api.http.HeaderNames$class.$init$(StandardValues.scala:195)
[error] play.api.test.Helpers$.<init>(Helpers.scala:16)
[error] play.api.test.Helpers$.<clinit>(Helpers.scala:111)
[error] CalendarSpec$$anonfun$1$$anonfun$apply$1.apply(CalendarSpec.scala:13)
[error] CalendarSpec$$anonfun$1$$anonfun$apply$1.apply(CalendarSpec.scala:10)
[error] play.api.test.Helpers$.play$api$http$HeaderNames$_setter_$ACCESS_CONTROL_ALLOW_ORIGIN_$eq(Ljava/lang/String;)V
[error] play.api.http.HeaderNames$class.$init$(StandardValues.scala:195)
[error] play.api.test.Helpers$.<init>(Helpers.scala:16)
[error] play.api.test.Helpers$.<clinit>(Helpers.scala:111)
[error] CalendarSpec$$anonfun$1$$anonfun$apply$1.apply(CalendarSpec.scala:13)
[error] CalendarSpec$$anonfun$1$$anonfun$apply$1.apply(CalendarSpec.scala:10)

StackOverflow/Google knows nothing about this exception. Thanks in advance.

Siton
  • 1

2 Answers2

0

The stacktrace makes me think that a library is incorrect or missing in your classpath. This is why you are seeing "Helpers$." traces where the class constructor seems to be failing.

You can validate this by writing a small app in your test directory, without specs2 but using Play2's helper classes and see what happens.

Eric
  • 15,494
  • 38
  • 61
0

I found solution - https://groups.google.com/forum/#!msg/play-framework/NSN9xfktUks/EwiG1Cc0C9oJ:
new play.core.StaticApplication(new java.io.File(".")) should be added to actualy start Play app so DAO calls can work in test.

Siton
  • 1