You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by changeOver <sr...@gmail.com> on 2013/09/06 17:27:05 UTC
How to mock or auto inject shiro's accessControl() method in grails
unit test case
I have a problem in writing grails unit test case for the controller with
filter enabled. When the test case run without filters then it is working
fine, if it runs withFilters then it is failing for accessControl() method
not found in the controller. I dont know how to make Shiro's api to be
visible while running the test case.I referred shiro unit test case link
http://shiro.apache.org/testing.html <http://shiro.apache.org/testing.html>
but I couldn't get any info regarding accessControl().I have given sample
code how the my classes and test case looks like
MyController.groovy
-------------------
def create() {
// getting request parameters and validation
String emailId = params.emailId
def ret = folderService.createUser(emailId)
return ret
}
MyControllerFilters.groovy
--------------------------
def filters = {
loginCheck(controller: 'user') {
before = {
//do some business checks
// Access control by convention.
accessControl() // This is a dynamic method injected by
ShiroGrailsPlugin to FilterConfig, but this is not visible during the test
case.
}
}
MyControllerTests.groovy
-------------------------
@TestFor(MyController)
@Mock(MyControllerFilters)
class MyControllerTests {
@Before
void setup() {
// initializing some variables
}
void testCreateUserWithFilter() {
request.accessAllowed = true
withFilters(action:"create") {
controller.create()
}
assert response.message == "success"
}
}
--
View this message in context: http://shiro-user.582556.n2.nabble.com/How-to-mock-or-auto-inject-shiro-s-accessControl-method-in-grails-unit-test-case-tp7579114.html
Sent from the Shiro User mailing list archive at Nabble.com.