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

Scala contentAsString类代码示例

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

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



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

示例1: run

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

import java.io.File

import loader.{AppApplicationLoader, AppComponents}
import mqtt.MqttConnector
import play.api.test.Helpers._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.test.FakeRequest
import play.api.test.Helpers.{GET, contentAsString, route}
import play.core.{DefaultWebCommands, SourceMapper, WebCommands}
import play.filters.csrf.CSRF.Token

trait IntegrationTest {

  var appComponents:BuiltInComponentsFromContext with WithoutMqttAppComponents = null

  trait WithoutMqttAppComponents extends AppComponents {
    override lazy val mqttConnector = new MqttConnector(null, null, actorSystem) {
      override val reconnect = new Runnable {
        override def run() = {}
      }
    }
  }

  class WithoutMqttApp extends AppApplicationLoader {
    override def createApp(context: Context) = {
      appComponents = new BuiltInComponentsFromContext(context) with WithoutMqttAppComponents
      appComponents
    }
  }

  implicit val app = new WithoutMqttApp()
    .load(ApplicationLoader.Context(environment, sourceMapper, webCommands, configuration))

  Play.start(app)

  def getCsrfToken() = {
    val request = FakeRequest(GET, "/data").withHeaders()
    val page = route(app, request).get
    val content = contentAsString(page)
    val name = ("""<input type="hidden" id="csrf_token_name" value="([\w]+)">""".r).findFirstMatchIn(content).get.group(1)
    val value = ("""<input type="hidden" id="csrf_token_value" value="([\w-]+)">""".r).findFirstMatchIn(content).get.group(1)
    Token(name, value)
  }

  def sourceMapper: Option[SourceMapper] = None
  def environment: Environment = Environment(new File("."), ClassLoader.getSystemClassLoader, Mode.Test)
  def webCommands: WebCommands = new DefaultWebCommands
  def configuration: Configuration = Configuration.load(Environment(new File("."), ClassLoader.getSystemClassLoader, Mode.Test))
} 
开发者ID:vavravl1,项目名称:home_center,代码行数:53,代码来源:IntegrationTest.scala


示例2: ApplicationSpec

//设置package包名称以及导入依赖的类
import java.util.concurrent.TimeUnit
import scala.concurrent.Await
import scala.concurrent.TimeoutException
import scala.concurrent.duration.Duration
import org.junit.runner.RunWith
import org.mongodb.scala.ScalaObservable
import org.mongodb.scala.bson.collection.immutable.Document
import org.mongodb.scala.model.Filters.and
import org.mongodb.scala.model.Filters.equal
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import core.database.DatabaseComponent
import models.User
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers.GET
import play.api.test.Helpers.NOT_FOUND
import play.api.test.Helpers.OK
import play.api.test.Helpers.contentAsString
import play.api.test.Helpers.contentType
import play.api.test.Helpers.defaultAwaitTimeout
import play.api.test.Helpers.route
import play.api.test.Helpers.status
import play.api.test.Helpers.writeableOf_AnyContentAsEmpty
import play.api.test.WithApplication
import core.database.JsonValueImplicits._
import play.api.libs.json.JsValue
import play.api.test.WithApplication


@RunWith(classOf[JUnitRunner])
class ApplicationSpec extends Specification with DatabaseComponent {

  "Application" should {

    "Be able to create a user" in new WithApplication {
      Await.ready(dropAllCollections(), Duration(10, TimeUnit.SECONDS))
      
      val resultObservable = User.create(User("TEST_USER", "TEST_PASSWORD"))
      Await.ready(resultObservable, Duration(10, TimeUnit.SECONDS))
      
      val result:Boolean = Await.result(User.authenticate("TEST_USER", "TEST_PASSWORD"), Duration(10, TimeUnit.SECONDS))
      
      assert(result)
    }

    "send 404 on a bad request" in new WithApplication {
      route(FakeRequest(GET, "/boum")) must beSome.which(status(_) == NOT_FOUND)
    }

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

      status(home) must equalTo(OK)
      contentType(home) must beSome.which(_ == "text/html")
      contentAsString(home) must contain("Your new application is ready.")
    }
  }
} 
开发者ID:Vladislav-Zolotaryov,项目名称:EchoCave,代码行数:60,代码来源:ApplicationSpec.scala


示例3: aultAwaitTimeout

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

import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import org.junit.runner.RunWith
import play.api.test.FakeRequest
import play.api.test.WithApplication
import play.api.test.Helpers.{GET, OK, route, status, contentAsString, contentType,
writeableOf_AnyContentAsEmpty, defaultAwaitTimeout}



@RunWith(classOf[JUnitRunner])
class ApiSpec extends Specification {

  "Api" should {

    "respond with a json representation" in new WithApplication {
      val response = route(FakeRequest(GET, "/api")).get
      status(response) must equalTo(OK)
      contentType(response) must beSome.which(_ == "application/json")
       contentAsString(response) must beEqualTo(
       """{"links":[{"rel":"self","href":"http:///api","method":"GET"},""" +
         """{"rel":"users","href":"http:///api/users","method":"GET"}]}""".stripMargin)
    }
  }
} 
开发者ID:swenib,项目名称:grp1C-pizza,代码行数:28,代码来源:ApiSpec.scala


示例4: AdminEndpointsTest

//设置package包名称以及导入依赖的类
package uk.co.telegraph.utils.server.routes

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.util.Timeout
import com.typesafe.config.{Config, ConfigFactory}
import org.scalatest._
import play.api.Configuration
import play.api.http.{MimeTypes, Status}
import play.api.test.FakeRequest
import play.api.test.Helpers.{GET, await, contentAsString, stubControllerComponents}
import uk.co.telegraph.utils.server.routes.AdminEndpointsTest._

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

class AdminEndpointsTest
  extends FreeSpec
  with Matchers
  with BeforeAndAfter
  with BeforeAndAfterAll
{
  val endpoint = new AdminEndpoints(Configuration(ConfigTest), stubControllerComponents())

  implicit val TimeoutTest:Timeout = 3 seconds

  "Given the admin endpoint," - {

    "I should be able to get a JSON version of my config" in {
      val request = FakeRequest(GET, "/admin")
      val response = endpoint.getConfig.apply(request)

      val content = contentAsString(response)
      val result = await(response)

      result.body.contentType shouldBe Some(MimeTypes.JSON)
      result.header.status shouldBe Status.OK
      content shouldBe """{"app":{"param1":"value1","param2":["value21","value22"],"param3":"30 seconds"}}"""
    }
  }
}

object AdminEndpointsTest{
  val ConfigTest: Config = ConfigFactory.parseString(
    """
      |app {
      |   param1: "value1"
      |   param2: [
      |     "value21"
      |     "value22"
      |   ]
      |   param3: 30 seconds
      |}
    """.stripMargin)
  implicit val ActorSystemTest = ActorSystem("sample-system", ConfigTest)
  implicit val MaterializerTest = ActorMaterializer()
} 
开发者ID:telegraph,项目名称:tmg-utils,代码行数:58,代码来源:AdminEndpointsTest.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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