|
@ -2,9 +2,13 @@ package controllers.common |
|
|
|
|
|
|
|
|
import com.alexitc.playsonify.test.PlayAPISpec |
|
|
import com.alexitc.playsonify.test.PlayAPISpec |
|
|
import org.slf4j.LoggerFactory |
|
|
import org.slf4j.LoggerFactory |
|
|
|
|
|
import play.api.db.{DBApi, Database, Databases} |
|
|
|
|
|
import play.api.inject.bind |
|
|
|
|
|
import play.api.inject.guice.GuiceApplicationBuilder |
|
|
import play.api.mvc.Result |
|
|
import play.api.mvc.Result |
|
|
import play.api.test.FakeRequest |
|
|
import play.api.test.FakeRequest |
|
|
import play.api.test.Helpers._ |
|
|
import play.api.test.Helpers._ |
|
|
|
|
|
import play.api.{Configuration, Environment, Mode} |
|
|
|
|
|
|
|
|
import scala.concurrent.Future |
|
|
import scala.concurrent.Future |
|
|
|
|
|
|
|
@ -15,4 +19,32 @@ trait MyAPISpec extends PlayAPISpec { |
|
|
override protected def log[T](request: FakeRequest[T], response: Future[Result]): Unit = { |
|
|
override protected def log[T](request: FakeRequest[T], response: Future[Result]): Unit = { |
|
|
logger.info(s"> REQUEST, $request; < RESPONSE, status = ${status(response)}, body = ${contentAsString(response)}") |
|
|
logger.info(s"> REQUEST, $request; < RESPONSE, status = ${status(response)}, body = ${contentAsString(response)}") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* A dummy [[Database]] and [[DBApi]] just to allow a play application |
|
|
|
|
|
* to start without connecting to a real database from application.conf. |
|
|
|
|
|
*/ |
|
|
|
|
|
private val dummyDB = Databases.inMemory() |
|
|
|
|
|
private val dummyDBApi = new DBApi { |
|
|
|
|
|
override def databases(): Seq[Database] = List(dummyDB) |
|
|
|
|
|
override def database(name: String): Database = dummyDB |
|
|
|
|
|
override def shutdown(): Unit = dummyDB.shutdown() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Loads configuration disabling evolutions on default database. |
|
|
|
|
|
* |
|
|
|
|
|
* This allows to not write a custom application.conf for testing |
|
|
|
|
|
* and ensure play evolutions are disabled. |
|
|
|
|
|
*/ |
|
|
|
|
|
private def loadConfigWithoutEvolutions(env: Environment): Configuration = { |
|
|
|
|
|
val map = Map("play.evolutions.db.default.enabled" -> false) |
|
|
|
|
|
|
|
|
|
|
|
Configuration.load(env) ++ Configuration.from(map) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override val guiceApplicationBuilder: GuiceApplicationBuilder = GuiceApplicationBuilder(loadConfiguration = loadConfigWithoutEvolutions) |
|
|
|
|
|
.in(Mode.Test) |
|
|
|
|
|
.overrides(bind[Database].to(dummyDB)) |
|
|
|
|
|
.overrides(bind[DBApi].to(dummyDBApi)) |
|
|
} |
|
|
} |
|
|