You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by "Nguyen, Olivier" <Ol...@am.sony.com> on 2012/09/06 18:35:38 UTC

Unit testing grails controllers with Shiro

Hi all,

I am trying to write the unit test of a controller's method that uses Shiro.

I followed the instructions at: http://shiro.apache.org/testing.html

I am using Spock to write my tests.

Here is my setup:

I have AbstractShiroTest that extends the Spock Specification class.

My AccountsControllerSpec extends AbstractShiroTest.

@TestFor(AccountsController)
class AccountsControllerSpec extends BaseUnitSpec {
        def 'index'() {
                setup:
                Subject subject = mockFor(Subject)
                setSubject(subject)

                //etc ...
        }
}

I get the following error: Cannot cast object 'grails.test.GrailsMock@429a849' with class 'grails.test.GrailsMock' to class 'org.apache.shiro.subject.Subject'

I want to mock the subject so I can mock methods like isPermitted or isAuthenticated.

Thanks in advance!

Re: Unit testing grails controllers with Shiro

Posted by changeOver <sr...@gmail.com>.
Hi
Did you resolve the problem?
I also have similar kind of question below is the link. Any inputs would be
great!!!

http://shiro-user.582556.n2.nabble.com/How-to-mock-or-auto-inject-shiro-s-accessControl-method-in-grails-unit-test-case-td7579114.html
<http://shiro-user.582556.n2.nabble.com/How-to-mock-or-auto-inject-shiro-s-accessControl-method-in-grails-unit-test-case-td7579114.html>  

Thanks



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Unit-testing-grails-controllers-with-Shiro-tp7577784p7579115.html
Sent from the Shiro User mailing list archive at Nabble.com.