当前位置: 首页>>代码示例>>Scala>>正文


Scala GuiceOneAppPerSuite类代码示例

本文整理汇总了Scala中org.scalatestplus.play.guice.GuiceOneAppPerSuite的典型用法代码示例。如果您正苦于以下问题:Scala GuiceOneAppPerSuite类的具体用法?Scala GuiceOneAppPerSuite怎么用?Scala GuiceOneAppPerSuite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GuiceOneAppPerSuite类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ApplicationSpec

//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api._
import play.api.cache.CacheApi
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.Helpers._
import play.api.test._
import util.FakeCache


class ApplicationSpec extends PlaySpec with GuiceOneAppPerSuite {

  implicit override lazy val app = new GuiceApplicationBuilder()
    .overrides(bind[CacheApi].to[FakeCache])
    .loadConfig(env => Configuration.load(env))
    .in(Mode.Test)
    .build

  "Routes" should {

    "send 404 on a bad request" in {
      route(app, FakeRequest(GET, "/boum")).map(status(_)) mustBe Some(NOT_FOUND)
    }

  }

  "NewsPageController" should {

    "render the index page" in {
      val home = route(app, FakeRequest(GET, "/")).get

      status(home) mustBe OK
      contentType(home) mustBe Some("text/html")
      contentAsString(home) must include("Aktuelles der Fakultät Informatik")
    }

  }

} 
开发者ID:P1tt187,项目名称:spirit-play,代码行数:41,代码来源:ApplicationSpec.scala

示例2: userAuthenticator

//设置package包名称以及导入依赖的类
import auth.UserAuthenticator
import com.jasperdenkers.play.auth.LoginData
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._

trait AuthenticationHelper { self: GuiceOneAppPerSuite =>

  def userAuthenticator: UserAuthenticator

  def adminLoginData(remember: Boolean) = LoginData("admin", "123", remember)
  def userLoginData(remember: Boolean) = LoginData("user", "321", remember)
  val invalidLoginData = LoginData("invalid", "invalid", false)

  def loginResult(loginData: LoginData) = {
    val data = Map(
      "username" -> loginData.identifier,
      "password" -> loginData.plaintextPassword,
      "remember" -> loginData.remember.toString
    )

    route(app, FakeRequest(controllers.routes.LoginLogout.doLogin()).withJsonBody(Json.toJson(data))).get
  }

  def getSessionCookie(loginData: LoginData) = {
    val result = loginResult(loginData)

    cookies(result).get(userAuthenticator.cookieName)
  }

} 
开发者ID:jasperdenkers,项目名称:play-auth,代码行数:33,代码来源:AuthenticationHelper.scala

示例3: AddonDescriptorControllerSpec

//设置package包名称以及导入依赖的类
package controllers

import io.toolsplus.atlassian.connect.play.models.AddonProperties
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.Configuration
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._

class AddonDescriptorControllerSpec extends PlaySpec with GuiceOneAppPerSuite {

  val config = Configuration.reference ++ TestData.configuration
  val addonProperties = new AddonProperties(config)
  val $ = new AddonDescriptorController(addonProperties)

  override def fakeApplication() = {
    GuiceApplicationBuilder(configuration = config).build()
  }

  "AddonDescriptorController" when {

    "GET atlassian-connect.json" should {

      "render descriptor" in {
        val descriptor = $.descriptor.apply(FakeRequest())

        status(descriptor) mustBe OK
        contentType(descriptor) mustBe Some(JSON)

        val json = Json.parse(contentAsString(descriptor))
        (json \ "key").as[String] mustBe addonProperties.key
        (json \ "baseUrl").as[String] mustBe addonProperties.baseUrl
        (json \ "name")
          .as[String] mustBe config.getString("atlassian.connect.name").get
      }

    }

    "GET to base URL" should {

      "redirect to descriptor" in {
        val redirect = $.redirectToDescriptor.apply(FakeRequest())

        redirectLocation(redirect) mustBe Some(
          routes.AddonDescriptorController
            .descriptor()
            .url)
      }

    }

  }

} 
开发者ID:toolsplus,项目名称:atlassian-connect-play-seed,代码行数:57,代码来源:AddonDescriptorControllerSpec.scala

示例4: EventSourceControllerSpec

//设置package包名称以及导入依赖的类
package controllers

import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.test.FakeRequest
import play.api.test.Helpers._


class EventSourceControllerSpec extends PlaySpec
    with GuiceOneAppPerSuite
    with ScalaFutures
{
  "event source controller" should {
    "return OK through route" in {
      val request = FakeRequest(method = GET, path = "/scala/eventSource/liveClock")
      route(app, request) match {
        case Some(future) =>
          whenReady(future) { result =>
            result.header.status mustEqual(OK)
          }
        case None =>
          fail
      }
    }
  }
} 
开发者ID:juancamilogaviriaacosta,项目名称:proyecto-transmimetro-JuanGaviria-MauricioMontano,代码行数:28,代码来源:EventSourceControllerSpec.scala

示例5: ScalaCommentControllerSpec

//设置package包名称以及导入依赖的类
package controllers

import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.test.FakeRequest
import play.api.test.Helpers._


