|
Hi all,
Before rising a JIRA issue I would like to understand whether someone has come across a similar issue. I have a simple controller with 1 method that is declared to accept only POST through "allowedMethods" static property class UserController { static allowedMethods = [registerUser: 'POST'] def registerUser() { String userId = request.JSON?.userId def result = [resultCode:"OK"] render result as JSON } } I want to have proper integration tests for this method (not unit, so that the whole grails env is invoked) this works perfectly fine class UserControllerTests extends GroovyTestCase{ @Test void testRegisterUser() { String userId = "122432" def controller = new UserController() controller.request.contentType = "application/json" controller.request.method = 'POST' controller.request.content = "{userId:$userId}".getBytes() controller.registerUser() def result = controller.response.contentAsString String expectedResult = "{\"resultCode\":\"OK\"}" assertEquals("The response is generated wrong", expectedResult, result) } } But I assumed that changed the request.method to "GET" will fail the test, and I will be able to test the restriction. But it didn't. Have you been seeing this issue or am I doing smth wrong? Thanks in advance. Regards, Nune |
|
You're not doing anything wrong, Grails doesn't respect the
allowedMethods map in tests. The JIRA for it is here: http://jira.grails.org/browse/GRAILS-8426 On 17/06/2012 17:05, nisabek wrote: > Hi all, > > Before rising a JIRA issue I would like to understand whether someone has > come across a similar issue. > > I have a simple controller with 1 method that is declared to accept only > POST through "allowedMethods" static property > > class UserController { > > static allowedMethods = [registerUser: 'POST'] > > def registerUser() { > String userId = request.JSON?.userId > def result = [resultCode:"OK"] > render result as JSON > } > } > > > I want to have proper integration tests for this method (not unit, so that > the whole grails env is invoked) > > this works perfectly fine > > class UserControllerTests extends GroovyTestCase{ > > @Test > void testRegisterUser() { > > String userId = "122432" > def controller = new UserController() > controller.request.contentType = "application/json" > controller.request.method = 'POST' > controller.request.content = "{userId:$userId}".getBytes() > > controller.registerUser() > def result = controller.response.contentAsString > String expectedResult = "{\"resultCode\":\"OK\"}" > assertEquals("The response is generated wrong", expectedResult, > result) > > } > } > > But I assumed that changed the request.method to "GET" will fail the test, > and I will be able to test the restriction. But it didn't. > > Have you been seeing this issue or am I doing smth wrong? > > Thanks in advance. > > Regards, > Nune > > -- > View this message in context: http://grails.1312388.n4.nabble.com/Integration-test-seems-to-ignore-allowedMethods-tp4630274.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Thanks for information!
On 18 June 2012 18:08, Sam Corbett [via Grails] <[hidden email]> wrote: You're not doing anything wrong, Grails doesn't respect the |
| Powered by Nabble | Edit this page |
