/** * 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; }