Hi,
I'm rather new to the play framework, and currently trying to prepare and test a model. I'm wondering how to populate a database and retrieve the values put into it for e.g. testing find methods. Here's what I'm doing at the moment:
I extended withApplication to prepare data setup:
class WithDBApplication(app: Application) extends WithApplication {
override def around[T: AsResult](t: => T): Result = super.around {
setupData()
t
}
def setupData() = {
val items = Generator.generateTestItems()
}
}
The generateTestItems basically creates items, persists them in the DB and returns a list of the generated items to test e.g. look-ups.
In my test case, I'm trying to do the following:
class ItemServiceTest extends Specification {
"ItemService.findById" should {
"find existing id" in new WithDBApplication(app) {
val testItem = ???
ItemService.findById(testItem.id) must beSome[Item].which {
item => item == testItem
}
}
}
}
For the testItem, I want to access one of the items the DB has been populated with. How can I access these items? Or am I doing something completely wrong in this setup?
I'm running play framework 2.3.
Thanks for any help,
Stefan