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

Scala AnyContentAsEmpty类代码示例

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

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



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

示例1: I019_datetime_constructor_Spec

//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import play.api.mvc.{AnyContentAsEmpty, _}
import play.api.test.{FakeHeaders, _}
import play.api.test.Helpers._
import play.api.libs.json._

class I019_datetime_constructor_Spec extends PlaySpec with OneAppPerSuite {

  val exptectedContentType = "application/json"

  val headers = FakeHeaders(Seq("Accept" -> exptectedContentType))

  "I09" should {

    "be able to construct datetime objects from string" in {
      val stringRequest =
        """{
          |  "complete_before": "2016-07-25T13:15:53.208Z",
          |  "complete_after": "2016-07-25T13:15:53.208Z"
          |}""".stripMargin

      val fromString = route(app, FakeRequest(POST, "/019", headers, Json.parse(stringRequest))).get
      status(fromString) mustBe OK
      contentType(fromString) mustBe Some(exptectedContentType)
      contentAsString(fromString) must include("\"complete_before\":")
      contentAsString(fromString) must include("\"complete_after\":")
    }

    "be able to construct datetime objects from long" in {
      val longRequest =
        """{
          |  "complete_before": 1469452060,
          |  "complete_after": 1469452060
          |}""".stripMargin

      val fromLong = route(app, FakeRequest(POST, "/019", headers, Json.parse(longRequest))).get
      status(fromLong) mustBe OK
      contentType(fromLong) mustBe Some(exptectedContentType)
      contentAsString(fromLong) must include("\"complete_before\":")
      contentAsString(fromLong) must include("\"complete_after\":")
    }

    "be able to construct datetime objects from string in header and path" in {
      val request = "2016-07-25T13:15:53.208Z"
      val withHeader = FakeHeaders(("header", request) +: headers.data)
      val fromString = route(app, FakeRequest(GET, s"/019/$request", withHeader, AnyContentAsEmpty)).get
      contentAsString(fromString) must include("\"complete_before\":")
      contentAsString(fromString) must include("\"complete_after\":")
      status(fromString) mustBe OK
      contentType(fromString) mustBe Some(exptectedContentType)
    }

    "NOT be able to construct datetime objects from long in header and path" in {
      val request = 1469452060
      val withHeader = FakeHeaders(("header", request.toString) +: headers.data)
      val fromLong = route(app, FakeRequest(GET, s"/019/$request", withHeader, AnyContentAsEmpty)).get
      status(fromLong) mustBe BAD_REQUEST
    }
  }
} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:61,代码来源:I019_datetime_constructor_Spec.scala


示例2: TestBuilder

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

import play.api.Application
import play.api.mvc.{AnyContentAsEmpty, Result}
import play.api.test.{FakeHeaders, FakeRequest, Helpers}
import play.mvc.Call

import scala.concurrent.Future

object TestBuilder {

  object anUser {

    import play.api.test.Helpers._
    def GET(call: Call)(implicit app: Application): Option[Future[Result]] =
      route(app, fakeUnauthenticatedRequest(Helpers.GET, call.url(), FakeHeaders(), AnyContentAsEmpty))

    def POST[A](call: Call)(body: A)(implicit w: play.api.http.Writeable[A], app: Application): Option[Future[Result]] =
      route(app, fakeUnauthenticatedRequest(Helpers.POST, call.url(), jsonHeaders, body))

    private def fakeUnauthenticatedRequest[A](method: String, uri: String, headers: FakeHeaders, body: A): FakeRequest[A] = FakeRequest(
      method,
      uri,
      withAjaxHeader(headers),
      body
    )

    private def jsonHeaders = FakeHeaders(
      Seq("Content-Type" -> "application/json")
    )

    private def withAjaxHeader(headers: FakeHeaders): FakeHeaders = headers.copy(data = headers.data :+ ("X-Requested-With" -> "XMLHttpRequest"))
  }

} 
开发者ID:fagossa,项目名称:play-reactive-couchbase,代码行数:36,代码来源:TestBuilder.scala


