grails.gorm.tests.ConstraintsSpec.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grace-datastore-gorm-tck Show documentation
Show all versions of grace-datastore-gorm-tck Show documentation
Grace Data : Grace Datastore Gorm Tck
package grails.gorm.tests
import grails.persistence.Entity
class ConstraintsSpec extends GormDatastoreSpec {
void "Test constraints with static default values"() {
given: "A Test class with static constraint values"
def ce = new ConstrainedEntity(num: 1000, str: "ABC")
when: "saved is called"
ce.save()
then:
!ce.hasErrors()
}
@Override
List getDomainClasses() {
[ConstrainedEntity]
}
}
@SuppressWarnings(["ClashingTraitMethods", "UnnecessaryQualifiedReference"])
@Entity
class ConstrainedEntity implements Serializable {
static final int MAX_VALUE = 1000
static final List ALLOWABLE_VALUES = ['ABC','DEF','GHI']
Long id
Integer num
String str
static constraints = {
num(maxSize: ConstrainedEntity.MAX_VALUE)
str validator: { val, obj ->
if (val != null && !ConstrainedEntity.ALLOWABLE_VALUES.contains(val)) {
return ['not.valid']
}
}
}
}