alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (BoneCPPluginSpec.scala)

This example Play Framework source code file (BoneCPPluginSpec.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

acolyte, api, bonecpplugin, db, ensure, fake, fakeapplication, h2, jdbc, map, no, play, play framework, specification, test, utilities

The BoneCPPluginSpec.scala Play Framework example source code

package play.api.db

import scala.util.Try
import java.sql.{ DriverManager, SQLException }
import play.api.test.FakeApplication
import org.specs2.mutable.Specification

object BoneCPPluginSpec extends Specification {
  "BoneCP DB plugin" title

  "JDBC driver" should {
    sequential 

    "be registered for H2 before plugin starts" in {
      DriverManager.getDriver("jdbc:h2:mem:") aka "H2 driver" must not(beNull)
    }

    "not be registered for Acolyte until plugin is started" in {
      Try { // Ensure driver is not registered
        DriverManager.deregisterDriver(DriverManager.getDriver(jdbcUrl))
      }

      DriverManager.getDriver(jdbcUrl) aka "Acolyte driver" must(
        throwA[SQLException](message = "No suitable driver"))
    }

    "be registered for both Acolyte & H2 when plugin is started" in {
      plugin.onStart()

      (DriverManager.getDriver(jdbcUrl) aka "Acolyte driver" must not(beNull)).
        and(DriverManager.getDriver("jdbc:h2:mem:").
          aka("H2 driver") must not(beNull))
    }

    "be deregistered for Acolyte but still there for H2 after plugin stops" in {
      plugin.onStop()

      (DriverManager.getDriver("jdbc:h2:mem:") aka "H2 driver" must not(beNull))
      .and(DriverManager.getDriver(jdbcUrl) aka "Acolyte driver" must {
        throwA[SQLException](message = "No suitable driver")
      })
    }
  }

  val jdbcUrl = "jdbc:acolyte:test?handler=boneCPPluginSpec"
  lazy val plugin = {
    acolyte.jdbc.Driver.register("boneCPPluginSpec", 
      acolyte.jdbc.CompositeHandler.empty()) // Fake driver

    new BoneCPPlugin(
      FakeApplication(additionalConfiguration = Map(
        "db.default.driver" -> "acolyte.jdbc.Driver",
        "db.default.url" -> jdbcUrl)))
  }
}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework BoneCPPluginSpec.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.