playframework / play-scala-isolated-slick-example

Example Play Slick Project
https://developer.lightbend.com/start/?group=play
Creative Commons Zero v1.0 Universal
154 stars 34 forks source link

Error when executing "sbt test" #57

Closed felipegutierrez closed 6 years ago

felipegutierrez commented 6 years ago

Hi, I was looking at the internet for some example with Slick + Play + Scala to use test unit. It is very hard to find and it is a pit that this one is not working yet. If you have some time to fix it, this will help me a lot to learn how to configure my play web app to execute unit test with slick also.

Thanks. Here are the errors when I execute sbt test

[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:30: not found: value Users
[error]     (id: Rep[String]) => Users.filter(_.id === id))
[error]                          ^
[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:33: not found: type UsersRow
[error]     val f: Future[Option[UsersRow]] = db.run(queryById(id).result.headOption)
[error]                          ^
[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:64: not found: type UsersRow
[error]   private def usersRowToUser(usersRow: UsersRow): User = {
[error]                                        ^
[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:38: not found: value Users
[error]     val f = db.run(Users.result)
[error]                    ^
[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:52: not found: value Users
[error]       Users += userToUsersRow(user.copy(createdAt = DateTime.now()))
[error]       ^
[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:60: not found: type UsersRow
[error]   private def userToUsersRow(user: User): UsersRow = {
[error]                                           ^
[error] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:61: not found: value UsersRow
[error]     UsersRow(user.id, user.email, user.createdAt, user.updatedAt)
[error]     ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:11: Unused import
[warn] import scala.language.implicitConversions
[warn]                       ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:29: private val queryById in class SlickUserDAO is never used
[warn]   private val queryById = Compiled(
[warn]               ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/src/main/scala/com/example/user/slick/SlickUserDAO.scala:60: private method userToUsersRow in class SlickUserDAO is never used
[warn]   private def userToUsersRow(user: User): UsersRow = {
[warn]               ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/target/scala-2.12/src_managed/main/com/example/user/slick/Tables.scala:11: Unused import
[warn]   import profile.api._
[warn]                      ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/target/scala-2.12/src_managed/main/com/example/user/slick/Tables.scala:12: Unused import
[warn]   import com.github.tototoshi.slick.H2JodaSupport._
[warn]                                                   ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/target/scala-2.12/src_managed/main/com/example/user/slick/Tables.scala:13: Unused import
[warn]   import org.joda.time.DateTime
[warn]                        ^
[warn] /home/felipe/Downloads/play-scala-isolated-slick-example/modules/slick/target/scala-2.12/src_managed/main/com/example/user/slick/Tables.scala:14: Unused import
[warn]   import slick.model.ForeignKeyAction
[warn]                      ^
[warn] 7 warnings found
[error] 7 errors found
[error] (slick/compile:compileIncremental) Compilation failed
[error] Total time: 28 s, completed Feb 2, 2018 10:50:15 AM
marcospereira commented 6 years ago

Hi @felipegutierrez,

This project uses slick code generation to create the mapping. So you first need to run sbt flyway/flywayMigrate, then sbt slickCodegen and only after that sbt test. See our README for more details.