forked from hibernate/hibernate-validator
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-843 Making sure non public annotation members are accessible. Unif…
…ying handling of annotation member value handling.
- Loading branch information
1 parent
ab21ca9
commit 763feff
Showing
11 changed files
with
315 additions
and
94 deletions.
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
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
30 changes: 30 additions & 0 deletions
30
...t/java/org/hibernate/validator/test/internal/engine/packageprivateconstraint/Giraffe.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,30 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.test.internal.engine.packageprivateconstraint; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
public class Giraffe { | ||
|
||
@ValidAnimalName("Bruno") | ||
public String getName() { | ||
return "Bob"; | ||
} | ||
} | ||
|
||
|
78 changes: 78 additions & 0 deletions
78
...test/internal/engine/packageprivateconstraint/PackagePrivateConstraintValidationTest.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,78 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.test.internal.engine.packageprivateconstraint; | ||
|
||
import java.util.Set; | ||
import javax.validation.ConstraintViolation; | ||
import javax.validation.Validator; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import org.hibernate.validator.testutil.TestForIssue; | ||
import org.hibernate.validator.testutil.ValidatorUtil; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* Tests the validation of package-private constraints. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
@TestForIssue(jiraKey = "HV-843") | ||
public class PackagePrivateConstraintValidationTest { | ||
|
||
private Validator validator; | ||
|
||
@BeforeMethod | ||
public void setupValidator() { | ||
validator = ValidatorUtil.getValidator(); | ||
} | ||
|
||
@Test | ||
public void shouldValidatePackagePrivateConstraint() { | ||
Set<ConstraintViolation<Giraffe>> violations = validator.validate( new Giraffe() ); | ||
assertEquals( violations.size(), 1 ); | ||
assertEquals( | ||
violations.iterator().next().getConstraintDescriptor().getAnnotation().annotationType(), | ||
ValidAnimalName.class | ||
); | ||
} | ||
|
||
/** | ||
* Currently it's not possible to have an annotation which is declared as inner-type within a package-private | ||
* annotation type and have that inner annotation refer to that outer annotation type. | ||
* <p> | ||
* That means it is not possible to work with the conventional pattern of an inner {@code @List} annotation for | ||
* multi-valued constraints if the actual constraint type is package private. Thus the multi-value annotation is a | ||
* top-level type itself as workaround here. | ||
* <p> | ||
* This is a limitation of how proxies for annotations are generated by the JDK. | ||
*/ | ||
@Test | ||
public void shouldValidatePackagePrivateMultiValueConstraint() { | ||
Set<ConstraintViolation<PolarBear>> violations = validator.validate( new PolarBear() ); | ||
assertEquals( violations.size(), 1 ); | ||
assertEquals( | ||
violations.iterator().next().getConstraintDescriptor().getAnnotation().annotationType(), | ||
ValidAnimalName.class | ||
); | ||
} | ||
} | ||
|
||
|
||
|
33 changes: 33 additions & 0 deletions
33
...java/org/hibernate/validator/test/internal/engine/packageprivateconstraint/PolarBear.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,33 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.test.internal.engine.packageprivateconstraint; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
public class PolarBear { | ||
|
||
@ValidAnimalNameList({ | ||
@ValidAnimalName("Bruno") | ||
}) | ||
public String getName() { | ||
return "Bob"; | ||
} | ||
} | ||
|
||
|
||
|
46 changes: 46 additions & 0 deletions
46
...rg/hibernate/validator/test/internal/engine/packageprivateconstraint/ValidAnimalName.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,46 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.validator.test.internal.engine.packageprivateconstraint; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
@Constraint(validatedBy = ValidAnimalNameValidator.class) | ||
@Target({ FIELD, METHOD }) | ||
@Retention(RUNTIME) | ||
@interface ValidAnimalName { | ||
|
||
String message() default "{org.hibernate.validator.test.internal.engine.privateconstraint.ValidAnimalName.message}"; | ||
|
||
Class<?>[] groups() default { }; | ||
|
||
Class<? extends Payload>[] payload() default { }; | ||
|
||
String value(); | ||
} | ||
|
||
|
||
|
Oops, something went wrong.