Skip to content

Commit

Permalink
Fixed use of deprecated Play.current in specs.
Browse files Browse the repository at this point in the history
Fixes #40.
  • Loading branch information
manuelkiessling committed Mar 14, 2016
1 parent 6c2b70a commit 2bcfebf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion api/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ libraryDependencies ++= Seq(
ws,
"org.scalatestplus" %% "play" % "1.4.0-M4" % "test",
"com.datastax.cassandra" % "cassandra-driver-core" % "2.1.8",
"org.scassandra" % "java-client" % "0.11.0" // depending on this globally in /build.sbt results in "Akka JAR version [2.3.13] does not match the provided config version [2.3.9]"
"org.scassandra" % "java-client" % "0.11.0", // depending on this globally in /build.sbt results in "Akka JAR version [2.3.13] does not match the provided config version [2.3.9]"
"com.typesafe.akka" %% "akka-testkit" % "2.4.2"
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
Expand Down
29 changes: 18 additions & 11 deletions api/test/StatisticsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package com.journeymonitor.analyze.api.test
import java.io.File
import java.util.Date

import akka.stream.ActorMaterializer
import com.journeymonitor.analyze.api.AppComponents
import com.journeymonitor.analyze.common.models.StatisticsModel
import com.journeymonitor.analyze.common.repositories.{Repository, StatisticsRepository}
import org.scalatestplus.play._
import play.api
import play.api.Play
import play.api.ApplicationLoader.Context
import play.api.test.Helpers._
import play.api.test._
import play.api.{ApplicationLoader, Environment, Mode}
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}

import scala.util.Try

abstract class AkkaTestkitSupport extends TestKit(ActorSystem()) with ImplicitSender {
implicit val materializer = ActorMaterializer()
def terminateActorSystem() = system.terminate()
}

class MockStatisticsRepository extends Repository[StatisticsModel, String] with StatisticsRepository {

class MockEmptyModelIterator extends Iterator[StatisticsModel] {
Expand Down Expand Up @@ -87,8 +94,7 @@ class StatisticsSpec extends PlaySpec with OneAppPerSuite {

"Non-integrated statistics controller" should {

"return a JSON array with the latest statistics entry for a given testcase id" in {
implicit val materializer = Play.current.materializer
"return a JSON array with the latest statistics entry for a given testcase id" in new AkkaTestkitSupport {
val Some(response) = route(app, FakeRequest(GET, "/testcases/testcase1/statistics/latest/"))

status(response) mustBe OK
Expand All @@ -112,46 +118,47 @@ class StatisticsSpec extends PlaySpec with OneAppPerSuite {
|"numberOf500":789}
|]
|""".stripMargin.replace("\n", "")
terminateActorSystem()
}

"return a JSON object with an error message if there is a problem with the repository" in {
implicit val materializer = Play.current.materializer
"return a JSON object with an error message if there is a problem with the repository" in new AkkaTestkitSupport {
val Some(response) = route(app, FakeRequest(GET, "/testcases/testcaseWithFailure/statistics/latest/"))

status(response) mustBe INTERNAL_SERVER_ERROR
contentType(response) mustBe Some("application/json")
charset(response) mustBe Some("utf-8")
contentAsString(response) mustBe """{"message":"An error occured: Error in mock"}"""
terminateActorSystem()
}

"return an empty JSON array if no statistics for a given testcase id exist" in {
implicit val materializer = Play.current.materializer
"return an empty JSON array if no statistics for a given testcase id exist" in new AkkaTestkitSupport {
val Some(response) = route(app, FakeRequest(GET, "/testcases/testcaseWithoutStatistics/statistics/latest/"))

status(response) mustBe OK
contentType(response) mustBe Some("application/json")
charset(response) mustBe Some("utf-8")
contentAsString(response) mustBe "[]"
terminateActorSystem()
}

"return a JSON object with an error message if the minTestresultDatetimeRun string is incorrectly formatted" in {
implicit val materializer = Play.current.materializer
"return a JSON object with an error message if the minTestresultDatetimeRun string is incorrectly formatted" in new AkkaTestkitSupport {
val Some(response) = route(app, FakeRequest(GET, "/testcases/testcaseWithFailure/statistics/latest/?minTestresultDatetimeRun=foo"))

status(response) mustBe BAD_REQUEST
contentType(response) mustBe Some("application/json")
charset(response) mustBe Some("utf-8")
contentAsString(response) mustBe """{"message":"Invalid minTestresultDatetimeRun format. You provided 'foo', use yyyy-MM-dd HH:mm:ssZ (e.g. 2016-01-02 03:04:05+0600)"}"""
terminateActorSystem()
}

"return a JSON object with an error message if the minTestresultDatetimeRun string is empty" in {
implicit val materializer = Play.current.materializer
"return a JSON object with an error message if the minTestresultDatetimeRun string is empty" in new AkkaTestkitSupport {
val Some(response) = route(app, FakeRequest(GET, "/testcases/testcaseWithFailure/statistics/latest/?minTestresultDatetimeRun="))

status(response) mustBe BAD_REQUEST
contentType(response) mustBe Some("application/json")
charset(response) mustBe Some("utf-8")
contentAsString(response) mustBe """{"message":"Invalid minTestresultDatetimeRun format. You provided '', use yyyy-MM-dd HH:mm:ssZ (e.g. 2016-01-02 03:04:05+0600)"}"""
terminateActorSystem()
}
}

Expand Down

0 comments on commit 2bcfebf

Please sign in to comment.