Permalink
Browse files

Merge pull request #293 from fernandezpablo85/master

Support for AsyncResults in functional testing
  • Loading branch information...
2 parents 2fcc284 + 3b6982b commit e136cfee17abd14fd4ad0e0d2c0e009496cad448 @guillaumebort guillaumebort committed May 15, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 framework/src/play/src/main/scala/play/core/j/JavaResults.scala
@@ -34,11 +34,13 @@ object JavaResults extends Results with DefaultWriteables with DefaultContentTyp
object JavaResultExtractor {
def getStatus(result: play.mvc.Result): Int = result.getWrappedResult match {
+ case r: AsyncResult => getStatus(new ResultWrapper(r.result.await.get))
case Result(status, _) => status
case r => sys.error("Cannot extract the Status code from a result of type " + r.getClass.getName)
}
def getCookies(result: play.mvc.Result): JCookies = result.getWrappedResult match {
+ case r: AsyncResult => getCookies(new ResultWrapper(r.result.await.get))
case Result(_, headers) => new JCookies {
def get(name: String) = {
Cookies(headers.get(HeaderNames.SET_COOKIE)).get(name).map { cookie =>
@@ -50,16 +52,22 @@ object JavaResultExtractor {
}
def getHeaders(result: play.mvc.Result): java.util.Map[String, String] = result.getWrappedResult match {
+ case r: AsyncResult => getHeaders(new ResultWrapper(r.result.await.get))
case Result(_, headers) => headers.asJava
case r => sys.error("Cannot extract the Status code from a result of type " + r.getClass.getName)
}
def getBody(result: play.mvc.Result): Array[Byte] = result.getWrappedResult match {
+ case r: AsyncResult => getBody(new ResultWrapper(r.result.await.get))
case r @ SimpleResult(_, bodyEnumerator) => {
var readAsBytes = Enumeratee.map[r.BODY_CONTENT](r.writeable.transform(_)).transform(Iteratee.consume[Array[Byte]]())
bodyEnumerator(readAsBytes).flatMap(_.run).value.get
}
case r => sys.error("Cannot extract the body content from a result of type " + r.getClass.getName)
}
+ class ResultWrapper(r: play.api.mvc.Result) extends play.mvc.Result {
+ def getWrappedResult = r
+ }
+
}

0 comments on commit e136cfe

Please sign in to comment.