You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I’m trying to write some tests using FixtureMonkey, and I’ve encountered an issue. My DTOs have custom validators, and I’m using JakartaValidationPlugin with FixtureMonkey.
The issue arises because some of my validators depend on a repository for validation logic. For example, I have a custom UniqueEmailValidator.
When I run the tests, I get the following error:
HV000064: Unable to instantiate ConstraintValidator: my.awesome.package.validation.UniqueEmailValidator.
jakarta.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: my.awesome.package.validation.UniqueEmailValidator.
at org.hibernate.validator.internal.util.privilegedactions.NewInstance.run(NewInstance.java:44)
my.awesome.package.validation.UniqueEmailValidator.<init>()
java.lang.NoSuchMethodException: my.awesome.package.validation.UniqueEmailValidator.<init>()
What I’ve Learned So Far
I understand that this error occurs because FixtureMonkey invokes Jakarta Validation when generating the DTOs, and the validator’s constructor requires a UserRepository (via @Autowired), which isn’t initialized in this context.
My Goal
I’d like to disable or bypass specific validations (e.g., UniqueEmailValidator) when generating data with FixtureMonkey. I’m looking for the best way to achieve this while keeping the rest of the validation logic intact.
What’s the recommended approach to handle this situation? Should I configure FixtureMonkey, mock the validator, or is there another solution?
The text was updated successfully, but these errors were encountered:
In your case, I recommend using the arbitraryValidator option in FixtureMonkeyBuilder to change the default ArbitraryValidator used for validation.
By default, if you are using the JakartaValidationPlugin, the JakartaArbitraryValidator will use Validation.buildDefaultValidatorFactory() to find the validator. You can make your custom validator that excludes specific validations (UniqueEmailValidator).
OR You can use the validOnly API in ArbitraryBuilder. If you set validOnly to false, it will disable validation.
Hi, I’m trying to write some tests using FixtureMonkey, and I’ve encountered an issue. My DTOs have custom validators, and I’m using
JakartaValidationPlugin
with FixtureMonkey.Here’s a simplified version of my test setup:
The issue arises because some of my validators depend on a repository for validation logic. For example, I have a custom
UniqueEmailValidator
.When I run the tests, I get the following error:
What I’ve Learned So Far
I understand that this error occurs because FixtureMonkey invokes Jakarta Validation when generating the DTOs, and the validator’s constructor requires a
UserRepository
(via @Autowired), which isn’t initialized in this context.My Goal
I’d like to disable or bypass specific validations (e.g.,
UniqueEmailValidator
) when generating data with FixtureMonkey. I’m looking for the best way to achieve this while keeping the rest of the validation logic intact.What’s the recommended approach to handle this situation? Should I configure FixtureMonkey, mock the validator, or is there another solution?
The text was updated successfully, but these errors were encountered: