Testing custom constraints in Grails App

Posted by WaZ on Stack Overflow See other posts from Stack Overflow or by WaZ
Published on 2010-04-07T08:18:35Z Indexed on 2010/04/07 8:23 UTC
Read the original article Hit count: 249

Filed under:

Hi there,

I have the following as my unit test:

void testCreateDealer() {
      mockForConstraintsTests(Dealer)
      def _dealer= new Dealer( dealerName:"ABC",
                            Email:"[email protected]",
                            HeadOffice:"",
                            isBranch:false)
       assertFalse _dealer.validate()

    }

But when I run the test I get the following error:

No signature of method: static com.myCompany.Dealer.findByDealerNameIlike() is applicable for argument types: (java.lang.String) values: [ABC]

I use some custom constraints in my domain class. How Can I test this?

 static constraints = {
     dealerName(blank:false, validator:
            { val, obj ->
                      def similarDealer = Dealer.findByDealerNameIlike(val)
                      return !similarDealer || (obj.id == similarDealer.id)
            }
     )

© Stack Overflow or respective owner

Related posts about grails