class ScalaCommentControllerSpec extends PlaySpec
  with GuiceOneAppPerSuite
  with ScalaFutures
{

  "comment controller" should {
    "return OK through route" in {
      val request = FakeRequest(method = GET, path = "/scala/comet/liveClock")
      route(app, request) match {
        case Some(future) =>
          whenReady(future) { result =>
            result.header.status mustEqual(OK)
          }
        case None =>
          fail
      }
    }
  }
} 
开发者ID:juancamilogaviriaacosta,项目名称:proyecto-transmimetro-JuanGaviria-MauricioMontano,代码行数:29,代码来源:ScalaCommentControllerSpec.scala

示例6: CarAdvertControllerTest

//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import play.api.mvc.Results
import controllers.CarAdvertController
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.test.FakeRequest
import repository.DBResource

import scala.concurrent.ExecutionContext


class CarAdvertControllerTest extends PlaySpec with Results with GuiceOneAppPerSuite{
  "test create" should {
    "should create a new car advert" in {
      implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
      val dbResouce = app.injector.instanceOf[DBResource]
      val controller = new CarAdvertController(dbResouce)
      val body = controller.create().apply(FakeRequest())
      controller.list()
    }
  }
} 
开发者ID:shexiaogui,项目名称:car-adverts,代码行数:22,代码来源:CarAdvertControllerTest.scala

示例7: AuthServiceSpec

//设置package包名称以及导入依赖的类
import services.AuthService
import org.scalatestplus.play._
import play.core.server.Server
import play.api.routing.sird._
import play.api.test._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration._
import models.GithubUser
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class AuthServiceSpec extends PlaySpec with GuiceOneAppPerSuite {
  "AuthServiceSpec" should {
    "return return an access_token via postCode method call" in {
      Server.withRouter() {
        case POST(p"/login/oauth/access_token") => ActionMocks.getGithubTokenResponse()
      } { implicit port =>
        WsTestClient.withClient { client =>
          val authService = new AuthService(client, app.environment, app.configuration ,"", "")
          val result = Await.result(authService.postCode("1234"), 10.seconds)
          result must be ("12345551233123a")
        }
      }
    }

    "return a github user object via getUserInfo method" in {
      Server.withRouter() {
        case GET(p"/user") => ActionMocks.getGithubUserResponse()
      } { implicit port =>
        WsTestClient.withClient { client =>

          val authService = new AuthService(client, app.environment, app.configuration ,"", "")
          val resp = Await.result(authService.getUserInfo("1234"), 10.seconds)
          val jsresp = resp.validate[GithubUser]
          jsresp.fold(
            error => assertTypeError("GithubUser validation fails"),
            result => {
              result.login must be ("poweruser")
              result.id must be (12313)
            }
          )
        }
      }
    }

  }
} 
开发者ID:malaman,项目名称:scala-weather-app,代码行数:49,代码来源:AuthServiceSpec.scala

示例8: ControllerTest

//设置package包名称以及导入依赖的类
package controllers
import org.scalatestplus.play._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.Play
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc._
import play.api.test.Helpers.{GET => GET_REQUEST, _}
import play.api.test._

import scala.concurrent.Future


class ControllerTest extends PlaySpec with Results {


  "Test function indexx " should {
    "should be valid" in {
      val controller = new Application(stubControllerComponents())
      val result: Future[Result] = controller.indexx().apply(FakeRequest())
      controller.insert
      val bodyText: String = contentAsString(result)
      bodyText mustBe "Hello world!"
    }
  }

  "Application  controller " should {
    "url should open side for input " in {

      val request = FakeRequest()
      val controller = new Application(stubControllerComponents())
      val result: Future[Result] = controller.insert().apply(FakeRequest())
      val bodyText: String = contentAsString(result)
      bodyText must endWith ("</html>")
    }

  }
}





class ExampleSpec extends PlaySpec with GuiceOneAppPerSuite {


  // Override fakeApplication if you need a Application with other than
  // default parameters.
  override def fakeApplication() = new GuiceApplicationBuilder().configure(Map("ehcacheplugin" -> "disabled")).build()

  "The GuiceOneAppPerSuite trait" must {
    "provide an Application" in {
      app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled")
    }
    "start the Application" in {
      Play.maybeApplication mustBe Some(app)
    }
  }
} 
开发者ID:devknutst,项目名称:searchIndex,代码行数:59,代码来源:ControllerTest.scala

示例9: PostSpec

//设置package包名称以及导入依赖的类
package v1.post.test.functional

import play.api.test._
import org.scalatestplus.play._
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.{ Application, Play }
import play.api.inject.guice._
import play.api.routing._
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.WebDriver
import org.scalatest.Matchers
import org.scalatest.selenium.WebBrowser
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class PostSpec extends PlaySpec with GuiceOneAppPerSuite {

  // Override fakeApplication if you need a Application with other than
  // default parameters.
  override def fakeApplication() = new GuiceApplicationBuilder().build()

  "The GuiceOneAppPerSuite trait" must {
    "start the Application" in {
      app.configuration != null mustBe true
      app.configuration.getConfig("play") != null mustBe true
    }
  }
} 
开发者ID:thaoninh,项目名称:ScalaPlayApiProject,代码行数:28,代码来源:PostSpec.scala


注:本文中的org.scalatestplus.play.guice.GuiceOneAppPerSuite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。