aspose file tools*
The moose likes Groovy and the fly likes Grails in action: MissingMethodException when creating one to one Integration test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Grails in action: MissingMethodException when creating one to one Integration test" Watch "Grails in action: MissingMethodException when creating one to one Integration test" New topic
Author

Grails in action: MissingMethodException when creating one to one Integration test

Dinesh Arora
Greenhorn

Joined: Apr 18, 2007
Posts: 21
I don't know how many times this question has been asked but no one seems to answer satisfactorily.
I am following the Grails in Action book.

I have tried everything but cannot get this working. Seems like every new user is struggling with this issue. Grails team should post a list of common issue and solutions.

I am creating a business domain class and an address domain. Every business has one address and I am trying to create a integration test and however it does not work.

I created Integration test but when I run it I get this exception. Here is the code

class Business {


static hasOne = [address:Address];

String name;
String description;
Business business;



static constraints = {
name(size:3..100,nullable:false);
address(nullable:true);
}

static mapping = { address lazy:false }
}


class Address {
Business business;

String addressLine1;
String addressLine2;
String city;
String state;
String zipCode;
String email;
String phone;
String homePage;


static constraints = {
// zipCode(size:1..5,nullable:false);

}
}



Integration Test:

void saveCascadeAddess() {
def address = new Address(addressLine1: 'Line1', addressLine2: 'line 2',city:'city1');
def business = new Business(name:'b_name1', description:'desc1');
business.addToAddress(address);
assertNotNull business.save();

def checkBusiness = Business.get(business.id);
assertEquals 'b_name1', checkBusiness.name;

def checkAddress = checkBusiness.address;
assertEquals 'Line1', checkAddress.addressLine1;
}

Result - The test fails.

I have tried running this code in grails console as well but I get the MethodMissingException.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You should read the docs on the hasOne. There is no addTo method created for a hasOne. That's why you're getting that exception.


GenRocket - Experts at Building Test Data
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Grails in action: MissingMethodException when creating one to one Integration test