Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dinesh Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic