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

Scala Specs2RouteTest类代码示例

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

本文整理汇总了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"
      }
    }
  }
} 
开发者ID:hackathinho,项目名称:right-here,代码行数:33,代码来源:MyServiceSpec.scala


示例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)
      }
    }
  }
} 
开发者ID:PacificBiosciences,项目名称:smrtflow,代码行数:34,代码来源:SanitySpec.scala


示例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)
      }
    }
  }
} 
开发者ID:PacificBiosciences,项目名称:smrtflow,代码行数:33,代码来源:SmrtLinkAnalysisSanitySpec.scala


示例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)
      }
    }
  }

} 
开发者ID:PacificBiosciences,项目名称:smrtflow,代码行数:30,代码来源:SanityBaseServiceSpec.scala


示例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)
      }
    }
  }
} 
开发者ID:peteslater-sky,项目名称:SprayWorkshop,代码行数:24,代码来源:PersonServiceSpec.scala


示例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")
      }
    }
  }
} 
开发者ID:peteslater-sky,项目名称:SprayWorkshop,代码行数:18,代码来源:HelloServiceSpec.scala


示例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"
            }
        }
    }
} 
开发者ID:sretsnom,项目名称:mangareader,代码行数:25,代码来源:HttpServerSpec.scala


示例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
      }
    }
  }
} 
开发者ID:ShiftForward,项目名称:apso,代码行数:57,代码来源:ExtraMiscDirectivesSpec.scala


示例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
      }
    }
  }

} 
开发者ID:indarium,项目名称:imageGenEval,代码行数:43,代码来源:EtagServiceSpec.scala


示例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!")
      }
    }
  }
} 
开发者ID:LeagueForHacker,项目名称:Rest-Server-Demo,代码行数:41,代码来源:MyServiceSpec.scala


示例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"
      }
    }
  }
} 
开发者ID:jdkendall,项目名称:angos-slicknspray,代码行数:32,代码来源:PeopleControllerSpec.scala


示例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
	}

} 
开发者ID:ganchurin,项目名称:reactive-prototype,代码行数:50,代码来源:RoutingServiceSpec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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