Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add an integration test for Java AsyncResult

  • Loading branch information...
commit f1a9cee2c036735954ef34d504857e177bfe0bbe 1 parent 09af364
@kevinbosman authored
View
23 framework/test/integrationtest-java/app/controllers/Application.java
@@ -1,7 +1,10 @@
package controllers;
+import java.util.concurrent.Callable;
import org.codehaus.jackson.JsonNode;
import play.*;
+import play.libs.Akka;
+import play.libs.F.Function;
import play.mvc.*;
import views.html.*;
@@ -22,5 +25,23 @@ public static Result getIdenticalJson() {
JsonNode node = request().body().asJson();
return ok(node);
}
-
+
+ public static Result asyncResult() {
+ return async(Akka.future(new Callable<String>() {
+ @Override
+ public String call() {
+ return "success";
+ }
+ }).map(new Function<String, Result>() {
+ @Override
+ public Result apply(String a) {
+ response().setHeader("header_test", "header_val");
+ response().setCookie("cookie_test", "cookie_val");
+ session("session_test", "session_val");
+ flash("flash_test", "flash_val");
+ return ok(a);
+ };
+ }));
+ }
+
}
View
1  framework/test/integrationtest-java/conf/routes
@@ -4,6 +4,7 @@
GET / controllers.Application.index(name = "Guest")
GET /key controllers.Application.key
+GET /async controllers.Application.asyncResult
GET /:name controllers.Application.index(name)
POST /json controllers.Application.getIdenticalJson()
View
49 framework/test/integrationtest-java/test/test/SimpleTest.java
@@ -19,6 +19,8 @@
import play.libs.F;
import play.libs.F.*;
+import play.api.mvc.AsyncResult;
+
import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;
@@ -157,4 +159,51 @@ public void run() {
}
});
}
+
+ @Test
+ public void asyncResult() {
+
+ class AsyncTestResult implements Result {
+ private final play.api.mvc.Result wrappedResult;
+
+ @Override
+ public play.api.mvc.Result getWrappedResult() {
+ return wrappedResult;
+ }
+
+ public AsyncTestResult(Result result) {
+ play.api.mvc.Result wrappedResult = result.getWrappedResult();
+ if (wrappedResult instanceof AsyncResult)
+ this.wrappedResult = ((AsyncResult) wrappedResult).result()
+ .value().get();
+ else
+ this.wrappedResult = wrappedResult;
+ }
+
+ }
+
+ running(fakeApplication(), new Runnable() {
+ @Override
+ public void run() {
+ Result result = routeAndCall(fakeRequest(
+ GET, "/async"));
+ assertThat(result.getWrappedResult() instanceof AsyncResult)
+ .isEqualTo(true);
+ result = new AsyncTestResult(result);
+ assertThat(status(result)).isEqualTo(OK);
+ assertThat(charset(result)).isEqualTo("utf-8");
+ assertThat(contentAsString(result)).isEqualTo("success");
+ assertThat(contentType(result)).isEqualTo("text/plain");
+ assertThat(header("header_test", result)).isEqualTo(
+ "header_val");
+ assertThat(session(result).get("session_test")).isEqualTo(
+ "session_val");
+ assertThat(cookie("cookie_test", result).value()).isEqualTo(
+ "cookie_val");
+ assertThat(flash(result).get("flash_test")).isEqualTo(
+ "flash_val");
+ }
+ });
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.