• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala WsTestClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala SQLiteDatabase类代码示例发布时间:2022-05-23
下一篇:
Scala Global类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap