FunctionalTest, URL and redirect

228 views
Skip to first unread message

Neoh59

unread,
Dec 28, 2010, 1:52:50 PM12/28/10
to play-fr...@googlegroups.com
Hi all,

I just begin with functional tests and ... I have some questions.

My app is based on the sample app "booking". I used the CRUD module to manage database, and the secure module to restrict access to the CRUD pages (admin area).
I want to check that my admin area need an authenticated user (see attachment).

L17: My test starts with trying to connect to the admin area.
L18: HTTP status must be 302 because user is not authenticated, so he is redirected to a login page.
L19: The test reads the "Location" HTTP header (is there any constant for that ? in Play! or Java ?)
L20+L21: If I just call GET() for the "Location" so I don't have a valid response (404 => Play! page with routes)
L22 to L28: I have to create a java.net.URL to only get the path (not the scheme, the host, ..) so GET() give me the valid response for the redirect

Perhaps my steps are bad. Perhaps I have to make it in a different way.
But if it's correct, I think it's a bit complicated.
Is there a method with Play! like : GETandRedirect("/path/url") ?
Or GETfromURL("http://localhost/complete/url") ?

Thanks for help.

PS: I also see there is a class : FunctionalTest.URL
But I don't know what I can do with it.

AdminCRUDTest.java

Guillaume Bort

unread,
Dec 29, 2010, 7:01:59 AM12/29/10
to play-fr...@googlegroups.com
You should use selenium tests for this kind of scenario.

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

Manuel Paccagnella

unread,
Jan 4, 2011, 6:09:14 AM1/4/11
to play-fr...@googlegroups.com
I have the same concern about this. I want to test my controllers directly without passing through the UI (that tends to be brittle) and I need to pass parameters to and check responses from the URL. But if the URL is restricted by the Secure module I can't do this because of the redirection.

Maybe I only need to refactor and move out the controllers all but the essential code so that I can test the business logic independently? I have a colleague that tends to write procedural Java code directly in the controllers. Too bad.

Guillaume Bort

unread,
Jan 5, 2011, 7:58:58 AM1/5/11
to play-fr...@googlegroups.com
I think we just need a simple helper method in the FunctionalTest
superclass here. If someone could help us and make a patch it would be
great.

Neoh59

unread,
Jan 5, 2011, 4:30:50 PM1/5/11
to play-fr...@googlegroups.com
I now use selenium tests like Guillaume said to me.

But if it can help someone, here is a patch I tried to code.
I'm a newbee with Git so perhaps it's not perfect ... but Play! ant task works.
And perhaps my code is not perfect too.
Like I said : "if it can help" ... to do a better patch. :)



functional-test-with-redirect.patch

Guillaume Bort

unread,
Jan 5, 2011, 5:26:44 PM1/5/11
to play-fr...@googlegroups.com
I would prefer a pull request on github. Otherwise, please open a bug
and attach this patch. Otherwise it will probably be lost here....

Neoh59

unread,
Jan 6, 2011, 4:03:53 PM1/6/11
to play-fr...@googlegroups.com
Sorry for the pull request on github, I just add a ticket with this patch : #534

Reply all
Reply to author
Forward
0 new messages