示例3: FakeApplicationHelper

//设置package包名称以及导入依赖的类
package integration.helper

import play.api.mvc.{AnyContentAsEmpty, Result}
import play.api.test.Helpers._
import play.api.test.{FakeApplication, FakeRequest}
import play.api.{Application, Play}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps

object FakeApplicationHelper {


  def withApplication(app: Application)(call: () => Unit): Unit = {
    Play.start(app)
    try {
      call()
    }
    finally {
      Play.stop(app)
    }
  }

  def call(fakeRequest: FakeRequest[AnyContentAsEmpty.type], application: Application): Option[Result] =
    route(application, fakeRequest).map(t => Await.result(t, 100000 seconds))


  def callWithBody(fakeRequest: FakeRequest[String], application: Application): Option[Result] =
    route(application, fakeRequest).map(t => Await.result(t, 100000 seconds))


  def application(host: String = "localhost", port: Option[Integer] = None): FakeApplication = {
    val portPart= port.map( port => s":$port").getOrElse("")
    FakeApplication(additionalConfiguration = Map(("server.uri", s"http://$host$portPart")))
  }

} 
开发者ID:innoq,项目名称:docster,代码行数:39,代码来源:FakeApplicationHelper.scala


示例4: ShortestPathControllerSpec

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

import scala.annotation.implicitNotFound
import scala.concurrent.Future

import play.api.http.Writeable
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc.AnyContentAsEmpty
import play.api.mvc.Headers
import play.api.mvc.Result
import play.api.mvc.Results
import play.api.test.FakeRequest
import play.api.test.PlaySpecification

class ShortestPathControllerSpec extends PlaySpecification with Results {
  "End point is working#index" should {

    lazy val app = new GuiceApplicationBuilder().build
    val basicHeaders = Headers(
      "type" -> "application/json")
    def routeGET(uri: String) = getRoute(GET, uri, AnyContentAsEmpty)
    def getRoute[A](method: String, uri: String, body: A)(implicit w: Writeable[A]) = route(app, FakeRequest(method, uri, basicHeaders, body)).get

    def codeMustMatch(code: Int, result: Future[Result]) = {
      status(result) must equalTo(code)
    }

    s"End point is available" in {
      val source = "source_user"
      val destination = "destination_user"
      val result = routeGET("/shortestPath/source_user/destination_user")
      codeMustMatch(200, result)
      contentAsString(result) must contain("hops")
    }
  }
} 
开发者ID:joaoB,项目名称:shortestPath,代码行数:37,代码来源:ShortestPathControllerSpec.scala


示例5: HomeControllerTest

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

import org.scalatestplus.play.PlaySpec
import play.api.mvc.{AnyContentAsEmpty, Results}
import play.api.test.Helpers._
import play.api.test._

class HomeControllerTest extends PlaySpec with Results {

  val controller = new HomeController()

  "HomeController#index" should {
    "should get host address" in {
      val result = controller.index.apply(FakeRequest())

      status(result) mustEqual OK
      (contentAsJson(result) \ "hostname").as[String] mustEqual "localhost"
      (contentAsJson(result) \ "ip").as[String] mustEqual "127.0.0.1"
    }

    "should return ip when there is no host" in {
      val result = controller.index.apply(FakeRequest(GET, "/", FakeHeaders(), AnyContentAsEmpty, "127.0.0.2"))

      status(result) mustEqual OK
      (contentAsJson(result) \ "hostname").as[String] mustEqual "127.0.0.2"
      (contentAsJson(result) \ "ip").as[String] mustEqual "127.0.0.2"
    }
  }
} 
开发者ID:wayne530,项目名称:webby-play2-scala,代码行数:30,代码来源:HomeControllerTest.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala TolerantNumerics类代码示例发布时间:2022-05-23
下一篇:
Scala Font类代码示例发布时间: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