本文整理汇总了Scala中play.api.test.WsTestClient类的典型用法代码示例。如果您正苦于以下问题:Scala WsTestClient类的具体用法?Scala WsTestClient怎么用?Scala WsTestClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WsTestClient类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: RoutesSpec
//设置package包名称以及导入依赖的类
import loader.MyApplicationBuilder
import play.api.libs.ws.WSClient
import play.api.test.WsTestClient
class RoutesSpec extends MixedPlaySpecWithNoDefaultApp
{
"send OK on router test" in new Server((new MyApplicationBuilder()).build()) {
implicit val ec = app.actorSystem.dispatchers.defaultGlobalDispatcher
WsTestClient.withClient { ws: WSClient =>
ws.url(s"http://localhost:${port}/").get().map { response =>
response.status mustBe 200
}
}
}
}
示例2: ServerSpec
//设置package包名称以及导入依赖的类
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play._
import play.api.libs.ws.WSClient
import play.api.mvc.Results
import play.api.test.Helpers._
import play.api.test.WsTestClient
class ServerSpec extends PlaySpec
with OneServerPerSuiteWithMyComponents
with Results
with ScalaFutures {
"Server query should" should {
"work" in {
implicit val ec = app.actorSystem.dispatchers.defaultGlobalDispatcher
WsTestClient.withClient { ws: WSClient =>
ws.url(s"http://localhost:${port}/").get().map { response =>
response.status mustBe 200
}
}
}
}
}
示例3: IntegrationSpec
//设置package包名称以及导入依赖的类
package com.github.dnvriend
import akka.actor.{ActorRef, ActorSystem, PoisonPill}
import akka.stream.Materializer
import akka.testkit.TestProbe
import akka.util.Timeout
import org.scalatest._
import org.scalatest.concurrent.{Eventually, ScalaFutures}
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.test.WsTestClient
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import scala.reflect.ClassTag
class IntegrationSpec extends FlatSpec
with Matchers
with GivenWhenThen
with OptionValues
with TryValues
with ScalaFutures
with WsTestClient
with BeforeAndAfterAll
with BeforeAndAfterEach
with Eventually
with GuiceOneServerPerSuite {
def getComponent[A: ClassTag]: A = app.injector.instanceOf[A]
// set the port number of the HTTP server
override lazy val port: Int = 9001
implicit val pc: PatienceConfig = PatienceConfig(timeout = 30.seconds, interval = 300.millis)
implicit val system: ActorSystem = getComponent[ActorSystem]
implicit val ec: ExecutionContext = getComponent[ExecutionContext]
implicit val mat: Materializer = getComponent[Materializer]
implicit val timeout: Timeout = 10.seconds
def killActors(actors: ActorRef*): Unit = {
val tp = TestProbe()
actors.foreach { (actor: ActorRef) =>
tp watch actor
actor ! PoisonPill
tp.expectTerminated(actor)
}
}
}
示例4: TestUtils
//设置package包名称以及导入依赖的类
import helpers.JobcoinConfig
import play.api.mvc.{Action, Results}
import play.api.test.WsTestClient
import play.core.server.Server
import services.JobcoinService
import play.api.routing.sird._
import scala.concurrent.duration._
import scala.language.postfixOps
object TestUtils {
private val emptyConfig = new JobcoinConfig(
url = "",
transactionEndpoint = "/transactions",
addressEndpoint = "",
retries = 2,
timeout = 1 minute
)
def withJobcoinService[T](block: JobcoinService => T): T = {
Server.withRouter() {
case GET(p"/transactions") =>
Action(Results.Ok(JobcoinMockPayloads.Transactions))
case POST(p"/transactions") =>
Action(Results.Ok(JobcoinMockPayloads.NewTransactionSuccessResponse))
} { implicit port =>
WsTestClient.withClient { client =>
block(new JobcoinService(emptyConfig, client))
}
}
}
}
示例5: BaseApiSpec
//设置package包名称以及导入依赖的类
import it.turingtest.spotify.scala.client.{AuthApi, BaseApi}
import it.turingtest.spotify.scala.client.entities.Track
import org.scalatest.{FunSpec, Matchers}
import org.scalatestplus.play.guice.GuiceOneServerPerTest
import play.api.test.WsTestClient
class BaseApiSpec extends FunSpec with Matchers with GuiceOneServerPerTest with SpotifyWebMock {
describe("Base Api") {
it("should have a constructor with default uri to api endpoint") {
WsTestClient.withClient { client =>
val authApi = new AuthApi(config, client)
val baseApi = new BaseApi(client, authApi)
baseApi.BASE_URL shouldBe "https://api.spotify.com/v1"
}
}
it("should be able to get a resource") {
withBaseApi { api =>
val result = await { api.get[Track]("/tracks/3n3Ppam7vgaVa1iaRUc9Lp") }
result.id shouldBe Some("3n3Ppam7vgaVa1iaRUc9Lp")
}
}
}
}