-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17451 from gsmet/1.13.5-backports-3
1.13.5 backports 3
- Loading branch information
Showing
5 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
95 changes: 95 additions & 0 deletions
95
...nt/src/test/java/io/quarkus/hibernate/validator/test/ContainerElementConstraintsTest.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,95 @@ | ||
package io.quarkus.hibernate.validator.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
import javax.validation.ValidatorFactory; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ContainerElementConstraintsTest { | ||
|
||
@Inject | ||
ValidatorFactory validatorFactory; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap | ||
.create(JavaArchive.class).addClasses(TestBean.class)); | ||
|
||
@Test | ||
public void testContainerElementConstraint() { | ||
assertThat(validatorFactory.getValidator().validate(new TestBean())).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testNestedContainerElementConstraint() { | ||
assertThat(validatorFactory.getValidator().validate(new NestedTestBean())).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testMethodParameterContainerElementConstraint() throws NoSuchMethodException, SecurityException { | ||
Map<String, List<String>> invalidMap = new HashMap<>(); | ||
invalidMap.put("key", Collections.singletonList("")); | ||
|
||
assertThat(validatorFactory.getValidator().forExecutables().validateParameters(new MethodParameterTestBean(), | ||
MethodParameterTestBean.class.getMethod("test", Map.class), new Object[] { invalidMap })).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testMethodReturnValueContainerElementConstraint() throws NoSuchMethodException, SecurityException { | ||
Map<String, List<String>> invalidMap = new HashMap<>(); | ||
invalidMap.put("key", Collections.singletonList("")); | ||
|
||
assertThat(validatorFactory.getValidator().forExecutables().validateReturnValue(new MethodReturnValueTestBean(), | ||
MethodReturnValueTestBean.class.getMethod("test"), invalidMap)).hasSize(1); | ||
} | ||
|
||
static class TestBean { | ||
|
||
public Map<String, @NotBlank String> constrainedMap; | ||
|
||
public TestBean() { | ||
Map<String, String> invalidMap = new HashMap<>(); | ||
invalidMap.put("key", ""); | ||
|
||
this.constrainedMap = invalidMap; | ||
} | ||
} | ||
|
||
static class NestedTestBean { | ||
|
||
public Map<String, List<@NotBlank String>> constrainedMap; | ||
|
||
public NestedTestBean() { | ||
Map<String, List<String>> invalidMap = new HashMap<>(); | ||
invalidMap.put("key", Collections.singletonList("")); | ||
|
||
this.constrainedMap = invalidMap; | ||
} | ||
} | ||
|
||
static class MethodParameterTestBean { | ||
|
||
public void test(Map<String, List<@NotBlank String>> constrainedMap) { | ||
// do nothing | ||
} | ||
} | ||
|
||
static class MethodReturnValueTestBean { | ||
|
||
public Map<String, List<@NotBlank String>> test() { | ||
return null; | ||
} | ||
} | ||
} |
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