/** * Constructs a new GET / fake request. */ public FakeRequest() { this.fake = play.api.test.FakeRequest.apply(); }
@SuppressWarnings(value = "unchecked") public play.api.mvc.Request<play.mvc.Http.RequestBody> getWrappedRequest() { return ((play.api.test.FakeRequest<play.api.mvc.AnyContent>)fake).map(new scala.runtime.AbstractFunction1<play.api.mvc.AnyContent, play.mvc.Http.RequestBody>() { public play.mvc.Http.RequestBody apply(play.api.mvc.AnyContent anyContent) { return new play.core.j.JavaParsers.DefaultRequestBody( anyContent.asFormUrlEncoded(), anyContent.asRaw(), anyContent.asText(), anyContent.asJson(), anyContent.asXml(), anyContent.asMultipartFormData(), false ); } }); }
/** * Set a any body to this request. * @param body the Body * @return the Fake Request */ public <T> FakeRequest withBody(T body) { this.fake = this.fake.withBody(body); return this; } }
/** * Set a AnyContent to this request. * @param content the AnyContent * @param contentType Content-Type header value * @param method The method to be set * @return the Fake Request */ public FakeRequest withAnyContent(AnyContent content, String contentType, String method) { Map<String, Seq<String>> map = new HashMap<String, Seq<String>>(Scala.asJava(fake.headers().toMap())); map.put("Content-Type", Scala.toSeq(new String[] {contentType})); fake = new play.api.test.FakeRequest(method, fake.uri(), new play.api.test.FakeHeaders(Scala.asScala(map).toSeq()), content, fake.remoteAddress(), fake.version(), fake.id(), fake.tags()); return this; }
/** * Set a Json Body to this request. * The <tt>Content-Type</tt> header of the request is set to <tt>application/json</tt>. * @param node the Json Node * @param method the HTTP method. <tt>POST</tt> if set to <code>null</code> * @return the Fake Request */ @SuppressWarnings(value = "unchecked") public FakeRequest withJsonBody(JsonNode node, String method) { if (method == null) { method = Helpers.POST; } Map<String, Seq<String>> map = new HashMap<String, Seq<String>>(Scala.asJava(fake.headers().toMap())); map.put("Content-Type", Scala.toSeq(new String[] {"application/json"})); AnyContentAsJson content = new AnyContentAsJson(play.api.libs.json.Json.parse(node.toString())); fake = new play.api.test.FakeRequest(method, fake.uri(), new play.api.test.FakeHeaders(Scala.asScala(map).toSeq()), content, fake.remoteAddress(), fake.version(), fake.id(), fake.tags()); return this; }
/** * Constructs a new request. */ public FakeRequest(String method, String path) { this.fake = play.api.test.FakeRequest.apply(method, path); }