Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about JakartaValidationPlugin and validation logic for creating fixture objects #1118

Open
doljae opened this issue Dec 11, 2024 · 3 comments
Labels
question Further information is requested

Comments

@doljae
Copy link
Contributor

doljae commented Dec 11, 2024

Describe your question

My understanding is that the JakartaValidationPlugin reads the settings in the validation annotation and creates a fixture object with values that match the settings.

This is not exact, but the way I understand the above logic to work is as follows.

  1. Create a fixture object
  2. Validate that the field in the fixture object has a value assigned to it that meets the validation annotation conditions
  3. Return the Fixture object if validation succeeds for all fields, otherwise recreate the Fixture object

It seems to be repeating the process of creating an object by first filling the fields with random values and then validating that the object is valid, rather than filling the fields with the validated values from the beginning.

So, I think if we can, it would be better to create the object when all the fields of the object have values that satisfy the conditions.

Of course, since Fixture Monkey uses the logic of the hibernate validator, in some ways I think creating an object and running the validation logic is a natural and much more common implementation.

I'm curious about the design history or opinions of the maintainer on this.

@doljae doljae added the question Further information is requested label Dec 11, 2024
@seongahjo
Copy link
Contributor

seongahjo commented Dec 11, 2024

@doljae
Hello, I think the bug causes the misunderstanding.

Fixture Monkey works as follows.

It seems to be repeating the process of creating an object by first filling the fields with random values and then validating that the object is valid, rather than filling the fields with the validated values from the beginning.

Fixture Monkey has two logical flows to satisfy the validation.

  1. Repeat to generate a value within each property that satisfies the condition constraints given by the validation annotation.
  2. Repeat to generate an instance until validated by the validator(ex, Hibernate Validator).

For better understanding, you can check the classes below.

  • JakartaValidationConstraintGenerator,
  • JqwikJavaArbitraryResolver

Thank you.

@doljae
Copy link
Contributor Author

doljae commented Dec 12, 2024

Thanks for your detailed explanation.

Which jqwik-related classes actually generate values please?

@seongahjo
Copy link
Contributor

@doljae

Which jqwik-related classes actually generate values please?

I didn't understand it properly. Can you elaborate on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants