本文整理汇总了Scala中spray.testkit.Specs2RouteTest类的典型用法代码示例。如果您正苦于以下问题:Scala Specs2RouteTest类的具体用法?Scala Specs2RouteTest怎么用?Scala Specs2RouteTest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Specs2RouteTest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MyServiceSpec
//设置package包名称以及导入依赖的类
package com.example
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.http._
import StatusCodes._
class MyServiceSpec extends Specification with Specs2RouteTest with MyService {
def actorRefFactory = system
"MyService" should {
"return a greeting for GET requests to the root path" in {
Get() ~> myRoute ~> check {
responseAs[String] must contain("Say hello")
}
}
"leave GET requests to other paths unhandled" in {
Get("/kermit") ~> myRoute ~> check {
handled must beFalse
}
}
"return a MethodNotAllowed error for PUT requests to the root path" in {
Put() ~> sealRoute(myRoute) ~> check {
status === MethodNotAllowed
responseAs[String] === "HTTP method not allowed, supported methods: GET"
}
}
}
}
示例2: SanitySpec
//设置package包名称以及导入依赖的类
import com.pacbio.common.models.{ServiceStatus, PacBioJsonProtocol}
import com.pacbio.secondary.smrtlink.app.{SmrtLinkApi, SmrtLinkProviders}
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.httpx.SprayJsonSupport._
class SanitySpec extends Specification with Specs2RouteTest {
object Api extends SmrtLinkApi {
override val providers = new SmrtLinkProviders {}
}
val routes = Api.routes
val eventManagerActorX = Api.providers.eventManagerActor()
import PacBioJsonProtocol._
"Service list" should {
"return a list of services" in {
Get("/services/manifests") ~> routes ~> check {
status.isSuccess must beTrue
}
}
"Uptime should be >0" in {
Get("/status") ~> routes ~> check {
val status = responseAs[ServiceStatus]
// Uptime is in sec, not millisec
// this is the best we can do
status.uptime must be_>=(0L)
}
}
}
}
示例3: SmrtLinkAnalysisSanitySpec
//设置package包名称以及导入依赖的类
import com.pacbio.common.models.{PacBioJsonProtocol, ServiceStatus}
import com.pacbio.secondary.smrtlink.app.SecondaryAnalysisProviders
import org.specs2.mutable.Specification
import spray.httpx.SprayJsonSupport._
import spray.testkit.Specs2RouteTest
class SmrtLinkAnalysisSanitySpec extends Specification with Specs2RouteTest {
import PacBioJsonProtocol._
val providers = new SecondaryAnalysisProviders {}
val totalRoutes = providers.routes()
val eventManagerActorX = providers.eventManagerActor()
"Service list" should {
"return a list of services" in {
Get("/services/manifests") ~> totalRoutes ~> check {
status.isSuccess must beTrue
}
}
"Uptime should be >0" in {
Get("/status") ~> totalRoutes ~> check {
val status = responseAs[ServiceStatus]
// Uptime is in sec, not millisec
// this is the best we can do
status.uptime must be_>=(0L)
}
}
}
}
示例4: SanityBaseServiceSpec
//设置package包名称以及导入依赖的类
import com.pacbio.common.actors.InMemoryLogDaoProvider
import com.pacbio.common.app.{BaseApi, CoreProviders}
import com.pacbio.common.models.{PacBioJsonProtocol, ServiceStatus}
import com.pacbio.common.services.PacBioServiceErrors
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.routing._
import spray.httpx.SprayJsonSupport._
class SanityBaseServiceSpec extends Specification with Directives with Specs2RouteTest {
import PacBioJsonProtocol._
object Api extends BaseApi {
override val providers: CoreProviders = new CoreProviders with InMemoryLogDaoProvider {}
}
val routes = Api.routes
"Service list" should {
"Uptime should be >0" in {
Get("/status") ~> routes ~> check {
val status = responseAs[ServiceStatus]
// TODO(smcclellan): Use FakeClock to test this
status.uptime must be_>=(0L)
}
}
}
}
示例5: PersonServiceSpec
//设置package包名称以及导入依赖的类
package com.sky.workshop.spray
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.routing.HttpService
class PersonServiceSpec extends Specification with Specs2RouteTest with HttpService with PersonService {
def actorRefFactory = system
val personRespone = """{
| "title": "Mr",
| "forename": "Bobby",
| "surname": "Bobbyson"
|}""".stripMargin
"The Hello endpoint" should {
"return a greeting" in {
Get("/person") ~> personRoutes ~> check {
responseAs[String] must be equalTo(personRespone)
}
}
}
}
示例6: HelloServiceSpec
//设置package包名称以及导入依赖的类
package com.sky.workshop.spray
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.routing.HttpService
class HelloServiceSpec extends Specification with Specs2RouteTest with HttpService with HelloService {
def actorRefFactory = system
"The Hello endpoint" should {
"return a greeting" in {
Get("/hello") ~> helloRoutes ~> check {
responseAs[String] must contain("Say hello")
}
}
}
}
示例7: HttpServerSpec
//设置package包名称以及导入依赖的类
package com.sretsnom.mangareader.server
import org.specs2.mutable.Specification
import spray.http.StatusCodes._
import spray.testkit.Specs2RouteTest
class HttpServerSpec extends Specification with Specs2RouteTest with HttpServer {
def actorRefFactory = system
"The ServerApp" should {
"return a 'PONG!' response for GET requests to /ping" in {
Get("/health") ~> serverRoute ~> check {
responseAs[String] === "PONG!"
}
}
"return a MethodNotAllowed error for PUT requests to the root path" in {
Put() ~> sealRoute(serverRoute) ~> check {
status === MethodNotAllowed
responseAs[String] === "HTTP method not allowed, supported methods: GET"
}
}
}
}
示例8: ExtraMiscDirectivesSpec
//设置package包名称以及导入依赖的类
package eu.shiftforward.apso.spray
import org.specs2.mutable.Specification
import spray.http.CacheDirectives.{ `max-age`, `must-revalidate`, `no-cache`, `no-store` }
import spray.http.HttpHeaders.{ RawHeader, `Cache-Control` }
import spray.routing._
import spray.http.StatusCodes.OK
import spray.testkit.Specs2RouteTest
class ExtraMiscDirectivesSpec extends Specification with Directives with Specs2RouteTest {
"The ExtraMiscDirectives" should {
import ExtraMiscDirectives._
def noCacheRoute: Route = cacheControlNoCache(complete(OK))
def maxAgeRoute(age: Option[Long]): Route = cacheControlMaxAge(age)(complete(OK))
"expose a no-cache control directive" in {
Get("/") ~> noCacheRoute ~> check {
response.headers must contain(`Cache-Control`(`no-cache`, `no-store`, `must-revalidate`))
}
}
"expose a max-age directive" in {
Get("/") ~> maxAgeRoute(Some(9001l)) ~> check {
response.headers must contain(`Cache-Control`(`max-age`(60l * 9001), `must-revalidate`))
}
Get("/") ~> maxAgeRoute(None) ~> check {
response.headers must contain(`Cache-Control`(`no-cache`, `no-store`, `must-revalidate`))
}
}
"expose an optional referer header host directive" in {
val optRefRoute: Route =
get {
optionalRefererHost { referer =>
complete(referer.toString)
}
}
Get("/") ~> optRefRoute ~> check {
responseAs[String] mustEqual None.toString
}
Get("/") ~> addHeader(RawHeader("Referer", "http://example.com")) ~> optRefRoute ~> check {
responseAs[String] mustEqual Some("example.com").toString
}
Get("/") ~> addHeader(RawHeader("Referer", "invalidhost :(")) ~> optRefRoute ~> check {
responseAs[String] mustEqual None.toString
}
}
}
}
示例9: EtagServiceSpec
//设置package包名称以及导入依赖的类
package actor
import akka.actor.ActorRefFactory
import org.specs2.mutable.Specification
import spray.http.StatusCodes._
import spray.http.HttpHeaders._
import spray.testkit.Specs2RouteTest
class EtagServiceSpec extends Specification with Specs2RouteTest with EtagService {
def actorRefFactory: ActorRefFactory = system
import json.Json4sSupport._
"EtagService" should {
"""return status: "ok" for GET requests to the root path""" in {
Get().withHeaders(ETag("406161ad525c9bdf02a21db721f2ffeb")) ~> routes ~> check {
status === OK
val response = responseAs[FooResponse]
response.status must_== "ok"
response.method must_== "GET"
response.headerCount must_== 1
}
}
"leave GET requests to other paths unhandled" in {
Get("/unhandled") ~> routes ~> check {
handled must beFalse
}
}
"return a MethodNotAllowed error for PUT requests to the root path" in {
Put() ~> sealRoute(routes) ~> check {
status === MethodNotAllowed
// responseAs[String] === "HTTP method not allowed, supported methods: GET" // TODO fix
}
}
}
}
示例10: MyServiceSpec
//设置package包名称以及导入依赖的类
package com.wallace.demo.rest.sever.demo.rest
import akka.actor.ActorRefFactory
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
class MyServiceSpec extends Specification with Specs2RouteTest with MyService {
def actorRefFactory: ActorRefFactory = system
"MyService" should {
"return Json String" in {
Get("/wallace") ~> myRoute ~> check {
log.info(
s"""
|[Entity]: ${response.entity.asString}
|[Entity => Option]: ${response.entity.toOption}
|[Entity => Case Class]: ${responseAs[Map[String, Int]]}
|[Message]: ${response.message}
|[Protocol]: ${response.protocol}
|[Status]: ${status.intValue}
""".stripMargin)
status.intValue mustEqual 200
response.entity.toOption.get.asString must contain("{\"Wallace\":25,\"Lina\":26,\"Lucy\":24}")
responseAs[Map[String, Int]].get("Wallace") mustEqual Some(25)
//responseAs[String] must contain("test")
}
Get("/wallace/index") ~> myRoute ~> check {
status.intValue mustEqual 200
response.entity.asString must contain("hello,world!")
}
}
}
}
示例11: PeopleControllerSpec
//设置package包名称以及导入依赖的类
package com.angos.slicknspray
import org.specs2.mutable.Specification
import spray.http.StatusCodes._
import spray.testkit.Specs2RouteTest
class PeopleControllerSpec extends Specification with Specs2RouteTest with PeopleController {
def actorRefFactory = system
"MyService" should {
"return a greeting for GET requests to the root path" in {
Get() ~> myRoutes ~> check {
responseAs[String] must contain("Say hello")
}
}
"leave GET requests to other paths unhandled" in {
Get("/kermit") ~> myRoutes ~> check {
handled must beFalse
}
}
"return a MethodNotAllowed error for PUT requests to the root path" in {
Put() ~> sealRoute(myRoutes) ~> check {
status === MethodNotAllowed
responseAs[String] === "HTTP method not allowed, supported methods: GET"
}
}
}
}
示例12: RoutingServiceSpec
//设置package包名称以及导入依赖的类
package com.ganchurin.currency.rest
import akka.actor.ActorRef
import akka.testkit.TestActor.AutoPilot
import akka.testkit.{TestActor, TestProbe}
import com.ganchurin.currency.domain.Quote
import com.ganchurin.currency.message.QuoteRequest
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
class RoutingServiceSpec extends Specification with Specs2RouteTest {
"Rest service" should {
"Print empty json when quote is not available" in {
val service = new TestService()
Get("/quote/USD") ~> service.route ~> check {
responseAs[String] must contain("{}")
}
}
"Print json when quote is available" in {
val service = new TestService()
Get("/quote/EUR") ~> service.route ~> check {
responseAs[String] must contain("""{"code":"EUR","bid":75.0,"offer":85.0}""")
}
}
}
class TestService extends RoutingService {
def actorRefFactory = system
val currencyBoardActor = TestProbe("currency-board")
val autoPilot = new AutoPilot {
def run(sender: ActorRef, msg: Any): AutoPilot = msg match {
case QuoteRequest("USD") =>
sender ! Option.empty[Quote]
TestActor.KeepRunning
case QuoteRequest("EUR") =>
sender ! Some(Quote("EUR", 75.0, 85.0))
TestActor.NoAutoPilot
}
}
currencyBoardActor setAutoPilot autoPilot
val quoteBoard = currencyBoardActor.ref
}
}