grails 2.0, testing controller with withForm{}.invalid{} notation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

grails 2.0, testing controller with withForm{}.invalid{} notation

netbrain
I ran into this problem when trying to write a unit test on a controller which is using withForm{} to handle duplicate form submissions.

| Error Compilation error compiling [unit] tests: startup failed:
OauthControllerTests.groovy: 26: unable to resolve class org.codehaus.groovy.grails.web.servlet.mvc.SynchronizerToken
 @ line 26, column 1.
   import org.codehaus.groovy.grails.web.servlet.mvc.SynchronizerToken
   ^

1 error
 (Use --stacktrace to see the full trace)


The test in question.

    void testAuthorizeApplicationEndpointWithValidParameters(){
        def token = SynchronizerToken.store(session)
        params[SynchronizerToken.KEY] = token.currentToken.toString()
        controller.authorizeApplication()
        assert response.status == 200
    }

Anyways, why isn't SynchronizerToken available on my classpath? I recently upgraded from grails 1.3.7 to 2.0, Could that have anything to do with it?

Any help is appreciated.
-Kim
Reply | Threaded
Open this post in threaded view
|

Re: grails 2.0, testing controller with withForm{}.invalid{} notation

netbrain
For anyone else wondering.. i found this grails issue


and then i solved it by doing this:

        def token = SynchronizerTokensHolder.store(session)
        params[SynchronizerTokensHolder.TOKEN_URI] = '/oauth/authorizeApplication'
        params[SynchronizerTokensHolder.TOKEN_KEY] = token.generateToken(params[SynchronizerTokensHolder.TOKEN_URI])
        controller.authorizeApplication()

-Kim

On Sat, Jan 21, 2012 at 3:40 PM, Kim Eik <[hidden email]> wrote:
I ran into this problem when trying to write a unit test on a controller which is using withForm{} to handle duplicate form submissions.

| Error Compilation error compiling [unit] tests: startup failed:
OauthControllerTests.groovy: 26: unable to resolve class org.codehaus.groovy.grails.web.servlet.mvc.SynchronizerToken
 @ line 26, column 1.
   import org.codehaus.groovy.grails.web.servlet.mvc.SynchronizerToken
   ^

1 error
 (Use --stacktrace to see the full trace)


The test in question.

    void testAuthorizeApplicationEndpointWithValidParameters(){
        def token = SynchronizerToken.store(session)
        params[SynchronizerToken.KEY] = token.currentToken.toString()
        controller.authorizeApplication()
        assert response.status == 200
    }

Anyways, why isn't SynchronizerToken available on my classpath? I recently upgraded from grails 1.3.7 to 2.0, Could that have anything to do with it?

Any help is appreciated.
-Kim