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