|
|
Hi all,
i have defined a filter based on a URI pattern. It seems that unit testing of filters based on URI is not working for me.
Filter looks like:
def filters = { secureFilter(uri: '/sec/**') { after = { map -> map << [sec: 'sec'] } } }
Unit test looks like:
void testSecureFilter() { def model withFilters(uri: '/sec/**') { model = controller.doAnything() } assert model.sec == 'sec' }
Anyone knows how to handle this?
thx in advance!
Elmar
|
|
Hi Elmar,
you need to set the requestURI of the mocked HttpServletRequest and the filter should be called (at least this is the case with Grails 2.0):
void testSecureFilter() {
GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/dashboards/add'
On Friday, January 27, 2012 at 12:21 PM, Elmar Kretzer wrote:
no solution yet.
and while debugging the test i saw the filter was actually set. but it did not get called. even if i call secureFilter with controller and action ( which is mapped to the corresponding URI) there is no result.
Am 27.01.2012 um 12:07 schrieb lsx:
Hi, I have the same question.
Did you find a solution?
I think maybe the docs need to include this part.
-- Sent from the Grails - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
|
|
Hi Andre,
thx for your fast response. I added the request URI, but its still not working:
Do you see any misconfiguration in the unit test? Is there still something missing?
@TestFor(SecureController) @Mock(SecureFilters) class NavigationFiltersTest {
void testSecureFilter() { def model GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/sec/test' withFilters(controller: 'secure', action: 'doAnything') { model = controller.doAnything() } assert model.sec == 'sec' } void testSecureFilter2() { def model GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/sec/test' withFilters(uri: '/sec/**') { model = controller.doAnything() } assert model.sec == 'sec' } }
With SecureFilters:
def filters = { secureFilter(uri: '/sec/**') { after = { map -> map << [sec: 'sec'] } } }
Elmar
Am 27.01.2012 um 12:28 schrieb Andre Steingress:
Hi Elmar,
you need to set the requestURI of the mocked HttpServletRequest and the filter should be called (at least this is the case with Grails 2.0):
void testSecureFilter() {
GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/dashboards/add'
On Friday, January 27, 2012 at 12:21 PM, Elmar Kretzer wrote:
no solution yet.
and while debugging the test i saw the filter was actually set. but it did not get called. even if i call secureFilter with controller and action ( which is mapped to the corresponding URI) there is no result.
Am 27.01.2012 um 12:07 schrieb lsx:
Hi, I have the same question.
Did you find a solution?
I think maybe the docs need to include this part.
-- Sent from the Grails - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
|
|
Elmar,
testSecureFilter2 doesn't work because uri is not supported in the withFilters parameter map.
testSecureFilter should work when calling it with an empty map
withFilters([:]) { ... }
that way only the requestURI is taken into account afaik (right know I do not have access to the source...)
Cheers, Andre
Hi Andre,
thx for your fast response.
I added the request URI, but its still not working:
Do you see any misconfiguration in the unit test? Is there still something missing?
@TestFor(SecureController) @Mock(SecureFilters) class NavigationFiltersTest {
void testSecureFilter() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(controller: 'secure', action: 'doAnything') {
model = controller.doAnything() } assert model.sec == 'sec'
} void testSecureFilter2() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(uri: '/sec/**') {
model = controller.doAnything() } assert model.sec == 'sec'
} }
With SecureFilters:
def filters = {
secureFilter(uri: '/sec/**') {
after = { map ->
map << [sec: 'sec']
}
} }
Elmar
Am 27.01.2012 um 12:28 schrieb Andre Steingress:
Hi Elmar,
you need to set the requestURI of the mocked HttpServletRequest and the filter should be called (at least this is the case with Grails 2.0):
void testSecureFilter() {
GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/dashboards/add'
On Friday, January 27, 2012 at 12:21 PM, Elmar Kretzer wrote:
no solution yet.
and while debugging the test i saw the filter was actually set. but it did not get called. even if i call secureFilter with controller and action ( which is mapped to the corresponding URI) there is no result.
Am 27.01.2012 um 12:07 schrieb lsx:
Hi, I have the same question.
Did you find a solution?
I think maybe the docs need to include this part.
--
Sent from the Grails - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
|
|
Hi Andre,
hm - its not working either. The model only contains the result from the controller. (in run-app the filter is working fine for the same controller)
I have to sleep on it. If its not working next week - i will try it with a fresh grails app. Then i will provide it on git - and if the error remains - i will add a feature request in jira.
Again - thx for your help Andre.
void testSecureFilter() { def model GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/sec/test' withFilters([:]) { model = controller.doAnything() } assert model.sec == 'sec' }
Am 27.01.2012 um 14:39 schrieb Andre Steingress: Elmar,
testSecureFilter2 doesn't work because uri is not supported in the withFilters parameter map.
testSecureFilter should work when calling it with an empty map
withFilters([:]) { ... }
that way only the requestURI is taken into account afaik (right know I do not have access to the source...)
Cheers, Andre
Hi Andre,
thx for your fast response.
I added the request URI, but its still not working:
Do you see any misconfiguration in the unit test? Is there still something missing?
@TestFor(SecureController) @Mock(SecureFilters) class NavigationFiltersTest {
void testSecureFilter() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(controller: 'secure', action: 'doAnything') {
model = controller.doAnything() } assert model.sec == 'sec'
} void testSecureFilter2() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(uri: '/sec/**') {
model = controller.doAnything() } assert model.sec == 'sec'
} }
With SecureFilters:
def filters = {
secureFilter(uri: '/sec/**') {
after = { map ->
map << [sec: 'sec']
}
} }
Elmar
Am 27.01.2012 um 12:28 schrieb Andre Steingress:
Hi Elmar,
you need to set the requestURI of the mocked HttpServletRequest and the filter should be called (at least this is the case with Grails 2.0):
void testSecureFilter() {
GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/dashboards/add'
On Friday, January 27, 2012 at 12:21 PM, Elmar Kretzer wrote:
no solution yet.
and while debugging the test i saw the filter was actually set. but it did not get called. even if i call secureFilter with controller and action ( which is mapped to the corresponding URI) there is no result.
Am 27.01.2012 um 12:07 schrieb lsx:
Hi, I have the same question.
Did you find a solution?
I think maybe the docs need to include this part.
--
Sent from the Grails - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
|
|
I created a test project too - what does the corresponding URL mapping look like?
Hi Andre,
hm - its not working either. The model only contains the result from the controller. (in run-app the filter is working fine for the same controller)
I have to sleep on it. If its not working next week - i will try it with a fresh grails app. Then i will provide it on git - and if the error remains - i will add a feature request in jira.
Again - thx for your help Andre.
void testSecureFilter() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters([:]) { model = controller.doAnything()
} assert model.sec == 'sec' }
Am 27.01.2012 um 14:39 schrieb Andre Steingress: Elmar,
testSecureFilter2 doesn't work because uri is not supported in the withFilters parameter map.
testSecureFilter should work when calling it with an empty map
withFilters([:]) { ... }
that way only the requestURI is taken into account afaik (right know I do not have access to the source...)
Cheers, Andre
Hi Andre,
thx for your fast response.
I added the request URI, but its still not working:
Do you see any misconfiguration in the unit test? Is there still something missing?
@TestFor(SecureController) @Mock(SecureFilters) class NavigationFiltersTest {
void testSecureFilter() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(controller: 'secure', action: 'doAnything') {
model = controller.doAnything() } assert model.sec == 'sec'
} void testSecureFilter2() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(uri: '/sec/**') {
model = controller.doAnything() } assert model.sec == 'sec'
} }
With SecureFilters:
def filters = {
secureFilter(uri: '/sec/**') {
after = { map ->
map << [sec: 'sec']
}
} }
Elmar
Am 27.01.2012 um 12:28 schrieb Andre Steingress:
Hi Elmar,
you need to set the requestURI of the mocked HttpServletRequest and the filter should be called (at least this is the case with Grails 2.0):
void testSecureFilter() {
GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/dashboards/add'
On Friday, January 27, 2012 at 12:21 PM, Elmar Kretzer wrote:
no solution yet.
and while debugging the test i saw the filter was actually set. but it did not get called. even if i call secureFilter with controller and action ( which is mapped to the corresponding URI) there is no result.
Am 27.01.2012 um 12:07 schrieb lsx:
Hi, I have the same question.
Did you find a solution?
I think maybe the docs need to include this part.
--
Sent from the Grails - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
|
|
i put the example on github.
while run-app, the page shows both attributes (controller and filter) while test-app the model only contains the controller attribute
thx elmar
Am 28.01.2012 um 21:50 schrieb Andre Steingress: I created a test project too - what does the corresponding URL mapping look like?
Hi Andre,
hm - its not working either. The model only contains the result from the controller. (in run-app the filter is working fine for the same controller)
I have to sleep on it. If its not working next week - i will try it with a fresh grails app. Then i will provide it on git - and if the error remains - i will add a feature request in jira.
Again - thx for your help Andre.
void testSecureFilter() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters([:]) { model = controller.doAnything()
} assert model.sec == 'sec' }
Am 27.01.2012 um 14:39 schrieb Andre Steingress: Elmar,
testSecureFilter2 doesn't work because uri is not supported in the withFilters parameter map.
testSecureFilter should work when calling it with an empty map
withFilters([:]) { ... }
that way only the requestURI is taken into account afaik (right know I do not have access to the source...)
Cheers, Andre
Hi Andre,
thx for your fast response.
I added the request URI, but its still not working:
Do you see any misconfiguration in the unit test? Is there still something missing?
@TestFor(SecureController) @Mock(SecureFilters) class NavigationFiltersTest {
void testSecureFilter() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(controller: 'secure', action: 'doAnything') {
model = controller.doAnything() } assert model.sec == 'sec'
} void testSecureFilter2() {
def model GrailsMockHttpServletRequest mockHttpServletRequest = request
mockHttpServletRequest.requestURI = '/sec/test' withFilters(uri: '/sec/**') {
model = controller.doAnything() } assert model.sec == 'sec'
} }
With SecureFilters:
def filters = {
secureFilter(uri: '/sec/**') {
after = { map ->
map << [sec: 'sec']
}
} }
Elmar
Am 27.01.2012 um 12:28 schrieb Andre Steingress:
Hi Elmar,
you need to set the requestURI of the mocked HttpServletRequest and the filter should be called (at least this is the case with Grails 2.0):
void testSecureFilter() {
GrailsMockHttpServletRequest mockHttpServletRequest = request mockHttpServletRequest.requestURI = '/dashboards/add'
On Friday, January 27, 2012 at 12:21 PM, Elmar Kretzer wrote:
no solution yet.
and while debugging the test i saw the filter was actually set. but it did not get called. even if i call secureFilter with controller and action ( which is mapped to the corresponding URI) there is no result.
Am 27.01.2012 um 12:07 schrieb lsx:
Hi, I have the same question.
Did you find a solution?
I think maybe the docs need to include this part.
--
Sent from the Grails - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
|
|
I am trying to get similar unit tests to work. what is the solution?
|
|