Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:20:20+00:00 2026-06-15T23:20:20+00:00

Using Play 2.1-RC1 I can’t write simple test. Here’s the action code: def echoTestTagFromXml

  • 0

Using Play 2.1-RC1 I can’t write simple test.

Here’s the action code:

def echoTestTagFromXml = Action(parse.xml) { request =>
    (request.body \ "test" headOption).map(_.text).map { test =>
        Ok(views.xml.testTag(test))
    }.getOrElse {
      BadRequest("Missing parameter [name]")
    }
}

Here’s testing code:

"Test Tag Xml Echo" in {
    running(FakeApplication()) {
      val req = new FakeRequest(POST, controllers.routes.SimpleResultsController.echoTestTagFromXml().url, FakeHeaders(), Xml("<test>gg</test>"))        
      val result = controllers.SimpleResultsController.echoTestTagFromXml()(req)
      status(result) must equalTo(OK)
    }
}

Test gives the error:

[error]  found   : play.api.libs.iteratee.Iteratee[Array[Byte],play.api.mvc.Result]
[error]  required: play.api.mvc.Result

From Google I know problem is in BodyParser. But I have no idea(after API investigation) how to make the code working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:20:21+00:00Added an answer on June 15, 2026 at 11:20 pm

    The following modified testing code should work, but I think there is a bug at the moment when trying to pass a body into a FakeRequest, somewhat a hangover with the Functional tests now deprecated ‘routeAndCall’ function. The body is always empty.

    "Test Tag Xml Echo" in {
      running(FakeApplication()) {
        val req = FakeRequest(POST, controllers.routes.SimpleResultsController.echoTestTagFromXml().url, FakeHeaders(), Xml("<test>gg</test>"))
          .withHeaders(CONTENT_TYPE -> "text/xml")
        val result = await(controllers.SimpleResultsController.echoTestTagFromXml()(req).run)
        contentAsString(result) must equalTo("gg")
        status(result) must equalTo(OK)
      }
    }
    

    I have a similar issue with passing Json into the body, but tried to get this working for your body parser (note the differences). Also, please set the content-type header.

    You can however use the ‘route’ function instead:

    "Test Tag Xml Echo Route" in {
      running(FakeApplication()) {
        val result = route(FakeRequest(POST, "/SimpleResultsController").withHeaders(CONTENT_TYPE -> "text/xml"), Xml("<test>gg</test>")).get
        contentAsString(result) must equalTo("gg")
        status(result) must equalTo(OK)
      }
    }
    

    This seems to work for me and you should be able to copy/paste this solution.

    If you don’t want to repeat your route as a string then you can use the reverse routes as you did before: controllers.routes.SimpleResultsController.echoTestTagFromXml().url

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The setup: Using Play! framework v 2.0.4 The controller: def javascriptRoutes = Action {
i'm using play now , here is some code in the controller.class i don't
I`m using Play! Framework 2.0 and I'm new in this framework. How can I
I am using Play Framework 2.0 with Scala. So I have an action that
Using Play! 1.2.4, Scala, and Squeryl with Postgres Performing a simple DB insert like
I am using play framework 1.2+ - I can save an image to disk
I'm trying to start Play 1.2.3 in test mode using play test but I
I'm using play 1.2.4 and I'm trying to set up a unit test to
Using Play Framework, you can do something like this: public static void mymethod() {
I'm using Play Framework, and have the following code: import org.hibernate.exception.ConstraintViolationException; ... public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.