|
Grails version: 2.0.0.RC3
I am trying to unit test urlmappings as explained in the documentation url mapping Specifically my code test code looks like this import myproject.AnimalController @TestFor(UrlMappings) class UrlMappingsTests{ @Test void testSomething() { assertForwardUrlMapping("/action1", controller: 'animal',action: "show") } } and the urlmappings class is class UrlMappings { static mappings = { "/$controller/$action?/$id?"{ constraints { // apply constraints here } } "/action1"(controller: "animal", action: "show") "/"(view:"/index") "500"(view:'/error') } } I get the following error: junit.framework.AssertionFailedError: Url mapping assertion for '/action1' failed, 'animal' is not a valid controller at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190) at grails.test.mixin.web.UrlMappingsUnitTestMixin.assertController(UrlMappingsUnitTestMixin.groovy:104) It calls my attention the comment made in the documentation: assertForwardUrlMapping - Asserts a URL mapping is forwarded for the given controller class (note that controller will need to be defined as a mock collaborate for this to work) Not sure how to make it work. I also looked at a couple of JIRA tickets but none really I think applied. When I look at the code for the UrlMappingsUnitTestMixin.groovy class what is failing is the call to grailsApplication.getArtefactByLogicalPropertyName(ControllerArtefactHandler.TYPE, controller). That is really as far as can take it. The whole unittesting in grails seems a bit misterious to me, in what has been loaded and what we have access to. Any help would be appreciated |
|
Add a mock annotation for your AnimalController and it should work fine
@TestFor(UrlMappings) @Mock(AnimalController) class UrlMappingsTests{ ... cheers david On Tue, Dec 13, 2011 at 3:48 PM, fiallega <[hidden email]> wrote: Grails version: 2.0.0.RC3 |
| Powered by Nabble | Edit this page |
