Quantcast

Integration test seems to ignore "allowedMethods"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Integration test seems to ignore "allowedMethods"

nisabek
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Integration test seems to ignore "allowedMethods"

Sam Corbett
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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Integration test seems to ignore "allowedMethods"

nisabek
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
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





If you reply to this email, your message will be added to the discussion below:
http://grails.1312388.n4.nabble.com/Integration-test-seems-to-ignore-allowedMethods-tp4630274p4630309.html
To unsubscribe from Integration test seems to ignore "allowedMethods", click here.
NAML

Loading...