2015-05-11 23:05:18 +02:00
|
|
|
/*
|
2016-01-25 10:16:14 +01:00
|
|
|
* Copyright (C) 2009-2016 Typesafe Inc. <http://www.typesafe.com>
|
2015-05-11 23:05:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package docs.http.scaladsl.server
|
|
|
|
|
|
|
|
|
|
// format: OFF
|
|
|
|
|
|
|
|
|
|
//# source-quote
|
|
|
|
|
import org.scalatest.{ Matchers, WordSpec }
|
|
|
|
|
import akka.http.scaladsl.model.StatusCodes
|
|
|
|
|
import akka.http.scaladsl.testkit.ScalatestRouteTest
|
|
|
|
|
import akka.http.scaladsl.server._
|
|
|
|
|
import Directives._
|
|
|
|
|
|
|
|
|
|
class FullTestKitExampleSpec extends WordSpec with Matchers with ScalatestRouteTest {
|
|
|
|
|
|
|
|
|
|
val smallRoute =
|
|
|
|
|
get {
|
|
|
|
|
pathSingleSlash {
|
|
|
|
|
complete {
|
|
|
|
|
"Captain on the bridge!"
|
|
|
|
|
}
|
|
|
|
|
} ~
|
|
|
|
|
path("ping") {
|
|
|
|
|
complete("PONG!")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"The service" should {
|
|
|
|
|
|
|
|
|
|
"return a greeting for GET requests to the root path" in {
|
2015-10-09 15:19:36 +02:00
|
|
|
// tests:
|
2015-05-11 23:05:18 +02:00
|
|
|
Get() ~> smallRoute ~> check {
|
2015-05-21 10:50:27 +02:00
|
|
|
responseAs[String] shouldEqual "Captain on the bridge!"
|
2015-05-11 23:05:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"return a 'PONG!' response for GET requests to /ping" in {
|
2015-10-09 15:19:36 +02:00
|
|
|
// tests:
|
2015-05-11 23:05:18 +02:00
|
|
|
Get("/ping") ~> smallRoute ~> check {
|
|
|
|
|
responseAs[String] shouldEqual "PONG!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"leave GET requests to other paths unhandled" in {
|
2015-10-09 15:19:36 +02:00
|
|
|
// tests:
|
2015-05-11 23:05:18 +02:00
|
|
|
Get("/kermit") ~> smallRoute ~> check {
|
|
|
|
|
handled shouldBe false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"return a MethodNotAllowed error for PUT requests to the root path" in {
|
2015-10-09 15:19:36 +02:00
|
|
|
// tests:
|
2015-05-11 23:05:18 +02:00
|
|
|
Put() ~> Route.seal(smallRoute) ~> check {
|
|
|
|
|
status === StatusCodes.MethodNotAllowed
|
|
|
|
|
responseAs[String] shouldEqual "HTTP method not allowed, supported methods: GET"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#
|