!htk rename RouteTest::entity to RouteTest::responseEntity, smaller test cleanups

Also upgrade to latest (un)marshalling changes.
This commit is contained in:
Mathias 2014-11-12 14:33:10 +01:00
parent d65fe4e04e
commit 931e8f9b18
5 changed files with 38 additions and 65 deletions

View file

@ -54,17 +54,17 @@ trait RouteTest extends RequestBuilding with RouteTestResultComponent with Marsh
def handled: Boolean = result.handled
def response: HttpResponse = result.response
def entity: HttpEntity = result.entity
def responseEntity: HttpEntity = result.entity
def chunks: immutable.Seq[HttpEntity.ChunkStreamPart] = result.chunks
def entityAs[T: FromEntityUnmarshaller: ClassTag](implicit timeout: Duration = 1.second): T = {
def msg(e: Throwable) = s"Could not unmarshal entity to type '${implicitly[ClassTag[T]]}' for `entityAs` assertion: $e\n\nResponse was: $response"
Await.result(Unmarshal(entity).to[T].fast.recover[T] { case error failTest(msg(error)) }, timeout)
Await.result(Unmarshal(responseEntity).to[T].fast.recover[T] { case error failTest(msg(error)) }, timeout)
}
def responseAs[T: FromResponseUnmarshaller: ClassTag](implicit timeout: Duration = 1.second): T = {
def msg(e: Throwable) = s"Could not unmarshal response to type '${implicitly[ClassTag[T]]}' for `responseAs` assertion: $e\n\nResponse was: $response"
Await.result(Unmarshal(response).to[T].fast.recover[T] { case error failTest(msg(error)) }, timeout)
}
def contentType: ContentType = entity.contentType
def contentType: ContentType = responseEntity.contentType
def mediaType: MediaType = contentType.mediaType
def charset: HttpCharset = contentType.charset
def definedCharset: Option[HttpCharset] = contentType.definedCharset