Here is your test little modified showing two ways testing the controller. The reason AnyContentAsXml is not working for you because your testing is mixing two approaches together.
"one way" in new WithApplication {
val action = controllers.Application.main
val req: FakeRequest[scala.xml.NodeSeq] = new FakeRequest(
PUT,
"some url",
new FakeHeaders(Seq("Content-Type" -> Seq("text/xml"))),
<xml>xml</xml>
)
val x = action(req)
status(x) should beEqualTo(200)
}
"2nd way" in new WithApplication {
val Some(result) = route(new FakeRequest("PUT",
"/",
new FakeHeaders(Seq("Content-Type" -> Seq("text/xml"))),
AnyContentAsXml(<xml>xml</xml>)))
status(result) should beEqualTo(200)
}
}
In the second approach Play is take care of unpacking the xml for the BodyParser to use. And here is the controller:
def main = Action(BodyParsers.parse.xml) { request =>
println(">>>>>>>>>>>>>>>>>>> main")
Ok("")
}