Grails

New-style unit test fails for domain class with inherited constraints

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Incomplete
  • Affects Version/s: 2.0.1
  • Fix Version/s: None
  • Component/s: Testing
  • Labels:
    None
  • Testcase included:
    yes

Description

Given a POGO base class that expresses constraints (e.g. it is the parent of both a domain and @Validateable class):

src/groovy/bug/Parent.groovy
package bug

class Parent {
    String lastName

    static constraints = {
        lastName(nullable: false)
    }
}

And a domain class that extends from it:

domain/bug/Child.groovy
package bug

class Child extends Parent {
    String firstName

    static constraints = {
        firstName(nullable: false)
    }
}

A unit test that uses the new '@TestFor(Child)' style fails with the following exception:

Mapped identifier [id] for class [bug.Parent] is not a valid property
org.grails.datastore.mapping.model.IllegalMappingException: Mapped identifier [id] for class [bug.Parent] is not a valid property
	at org.grails.datastore.mapping.model.config.GormMappingConfigurationStrategy.getIdentity(GormMappingConfigurationStrategy.java:740)
	at org.grails.datastore.mapping.model.AbstractPersistentEntity.resolveIdentifier(AbstractPersistentEntity.java:117)
	at org.grails.datastore.mapping.model.AbstractPersistentEntity.initialize(AbstractPersistentEntity.java:83)
	at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntityInternal(AbstractMappingContext.java:150)
	at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:135)
	at org.grails.datastore.mapping.model.AbstractPersistentEntity.initialize(AbstractPersistentEntity.java:104)
	at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntityInternal(AbstractMappingContext.java:150)
	at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:135)
	at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:132)
	at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:128)

The old-style unit test passes.

Activity

Hide
Graeme Rocher added a comment -

This isn't really related to the inherited constraints. The reason it fails is because the mocking currently only works on domain classes which all have an 'id' property. Your classes don't have this property hence the error.

If you want to create a separate feature request for enabling mocking of non-domain classes that have constraints, then by all means do so.

Show
Graeme Rocher added a comment - This isn't really related to the inherited constraints. The reason it fails is because the mocking currently only works on domain classes which all have an 'id' property. Your classes don't have this property hence the error. If you want to create a separate feature request for enabling mocking of non-domain classes that have constraints, then by all means do so.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: