Author: hardy.ferentschik
Date: 2009-06-21 05:36:16 -0400 (Sun, 21 Jun 2009)
New Revision: 16844
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/customconstraint/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java
Log:
Updated and mapped the tests for default group re-definition
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-21
08:39:29 UTC (rev 16843)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-06-21
09:36:16 UTC (rev 16844)
@@ -99,11 +99,13 @@
}
@Test
+ @SpecAssertion(section = "4.3.2", id = "b")
public void testCustomMessageInterpolatorViaConfiguration() {
- Configuration<?> configuration = Validation.byDefaultProvider().configure();
- configuration.messageInterpolator( new DummyMessageInterpolator() );
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+ Validator validator = factory.usingContext()
+ .messageInterpolator( new DummyMessageInterpolator() )
+ .getValidator();
- Validator validator = configuration.buildValidatorFactory().getValidator();
assertCustomMessageInterpolatorUsed( validator );
}
@@ -175,7 +177,7 @@
throw new RuntimeException( "Unable to load service file", e );
}
return providers;
- }
+ }
private void assertCustomMessageInterpolatorUsed(Validator validator) {
Person person = new Person();
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java 2009-06-21
08:39:29 UTC (rev 16843)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/AddressWithInvalidGroupSequence.java 2009-06-21
09:36:16 UTC (rev 16844)
@@ -1,12 +0,0 @@
-package org.hibernate.jsr303.tck.tests.constraints.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.groups.Default;
-
-/**
- * @author Emmanuel Bernard
- */
-@GroupSequence({ Default.class, AddressWithInvalidGroupSequence.HighLevelCoherence.class
})
-public class AddressWithInvalidGroupSequence extends Address {
-
-}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java 2009-06-21
08:39:29 UTC (rev 16843)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/Car.java 2009-06-21
09:36:16 UTC (rev 16844)
@@ -12,7 +12,7 @@
@GroupSequence({ Car.class, Car.Test.class })
public class Car {
@Pattern(regexp = ".*", groups = Default.class)
- @Size(min = 2, max = 20, groups = Car.Test.class)
+ @Size(min = 2, max = 20, groups = Car.Test.class, message = "Car type has to be
betweeb {min} and {max} characters.")
private String type;
public String getType() {
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-06-21
08:39:29 UTC (rev 16843)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/DefaultGroupRedefinitionTest.java 2009-06-21
09:36:16 UTC (rev 16844)
@@ -20,13 +20,15 @@
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.validation.ConstraintViolation;
-import javax.validation.ValidationException;
+import javax.validation.GroupDefinitionException;
+import javax.validation.GroupSequence;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
@@ -37,9 +39,12 @@
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static
org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessage;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
/**
- * Tests for the group and group sequence feature.
+ * Tests for redifining the default group sequence.
*
* @author Hardy Ferentschik
*/
@@ -64,7 +69,8 @@
);
ConstraintViolation<Address> violation = constraintViolations.iterator().next();
- TestUtil.assertConstraintViolation( violation, Address.class, null, "zipcode"
);
+ assertConstraintViolation( violation, Address.class, null, "zipcode" );
+ assertCorrectConstraintViolationMessage( violation, "may not be null" );
address.setZipcode( "41841" );
@@ -77,7 +83,8 @@
);
violation = constraintViolations.iterator().next();
- TestUtil.assertConstraintViolation( violation, Address.class, address, "" );
+ assertConstraintViolation( violation, Address.class, address, "" );
+ assertCorrectConstraintViolationMessage( violation, "Zip code is not
coherent." );
}
@Test(enabled = false)
@@ -102,68 +109,66 @@
}
@Test
- public void testRedefiningDefaultGroup2() {
+ @SpecAssertion(section = "3.4.3", id = "a")
+ public void testValidatingAgainstRedefinedDefaultGroup() {
Car car = new Car();
car.setType( "A" );
Validator validator = TestUtil.getDefaultValidator();
+ // if the group sequence would not be properly redefined there would be no error when
validating default.
+
Set<ConstraintViolation<Car>> constraintViolations = validator.validate(
car );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default
group"
- );
- assertEquals(
- "size must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
+ assertCorrectNumberOfViolations(constraintViolations, 1);
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(),
"Car type has to be betweeb 2 and 20 characters." );
constraintViolations = validator.validateProperty( car, "type" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default
group"
- );
- assertEquals(
- "size must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
+ assertCorrectNumberOfViolations(constraintViolations, 1);
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(),
"Car type has to be betweeb 2 and 20 characters.");
constraintViolations = validator.validateValue( Car.class, "type",
"A" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default
group"
- );
- assertEquals(
- "size must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
+ assertCorrectNumberOfViolations(constraintViolations, 1);
+ assertCorrectConstraintViolationMessage( constraintViolations.iterator().next(),
"Car type has to be betweeb 2 and 20 characters.");
}
@Test
- public void testInvalidRedefinitionOfDefaultGroup() {
- Address address = new AddressWithInvalidGroupSequence();
+ @SpecAssertions({
+ @SpecAssertion(section = "3.4.3", id = "c"),
+ @SpecAssertion(section = "3.4.3", id = "d")
+ })
+ public void testGroupSequenceContainingDefault() {
+ Address address = new AddressWithDefaultInGroupSequence();
Validator validator = TestUtil.getDefaultValidator();
try {
validator.validate( address );
fail( "It shoud not be allowed to have Default.class in the group sequence of a
class." );
}
- catch ( ValidationException e ) {
- assertEquals(
- "'Default.class' cannot appear in default group sequence list.",
e.getMessage(), "Wrong message"
- );
+ catch ( GroupDefinitionException e ) {
+ // success
}
}
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.4.3", id = "c"),
+ @SpecAssertion(section = "3.4.3", id = "d")
+ })
+ public void testGroupSequenceWithNoImplicitDefaultGroup() {
+ Address address = new AddressWithNoImplicitDefaultGroupSequence();
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( address );
+ fail( "A valid group sequence definiton must contain the class itself as implicit
default group." );
+ }
+ catch ( GroupDefinitionException e ) {
+ // success
+ }
+ }
+
private void assertAssertionType(Set<ConstraintViolation<Address>>
violations) {
for ( ConstraintViolation<Address> violation : violations ) {
// cast is required for JDK 5 - at least on Mac OS X
- Annotation ann = (Annotation) violation.getConstraintDescriptor().getAnnotation();
+ Annotation ann = ( Annotation ) violation.getConstraintDescriptor().getAnnotation();
assertEquals(
NotNull.class,
ann.annotationType(),
@@ -171,4 +176,14 @@
);
}
}
+
+ @GroupSequence({ Default.class, Address.HighLevelCoherence.class })
+ public class AddressWithDefaultInGroupSequence extends Address {
+
+ }
+
+ @GroupSequence({ Address.HighLevelCoherence.class })
+ public class AddressWithNoImplicitDefaultGroupSequence extends Address {
+
+ }
}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java 2009-06-21
08:39:29 UTC (rev 16843)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/ZipCodeCoherenceChecker.java 2009-06-21
09:36:16 UTC (rev 16844)
@@ -16,7 +16,7 @@
@Documented
@Constraint(validatedBy = ZipCodeCoherenceValidator.class)
public @interface ZipCodeCoherenceChecker {
- public abstract String message() default
"{validator.zipCodeCoherenceChecker}";
+ public abstract String message() default "Zip code is not coherent.";
public abstract Class<?>[] groups() default { };
}
\ No newline at end of file