File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Grails Testing problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "Grails Testing problem" Watch "Grails Testing problem" New topic
Author

Grails Testing problem

sachin burange
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
Hello guys,
I am testing the cotrollers.

Following is the scenario.

A class extends GrailsUnitTestCase class.
Following is the setup method inside it.

void setUp() {
super.setUp()
instance = controllerClass.newInstance()
assertNotNull("No instance found", instance)
String logicalName = controllerGrailsClass.logicalPropertyName
this.metaClass."get${logicalName[0].toUpperCase() + logicalName[1..-1]}" = {-> instance }
['request', 'response', 'session', 'params'].each { field ->
this.metaClass."get${field[0].toUpperCase() + field[1..-1]}" = {-> instance."${field}" }
}
['view', 'viewName', 'model'].each { field ->
this.metaClass."get${field[0].toUpperCase() + field[1..-1]}" = {-> instance.modelAndView."${field}" }
}

}


I am writing test case for render it was sucessful. but when i call redirect testcase it was throwing me follwing exception

Unable to create URL for mapping [/(*)/(*)?/(*)?] and parameters [{payGatewayParam=PayGatewayParam : 1, action=gatewayStatus}]. Parameter [controller] is required, but was not specified!

i am missing somthing in while setting up ?



Regards
Sachin
Jon Dickinson
Author
Ranch Hand

Joined: Feb 24, 2009
Posts: 45
Hi Sachin,

Have you tried using the mockController method? It looks like you are trying to mock a lot of behaviour yourself, which may be confusing the issue. If you are already extending GrailsUnitTestCase you can do the following:



When a controller is mocked in this way the arguments that your code passes to the render and redirect methods are available through the renderArgs and redirectArgs properties. You can also get access to the various scopes (request, flash, session) to check the contents.

There is of course, quite a good example of this, using controllers, domain classes and services, in Chapter 6 of my book!

Cheers,
Jon.


Jon Dickinson
Accolade Consulting
Grails 1.1 Web Application Development
sachin burange
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
Thanks dear. It get solved.
prviousely my service method was returning
redirect(action: list)
because of this error was coming then i replaced above with below

redirect(controller:"controllername",action: list)

cheers
 
 
subject: Grails Testing problem
 
Threads others viewed
Can not Populate the form on combo box change
HTTPUnit Button Clicks and javascript functions
MultiDimenaional Array sort
Help needed in ModelMBean descriptors
problem with <logic:iterate> and with onload function in javascript
IntelliJ Java IDE