forked from micronaut-projects/micronaut-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Validator doesn't throw UnexpectedTypeException in retry
Fixed micronaut-projects#361
- Loading branch information
Showing
7 changed files
with
311 additions
and
208 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
test-suite/src/test/java/io/micronaut/docs/validation/retry/ValidatedBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.micronaut.docs.validation.retry; | ||
|
||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.docs.validation.retry.validation.ValidInternalId; | ||
import io.micronaut.docs.validation.retry.validation.ValidatedByFactory; | ||
|
||
@Introspected | ||
public record ValidatedBean( | ||
@ValidatedByFactory | ||
String value, | ||
@ValidInternalId | ||
int internalId | ||
) { | ||
} |
26 changes: 26 additions & 0 deletions
26
test-suite/src/test/java/io/micronaut/docs/validation/retry/ValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.micronaut.docs.validation.retry; | ||
|
||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import jakarta.validation.UnexpectedTypeException; | ||
import jakarta.validation.Validator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@MicronautTest(rebuildContext = true, startApplication = false) | ||
public class ValidatorTest { | ||
|
||
@Inject | ||
Validator validator; | ||
|
||
@Test | ||
void BUG_REPRODUCTION_CASE_validateValidBean_shouldNotFail() { | ||
var bean = new ValidatedBean("foobar", 42); | ||
|
||
assertThrows(UnexpectedTypeException.class, () -> validator.validate(bean)); | ||
assertThrows(UnexpectedTypeException.class, () -> validator.validate(bean)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
test-suite/src/test/java/io/micronaut/docs/validation/retry/validation/ValidInternalId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.micronaut.docs.validation.retry.validation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Constraint(validatedBy = {}) | ||
@Target({ | ||
ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.TYPE_USE | ||
}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@NotNull | ||
@Positive | ||
@Max(Integer.MAX_VALUE) | ||
public @interface ValidInternalId { | ||
} |
20 changes: 20 additions & 0 deletions
20
...suite/src/test/java/io/micronaut/docs/validation/retry/validation/ValidatedByFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.micronaut.docs.validation.retry.validation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.constraints.Size; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Constraint(validatedBy = {}) | ||
@Target({ | ||
ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.TYPE_USE | ||
}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Size(max = 32) | ||
public @interface ValidatedByFactory { | ||
} |
17 changes: 17 additions & 0 deletions
17
test-suite/src/test/java/io/micronaut/docs/validation/retry/validation/ValidatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.micronaut.docs.validation.retry.validation; | ||
|
||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.validation.validator.constraints.ConstraintValidator; | ||
import jakarta.inject.Singleton; | ||
|
||
@Factory | ||
@Introspected | ||
public class ValidatorFactory { | ||
|
||
@Singleton | ||
ConstraintValidator<ValidatedByFactory, CharSequence> validatedByFactoryValidator() { | ||
return (ignored1, ignored2, ignored3) -> true; | ||
} | ||
|
||
} |
349 changes: 173 additions & 176 deletions
349
validation/src/main/java/io/micronaut/validation/validator/DefaultValidator.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters