Quantcast

Testing constraints of embedded object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Testing constraints of embedded object

Olivier Gourment
Hi there,

I have an object that is embedded in a domain object. No table is mapped to the object, so not a real domain.
It's therefore standing in src/groovy.

Now, there are still constraints for that object.
I've tried various ways to unit test the constraints, to no avail.

The attempt below fails with a NullPointerException on grailsApplication.config (grailsApplication is null).

Can anyone shed some light on this? Is this possible or not?

Thanks,

     Olivier
 

--

import grails.test.mixin.domain.DomainClassUnitTestMixin

import grails.test.mixin.support.GrailsUnitTestMixin

@Mixin([GrailsUnitTestMixin, DomainClassUnitTestMixin])

public class AddressTest {

  public void testConstraint() {

    mockForConstraintsTests(Address)

  }

}

--

import grails.validation.Validateable

@Validateable

class Address {

  int number

  String street

  static constraints = {

    number(min: 0)

    street(blank: false)

  }

}


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Testing constraints of embedded object

Olivier Gourment

I tried a few more things.. Here are the attempts and reasons for failure:

public void setUp() {

  // nothing: ServletContext must not be null on validate()

  //mockForConstraintsTests(Address) - NPE on grailsApplication.config

  //mockCommandObject(Address) - unknown method

  //MockUtils.prepareForConstraintsTests(Address) - validation succeeds when it should fail

  //MockUtils.mockCommandObject(Address) - validation succeeds when it should fail

}



On Sun, May 6, 2012 at 12:53 PM, Olivier Gourment <[hidden email]> wrote:
Hi there,

I have an object that is embedded in a domain object. No table is mapped to the object, so not a real domain.
It's therefore standing in src/groovy.

Now, there are still constraints for that object.
I've tried various ways to unit test the constraints, to no avail.

The attempt below fails with a NullPointerException on grailsApplication.config (grailsApplication is null).

Can anyone shed some light on this? Is this possible or not?

Thanks,

     Olivier
 

--

import grails.test.mixin.domain.DomainClassUnitTestMixin

import grails.test.mixin.support.GrailsUnitTestMixin

@Mixin([GrailsUnitTestMixin, DomainClassUnitTestMixin])

public class AddressTest {

  public void testConstraint() {

    mockForConstraintsTests(Address)

  }

}

--

import grails.validation.Validateable

@Validateable

class Address {

  int number

  String street

  static constraints = {

    number(min: 0)

    street(blank: false)

  }

}





--
!new cell/nouveau cellulaire! 514 692 2525


Loading...