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


Scala OK类代码示例

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


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

示例1: 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

示例2: APITest

//设置package包名称以及导入依赖的类
import org.scalatestplus.play.OneAppPerTest
import org.scalatestplus.play.PlaySpec

import play.api.test.FakeRequest
import play.api.test.Helpers.FORBIDDEN
import play.api.test.Helpers.GET
import play.api.test.Helpers.NOT_FOUND
import play.api.test.Helpers.OK
import play.api.test.Helpers.TOO_MANY_REQUESTS
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 services.CSVData
import services.CSVExtractor

class APITest extends PlaySpec with OneAppPerTest {

  lazy val data = CSVExtractor.extract("public/hoteldb.csv")

  "CSV extractor" should {
    "extracts data" in {
      data must have size (26)
      data.head must equal(CSVData("Bangkok", 1, "Deluxe", 1000))
    }
  }

  "Find Hotels action" should {
    "returns 200 with valid API key" in {
      route(app, FakeRequest(GET, "/api/hotels?key=apikey1&cityId=Bangkok&sort=desc")).map(status(_)) mustBe Some(OK)
    }
    "returns 429 with multiple requests" in {
      route(app, FakeRequest(GET, "/api/hotels?key=apikey1&cityId=Bangkod&sort=desc")).map(status(_)) mustBe Some(TOO_MANY_REQUESTS)
    }
    "returns 200 after 20 seconds suspension" in {
      Thread.sleep(1000 * 5)
      //Checking after 5 seconds
      route(app, FakeRequest(GET, "/api/hotels?key=apikey1&cityId=Bangkok&sort=desc")).map(status(_)) mustBe Some(TOO_MANY_REQUESTS)
      Thread.sleep(1000 * 15)
      //Checking after 20 seconds
      route(app, FakeRequest(GET, "/api/hotels?key=apikey1&cityId=Bangkok&sort=desc")).map(status(_)) mustBe Some(OK)
    }
    "returns 403 with invalid API key" in {
      route(app, FakeRequest(GET, "/api/hotels?key=apikey3&cityId=Bangkok&sort=desc")).map(status(_)) mustBe Some(FORBIDDEN)
    }
    "returns 404 with wrong city ID" in {
      route(app, FakeRequest(GET, "/api/hotels?key=apikey2&cityId=Bangkod&sort=desc")).map(status(_)) mustBe Some(NOT_FOUND)
    }
  }
} 
开发者ID:jayhawk,项目名称:ratelimit-api,代码行数:51,代码来源:APITest.scala


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