How can I execute this controller action code in an integration test?

by Colin Strong   Last Updated November 09, 2018 00:26 AM

I am writing an integration test using the Scala Play framework.

I in the controller I have a function that looks like this:

def myEndpoint: AnyAction = myActionProvider.securedEndpoint("myEndpoint") { implicit request =>
    // Business logic
    Ok("")
}

myActionProvider.securedEndpoint chains together some Action builders using andThen() and returns an ActionBuilder.

In my integration test I have the following:

val fakeRequest: FakeRequest = buildFakeRequest()
myController.myEndpoint.apply(fakeRequest)

The fake request contains a generated security token and other headers required by our app.

I am able to break inside myActionProvider.securedEndpoint and follow the execution. However, I am not able to break inside any of the invokeBlock methods, nor inside the business logic of the controller. Logging shows that those pathways are never executed.

If I save the result of myController.myEndpoint.apply(fakeRequest) to a variable, its type is SinkAccumulator. It looks like this contains the chained Action builders and the business logic code block, but Play never executes it.

The code throws no exceptions and nothing is output to the console.

I was wondering if it was an error with my test syntax. I've also tried the following, to no avail:

  • dataUploadController.processFiles { fakeRequest }
  • dataUploadController.processFiles()(fakeRequest)

And yes, the code works in a "regular" e.g. non-testing environment :)



Related Questions


Updated February 23, 2017 01:26 AM

Updated June 11, 2017 18:26 PM

Updated January 04, 2018 19:26 PM

Updated February 26, 2017 00:26 AM

Updated April 17, 2018 03:26 AM