+htp #15920 import DebuggingDirectives from spray

This commit is contained in:
Johannes Rudolph 2014-10-20 14:04:44 +02:00
parent 34363374b6
commit 4b05824730
3 changed files with 164 additions and 1 deletions

View file

@ -0,0 +1,77 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.http.server
package directives
import akka.event.LoggingAdapter
import akka.http.util._
class DebuggingDirectivesSpec extends RoutingSpec {
var debugMsg = ""
def resetDebugMsg(): Unit = { debugMsg = "" }
val log = new LoggingAdapter {
def isErrorEnabled = true
def isWarningEnabled = true
def isInfoEnabled = true
def isDebugEnabled = true
def notifyError(message: String): Unit = {}
def notifyError(cause: Throwable, message: String): Unit = {}
def notifyWarning(message: String): Unit = {}
def notifyInfo(message: String): Unit = {}
def notifyDebug(message: String): Unit = { debugMsg += message + '\n' }
}
"The 'logRequest' directive" should {
"produce a proper log message for incoming requests" in {
val route =
withLog(log)(
logRequest("1")(
completeOk))
resetDebugMsg()
Get("/hello") ~> route ~> check {
response shouldEqual Ok
debugMsg shouldEqual "1: HttpRequest(HttpMethod(GET),http://example.com/hello,List(),Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1))\n"
}
}
}
"The 'logResponse' directive" should {
"produce a proper log message for outgoing responses" in {
val route =
withLog(log)(
logResult("2")(
completeOk))
resetDebugMsg()
Get("/hello") ~> route ~> check {
response shouldEqual Ok
debugMsg shouldEqual "2: Complete(HttpResponse(200 OK,List(),Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1)))\n"
}
}
}
"The 'logRequestResponse' directive" should {
"produce proper log messages for outgoing responses, thereby showing the corresponding request" in {
val route =
withLog(log)(
logRequestResult("3")(
completeOk))
resetDebugMsg()
Get("/hello") ~> route ~> check {
response shouldEqual Ok
debugMsg shouldEqual """|3: Response for
| Request : HttpRequest(HttpMethod(GET),http://example.com/hello,List(),Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1))
| Response: Complete(HttpResponse(200 OK,List(),Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1)))
|""".stripMarginWithNewline("\n")
}
}
}
}