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


Scala WsTestClient类代码示例

本文整理汇总了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
      }
    }
  }

} 
开发者ID:wsargent,项目名称:play-cucumber,代码行数:18,代码来源:RoutesSpec.scala

示例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
        }
      }
    }
  }

} 
开发者ID:wsargent,项目名称:play-cucumber,代码行数:27,代码来源:ServerSpec.scala

示例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)
    }
  }
} 
开发者ID:dnvriend,项目名称:spring-kafka-test,代码行数:47,代码来源:IntegrationSpec.scala

示例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))
      }
    }
  }

} 
开发者ID:agaro1121,项目名称:jobcoin-mixer,代码行数:37,代码来源:TestUtils.scala

示例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")
      }
    }
  }

} 
开发者ID:bartholomews,项目名称:spotify-scala-client,代码行数:29,代码来源:BaseApiSpec.scala


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