0

I have a problem migrating my old unit tests from grails 2.5.4 to grails 3.3

I have a lot of commands using shared preferences. An example, the UserCommand inside de UserController:

class UserCommand implements Validateable {
    String firstName

    static constraints = {
        firstName shared: 'nonNullableString'
    }
}

In the application.groovy I have defined the constraint this way:

grails.gorm.default.constraints = {
    nonNullableString(blank: false, maxSize: 255)
}

Also I have the User domain defined as:

class User {
    String firstName

    static constraints = {
        firstName shared: 'nonNullableString'
    }
}

Writing a test I do:

User user = new User()
user.validate() 

it works as expected. But when I do this:

UserCommand command = new UserCommand()
command.validate()

It throws an Exception.

`grails.gorm.validation.exceptions.ValidationConfigurationException: Property [User.firstName] references shared constraint [nonNullableString:null], which doesn't exist!`

I thought I made a mistake in the application.groovy file, but shared constraints works for the domains..

Here is a sample project with the same problem: https://github.com/almejo/commandtest

Any thoughts?

Alejandro Vera
  • 377
  • 2
  • 12

0 Answers0