如何直接测试MyManserService的方法以获取Play Framework的securesocial插件

时间:2013-07-29 14:33:09

标签: scala playframework specs2 securesocial

我想知道如何直接测试我实现的UserServiceMyUserService)方法。我导入了MyUserService,但它似乎没有认出来。

错误是:

not found: value MyUserService

感谢您提供任何帮助。这是我的find方法的测试用例。

这是我的测试案例......

"retrieve a user by UserId" in new WithApplication  {

  val user : Option[User]  = MyUserService.find(UserId("johnnyboy", "userpass"))

  val getUser = user.get

  getUser.uid must equalTo(Some(1))
  getUser.id.id must equalTo ("johnnyboy")
  getUser.id.providerId must equalTo("userpass")
  getUser.userType must equalTo(Some("admin"))
  getUser.firstName must equalTo("John")
  getUser.lastName must equalTo("Smith")
  getUser.fullName must equalTo("John Smith)
  getUser.email must equalTo(Some("johnsmith@gmail.com"))
  getUser.avatarUrl must equalTo(None)
  getUser.authMethod must equalTo(AuthenticationMethod("userPassword"))
  getUser.oAuth1Info must equalTo(None)
  getUser.oAuth2Info must equalTo(None)
  getUser.passwordInfo.get.hasher must equalTo(PasswordHasher.BCryptHasher)
  getUser.passwordInfo.get.password must      equalTo("$2a$10$eYPUTBSjprjKKmUf4m4XRuwurSxKKwbw13eP6WyDNk/LdpKgBytda")
  getUser.passwordInfo.get.salt must equalTo(None)
}

再次感谢。

1 个答案:

答案 0 :(得分:0)

您应该从播放应用程序中检索MyUserService插件实例,并在检索到的MyUserService实例上调用find方法。 你是如何做的(如上所示)find必须在MyUserService对象中定义。

更新:可以像这样检索MyUserService插件:

"retrieve a user by UserId" in new WithApplication  {
  val userService = implicitApp.plugin(classOf[MyUserService]).get
  ...
}