Skip to content

Instantly share code, notes, and snippets.

@fwbrasil
Forked from b0c1/CrudTest.scala
Last active December 17, 2015 00:19
Show Gist options
  • Save fwbrasil/5519601 to your computer and use it in GitHub Desktop.
Save fwbrasil/5519601 to your computer and use it in GitHub Desktop.
package hu.finesolution.sepia.test.core.controller
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FunSuite, BeforeAndAfter}
import org.scalatra.test.scalatest.ScalatraSuite
import org.scalatra.ScalatraServlet
import net.fwbrasil.activate.ActivateContext
import net.fwbrasil.activate.storage.relational.PooledJdbcRelationalStorage
import net.fwbrasil.activate.storage.relational.idiom.h2Dialect
object h2Context extends ActivateContext {
val storage = new PooledJdbcRelationalStorage {
val jdbcDriver = "org.h2.Driver"
val user = ""
val password = ""
val url = "jdbc:h2:mem:my_database;DB_CLOSE_DELAY=-1"
val dialect = h2Dialect
}
}
import h2Context._
class Test(var name: String) extends Entity
class TestMigration extends Migration {
def timestamp = 20130523001l
def up = {
table[Test].createTable(
_.column[String]("name")
)
}
}
class ManifestExample[T <: AnyRef](implicit m: Manifest[T]) extends ScalatraServlet {
get("/") {
"hi"
}
}
@RunWith(classOf[JUnitRunner])
class CrudTest extends FunSuite with ScalatraSuite with MockitoSugar with BeforeAndAfter {
transactional{}
addServlet(new ManifestExample[Test](), "/*")
test("Test creat") {
get("/") {
status should equal(200)
body should include("hi")
}
}
before {
transactional {
all[Test].foreach(_.delete)
}
}
}
package hu.finesolution.sepia.test.core.controller
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FunSuite, BeforeAndAfter}
import org.scalatra.test.scalatest.ScalatraSuite
import org.scalatra.ScalatraServlet
import net.fwbrasil.activate.ActivateContext
import net.fwbrasil.activate.storage.relational.PooledJdbcRelationalStorage
import net.fwbrasil.activate.storage.relational.idiom.h2Dialect
object h2Context extends ActivateContext {
val storage = new PooledJdbcRelationalStorage {
val jdbcDriver = "org.h2.Driver"
val user = ""
val password = ""
val url = "jdbc:h2:mem:my_database;DB_CLOSE_DELAY=-1"
val dialect = h2Dialect
}
}
import h2Context._
class Test(var name: String) extends Entity
class TestMigration extends Migration {
def timestamp = 20130523001l
def up = {
table[Test].createTable(
_.column[String]("name")
)
}
}
class ManifestExample[T <: AnyRef](implicit m: Manifest[T]) extends ScalatraServlet {
get("/") {
"hi"
}
}
@RunWith(classOf[JUnitRunner])
class CrudTest extends FunSuite with ScalatraSuite with MockitoSugar with BeforeAndAfter {
test("Test creat") {
get("/") {
status should equal(200)
body should include("hi")
}
}
before {
transactional {
all[Test].foreach(_.delete)
}
addServlet(new ManifestExample[Test](), "/*")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment