playframework - Play scala integration spec - Injecting dependencies through Guice -
i use scala, play 2.4, , slick 3 in project. have following dao code , works fine end end.
@singleton() class companiesdao @inject() (protected val dbconfigprovider: databaseconfigprovider) extends companiescomponent hasdatabaseconfigprovider[jdbcprofile] { import driver.api._ }
however, can't working expected in integration test because of dbconfig stuff. integration test below:
class companiesdaointegrationspec extends funspec oneserverpersuite { def companiesdao(implicit app: application) = { val app2companiesdao = application.instancecache[companiesdao] app2companiesdao(app) } describe("create") { it("should create ") { companiesdao.create... } } }
if don't put db properties in application.conf got following error:
[info] java.lang.runtimeexception: com.google.inject.provisionexception: unable provision, see following errors: [info] [info] 1) no implementation play.api.db.slick.databaseconfigprovider bound. [info] while locating play.api.db.slick.databaseconfigprovider [info] parameter 0 @
it seems given above code, play application reads db properties configuration file located @ /conf/application.conf
.
my project setup bit different this, have multiple environments have file structuers like:
/conf/local/application.conf /conf/testing/application.conf /conf/staging/application.conf /conf/production/application.conf
when run play application using command like: activator run -dconfig.resource=/conf/local/application.conf
, work fine. want same integration spec like: activator test -dconfig.resource=/conf/local/application.conf
. play read specified config run integration tests.
what's best way achieve that?
you have make trait , mix in test, , work.
trait withdatabaseconfig { lazy val (driver, db) = { val dbconfig = databaseconfigprovider.get[jdbcprofile](play.current) (dbconfig.driver, dbconfig.db) } }
i have no idea why, i'm scala beginner. has not/running app or guice. found in samples folder @ https://github.com/playframework/play-slick/blob/1.1.x/samples/json/test/dbspec.scala
Comments
Post a Comment