Created
August 13, 2010 18:50
-
-
Save dchenbecker/523347 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object JPASpec extends Specification { | |
object EM extends LocalEMF("jpaSample") with ThreadLocalEM | |
"EntityManager" should { | |
setSequential() // Make sure that the following specs execute in order | |
"Add users" in { | |
println("running add users") | |
val user1 = new User("Ted") | |
val user2 = new User("Fred") | |
EM.persist(user1) | |
EM.persist(user2) | |
EM.flush | |
val users = EM.createQuery[User]("from User").findAll | |
println(users.size) | |
users.size must_== 2 | |
} | |
"Retrieve users" in { | |
println("running retrieve users") | |
val users = EM.createQuery[User]("from User").findAll | |
println(users.size) | |
users.size must_== 2 | |
} | |
"Delete users" in { | |
println("running delete users") | |
val users = EM.createQuery[User]("from User").findAll | |
println(users.size) | |
users.foreach { | |
user ⇒ EM.remove(user) | |
} | |
EM.flush | |
val empty = EM.createQuery[User]("from User").findAll | |
println(empty.size) | |
empty.size must_== 0 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment