|
Play Framework/Scala example source code file (DBSpec.scala)
The DBSpec.scala Play Framework example source codepackage play.db; import play.api.test.FakeApplication object DBSpec extends org.specs2.mutable.Specification { "Java DB utility" title "DB" should { "execute block with default connection" in { val id = s"withConnection-${System.identityHashCode(this)}" DB.withConnection(callable(id), fakeApp). aka("connection block result") must_== id } "execute block with connection from specified datasource" in { val id = s"withConnection-${System.identityHashCode(this)}" DB.withConnection("default", callable(id), fakeApp). aka("connection block result") must_== id } "execute block with transaction for default connection" in { val id = s"withConnection-${System.identityHashCode(this)}" DB.withTransaction(callable(id), fakeApp). aka("transaction block result") must_== id } "execute block with transaction from specified datasource" in { val id = s"withConnection-${System.identityHashCode(this)}" DB.withTransaction("default", callable(id), fakeApp). aka("connection block result") must_== id } } // --- def callable(res: String) = new ConnectionCallable[String] { def call(con: java.sql.Connection) = res } lazy val fakeApp = { acolyte.jdbc.Driver.register("test", acolyte.jdbc.CompositeHandler.empty()) FakeApplication(additionalConfiguration = Map( "db.default.driver" -> "acolyte.jdbc.Driver", "db.default.url" -> "jdbc:acolyte:test?handler=test")) } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework DBSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.