Quantcast

Codecs fail in controller unit tests

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

Codecs fail in controller unit tests

barnesjd
I have added a PasswordCodec per this Grails page, and it works great while running my application.  However, when I run my tests, I get the failures below for the testSave() and testUpdate() cases.  Is there something special I should do for tests involving codecs?

| Failure:  testUpdate(ww1.domain.UserControllerTests)
|  groovy.lang.MissingMethodException: No signature of method: java.lang.String.encodeAsPassword() is applicable for argument types: () values: []
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Codecs fail in controller unit tests

Jeff Brown-3
On Tue, Feb 28, 2012 at 3:16 PM, barnesjd <[hidden email]> wrote:

> I have added a PasswordCodec per
> http://grails.org/Simple+Dynamic+Password+Codec this Grails page , and it
> works great while running my application.  However, when I run my tests, I
> get the failures below for the testSave() and testUpdate() cases.  Is there
> something special I should do for tests involving codecs?
>
> | Failure:  testUpdate(ww1.domain.UserControllerTests)
> |  groovy.lang.MissingMethodException: No signature of method:
> java.lang.String.encodeAsPassword() is applicable for argument types: ()
> values: []
>

It may depend on what version of Grails you are using and what type of
test it is.  If this is a unit test that uses GrailsUnitTestMixin you
may need to do something like this:

mockCodec(PasswordCodec)

Does that help?



jb
--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
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: Codecs fail in controller unit tests

barnesjd
Thanks for the reply, Jeff!  I should have mentioned that I am using Grails 2.0.1.  I don't see an annotation called MockCodec.  I'll google around and see if I can find exactly how I add this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Codecs fail in controller unit tests

Jeff Brown-3
On Tue, Feb 28, 2012 at 3:48 PM, barnesjd <[hidden email]> wrote:
> Thanks for the reply, Jeff!  I should have mentioned that I am using Grails
> 2.0.1.  I don't see an annotation called MockCodec.  I'll google around and
> see if I can find exactly how I add this.
>

I don't think there is an annotation called MockCodec.  There is a
method called mockCodec which you can call from your test like this…

mockCodec(PasswordCodec)

Does that make your test succeed?



jb

--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
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: Codecs fail in controller unit tests

xunitc
In reply to this post by Jeff Brown-3
Thanks a lot! Jeff Brown-3.

Before that I test the codec only in integration.

I think the guide/testing need a part and some examples about how to unit-test the Codec. :)
Xunitc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Codecs fail in controller unit tests

barnesjd
In reply to this post by Jeff Brown-3
That worked, Jeff!  Thanks for the help.  I added that call to my setup() method:

    void setup()
    {
        mockCodec(utils.PasswordCodec)
    }
Loading...