Fix compilation error service test case

This commit is contained in:
Tomofumi Tanaka
2014-07-09 00:25:40 +09:00
parent c182cde14b
commit a2a2e22485
2 changed files with 10 additions and 10 deletions

View File

@@ -9,13 +9,13 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
"AccountService" should { "AccountService" should {
val RootMailAddress = "root@localhost" val RootMailAddress = "root@localhost"
"getAllUsers" in { withTestDB{ "getAllUsers" in { withTestDB { implicit session =>
AccountService.getAllUsers() must be like{ AccountService.getAllUsers() must be like{
case List(model.Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false, false)) => ok case List(model.Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false, false)) => ok
} }
}} }}
"getAccountByUserName" in { withTestDB{ "getAccountByUserName" in { withTestDB { implicit session =>
AccountService.getAccountByUserName("root") must beSome.like{ AccountService.getAccountByUserName("root") must beSome.like{
case user => user.userName must_== "root" case user => user.userName must_== "root"
} }
@@ -23,11 +23,11 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
AccountService.getAccountByUserName("invalid user name") must beNone AccountService.getAccountByUserName("invalid user name") must beNone
}} }}
"getAccountByMailAddress" in { withTestDB{ "getAccountByMailAddress" in { withTestDB { implicit session =>
AccountService.getAccountByMailAddress(RootMailAddress) must beSome AccountService.getAccountByMailAddress(RootMailAddress) must beSome
}} }}
"updateLastLoginDate" in { withTestDB{ "updateLastLoginDate" in { withTestDB { implicit session =>
val root = "root" val root = "root"
def user() = def user() =
AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists")) AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists"))
@@ -46,7 +46,7 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
} }
}} }}
"updateAccount" in { withTestDB{ "updateAccount" in { withTestDB { implicit session =>
val root = "root" val root = "root"
def user() = def user() =
AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists")) AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists"))
@@ -56,7 +56,7 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
user().mailAddress must_== newAddress user().mailAddress must_== newAddress
}} }}
"group" in { withTestDB { "group" in { withTestDB { implicit session =>
val group1 = "group1" val group1 = "group1"
val user1 = "root" val user1 = "root"
AccountService.createGroup(group1, None) AccountService.createGroup(group1, None)

View File

@@ -1,6 +1,6 @@
package service package service
import scala.slick.session.Database import model.simple._
import util.ControlUtil._ import util.ControlUtil._
import java.sql.DriverManager import java.sql.DriverManager
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
@@ -9,15 +9,15 @@ import java.io.File
trait ServiceSpecBase { trait ServiceSpecBase {
def withTestDB[A](action: => A): A = { def withTestDB[A](action: (Session) => A): A = {
util.FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){ dir => util.FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){ dir =>
val (url, user, pass) = (s"jdbc:h2:${dir}", "sa", "sa") val (url, user, pass) = (s"jdbc:h2:${dir}", "sa", "sa")
org.h2.Driver.load() org.h2.Driver.load()
using(DriverManager.getConnection(url, user, pass)){ conn => using(DriverManager.getConnection(url, user, pass)){ conn =>
servlet.AutoUpdate.versions.reverse.foreach(_.update(conn)) servlet.AutoUpdate.versions.reverse.foreach(_.update(conn))
} }
Database.forURL(url, user, pass).withSession { Database.forURL(url, user, pass).withSession { session =>
action action(session)
} }
} }
} }