Author: hardy.ferentschik
Date: 2009-06-22 06:57:54 -0400 (Mon, 22 Jun 2009)
New Revision: 16847
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Metadata tests
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -132,17 +132,16 @@
assertNull( beanDescriptor.getConstraintsForProperty( "foobar" ), "There
should be no descriptor" );
}
- /**
- * @todo Is this corect or should we get a IllegalArgumentException
- */
- @Test
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void testGetConstraintsForNullProperty() {
Validator validator = TestUtil.getDefaultValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertNull( beanDescriptor.getConstraintsForProperty( null ), "There should be no
descriptor" );
+ beanDescriptor.getConstraintsForProperty( null );
}
@Test
+ @SpecAssertion(section = "5.3", id = "b")
public void testGetConstrainedProperties() {
Validator validator = TestUtil.getDefaultValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
@@ -156,6 +155,15 @@
}
@Test
+ @SpecAssertion(section = "5.3", id = "b")
+ public void testGetConstrainedPropertiesForUnconstraintEntity() {
+ Validator validator = TestUtil.getDefaultValidator();
+ BeanDescriptor beanDescriptor = validator.getConstraintsForClass(
UnconstraintEntity.class );
+ Set<PropertyDescriptor> constraintProperties =
beanDescriptor.getConstrainedProperties();
+ assertEquals( constraintProperties.size(), 0, "We should get the empty set."
);
+ }
+
+ @Test(enabled = false)
public void testGetConstrainedPropertiesImmutable() {
Validator validator = TestUtil.getDefaultValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
@@ -176,12 +184,4 @@
// success
}
}
-
- @Test
- public void testGetConstrainedPropertiesForUnconstraintEntity() {
- Validator validator = TestUtil.getDefaultValidator();
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass(
UnconstraintEntity.class );
- Set<PropertyDescriptor> constraintProperties =
beanDescriptor.getConstrainedProperties();
- assertEquals( constraintProperties.size(), 0, "We should get the empty set."
);
- }
}
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -17,21 +17,21 @@
*/
package org.hibernate.jsr303.tck.tests.metadata;
-import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
import javax.validation.groups.Default;
import javax.validation.metadata.ConstraintDescriptor;
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;
import org.jboss.testharness.impl.packaging.Classes;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import org.testng.annotations.Test;
@@ -48,6 +48,107 @@
public class ConstraintDescriptorTest extends AbstractTest {
@Test
+ public void testReportAsSingleViolation() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
+ assertFalse( descriptor.isReportAsSingleViolation() );
+
+ descriptor = getConstraintDescriptor( Person.class, "firstName" );
+ assertTrue( descriptor.isReportAsSingleViolation() );
+ }
+
+ @Test
+ public void testEmptyComposingConstraints() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
+ assertTrue( descriptor.getComposingConstraints().isEmpty() );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "5.5", id = "a"),
+ @SpecAssertion(section = "5.5", id = "c")
+ })
+ public void testAnnotationAndMapParamtersReflectParamterOverriding() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class,
"firstName" );
+ Set<ConstraintDescriptor<?>> composingDescriptors =
descriptor.getComposingConstraints();
+ assertEquals( composingDescriptors.size(), 2, "Wrong number of composing
constraints" );
+ for ( ConstraintDescriptor<?> desc : composingDescriptors ) {
+ if ( desc.getAnnotation().annotationType().equals( Size.class ) ) {
+ Size sizeAnn = ( Size ) desc.getAnnotation();
+ assertEquals( sizeAnn.min(), 5, "The min parameter should reflect the overriden
parameter" );
+ assertEquals(
+ desc.getAttributes().get( "min" ), 5, "The min parameter should
reflect the overriden parameter"
+ );
+ }
+ else if ( desc.getAnnotation().annotationType().equals( NotNull.class ) ) {
+ }
+ else {
+ fail( "Unexpected annotation." );
+ }
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "b")
+ public void testGetAttributesFromConstraintDescriptor() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
+ Map<String, Object> attributes = descriptor.getAttributes();
+ assertTrue( attributes.containsKey( "message" ) );
+ assertTrue( attributes.containsKey( "groups" ) );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "d")
+ public void testGetGroups() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class,
"firstName" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1 );
+ assertEquals( groups.iterator().next(), Person.PersonValidation.class, "Wrong
group" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "d")
+ public void testGetGroupsOnInterface() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class,
"lastName" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1 );
+ assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "d")
+ public void testGetGroupsWithImplcitGroup() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Man.class,
"lastName" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 2 );
+ for ( Class<?> group : groups ) {
+ if ( !( group.equals( Default.class ) || group.equals( Person.class ) ) ) {
+ fail( "Invalid group." );
+ }
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "e")
+ public void testDefaultGroupIsReturnedIfNoGroupSpecifiedInDeclaration() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
+ Set<Class<?>> groups = descriptor.getGroups();
+ assertTrue( groups.size() == 1 );
+ assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
+ }
+
+ @Test
+ @SpecAssertion(section = "5.5", id = "f")
+ public void testComposingConstraints() {
+ ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class,
"firstName" );
+ Set<ConstraintDescriptor<?>> composingDescriptors =
descriptor.getComposingConstraints();
+ assertEquals( composingDescriptors.size(), 2, "Wrong number of composing
constraints" );
+ for ( ConstraintDescriptor<?> desc : composingDescriptors ) {
+ assertTrue( desc.getGroups().size() == 1 );
+ assertEquals( desc.getGroups().iterator().next(), Person.PersonValidation.class,
"Wrong group" );
+ }
+ }
+
+ @Test(enabled = false)
public void testConstraintDescriptorImmutable() {
ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
@@ -84,64 +185,6 @@
}
}
- @Test
- public void testReportAsSingleViolation() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
- assertFalse( descriptor.isReportAsSingleViolation() );
-
- descriptor = getConstraintDescriptor( Person.class, "firstName" );
- assertTrue( descriptor.isReportAsSingleViolation() );
- }
-
- @Test
- public void testComposingConstraints() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
- assertTrue( descriptor.getComposingConstraints().isEmpty() );
- }
-
- /**
- * @todo Is getComposingConstraints() recursive and hence the result should be 4?
- */
- @Test
- public void testEmptyComposingConstraints() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class,
"firstName" );
- assertEquals( descriptor.getComposingConstraints().size(), 2, "Wrong number of
composing constraints" );
- }
-
- @Test
- public void testGetAnnotation() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
- Annotation annotation = descriptor.getAnnotation();
- assertNotNull( annotation );
- assertTrue( annotation instanceof NotNull );
- }
-
- @Test
- @SpecAssertion(section = "5.5", id = "e")
- public void testDefaultGroupIsReturnedIfNoGroupSpecifiedInDeclaration() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
- Set<Class<?>> groups = descriptor.getGroups();
- assertTrue( groups.size() == 1 );
- assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
- }
-
-// @Test
-// public void testGetConstraintValidatorClasses() {
-// Set<ConstraintDescriptor<?>> descriptors = getConstraintDescriptorsFor(
Order.class, "orderNumber" );
-// assertTrue( descriptors.size() == 1, "There should only by one descriptor."
);
-// ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
-// assertEquals( descriptor.getConstraintValidatorClasses().get( 0 ),
InvertedNotNullValidator.class, "Wrong classes" );
-// }
-
- @Test
- @SpecAssertion(section = "5.5", id = "b")
- public void testGetAttributesFromConstraintDescriptor() {
- ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class,
"orderNumber" );
- Map<String, Object> attributes = descriptor.getAttributes();
- assertTrue( attributes.containsKey( "message" ) );
- assertTrue( attributes.containsKey( "groups" ) );
- }
-
private ConstraintDescriptor<?> getConstraintDescriptor(Class<?> clazz,
String property) {
Set<ConstraintDescriptor<?>> descriptors = getConstraintDescriptorsFor(
clazz, property );
assertTrue( descriptors.size() == 1, "There should only by one descriptor."
);
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -1,92 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.jsr303.tck.tests.metadata;
-
-import java.util.Set;
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.metadata.ConstraintDescriptor;
-import javax.validation.metadata.ElementDescriptor;
-import javax.validation.Validator;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-import org.testng.annotations.Test;
-import org.jboss.testharness.AbstractTest;
-import org.jboss.testharness.impl.packaging.Artifact;
-import org.jboss.testharness.impl.packaging.ArtifactType;
-import org.jboss.testharness.impl.packaging.Classes;
-
-import org.hibernate.jsr303.tck.util.TestUtil;
-
-/**
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes(TestUtil.class)
-public class ElementDescriptorTest extends AbstractTest {
-
-
- @Test
- public void testGetTypeForConstrainedBean() {
- Validator validator = TestUtil.getDefaultValidator();
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
- assertEquals( beanDescriptor.getType(), Customer.class, "Wrong type." );
- }
-
- @Test
- public void testGetTypeForConstrainedProperty() {
- ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class,
"orderNumber" );
- assertEquals( elementDescriptor.getType(), Integer.class, "Wrong type." );
- }
-
- /**
- * HV-95
- */
- @Test
- public void testElementDescriptorForProperty() {
- ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class,
"orderNumber" );
- Set<ConstraintDescriptor<?>> constraintDescriptors =
elementDescriptor.getConstraintDescriptors();
- assertTrue( constraintDescriptors.size() == 1, "There should be a descriptor"
);
- }
-
- /**
- * HV-95
- */
- @Test
- public void testElementDescriptorImmutable() {
- ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class,
"orderNumber" );
- Set<ConstraintDescriptor<?>> constraintDescriptors =
elementDescriptor.getConstraintDescriptors();
-
- try {
- constraintDescriptors.add( null );
- fail( "Set should be immutable" );
- }
- catch ( UnsupportedOperationException e ) {
- // success
- }
-
- try {
- constraintDescriptors.remove( null );
- fail( "Set should be immutable" );
- }
- catch ( UnsupportedOperationException e ) {
- // success
- }
- }
-}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -24,6 +24,7 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
import javax.validation.ReportAsSingleViolation;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -32,14 +33,17 @@
* @author Emmanuel Bernard
*/
@Documented
-@Constraint(validatedBy = {})
+@Constraint(validatedBy = { })
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
@ReportAsSingleViolation
@NotNull
-@Size(min=1)
+@Size
public @interface NotEmpty {
public abstract String message() default
"{org.hibernate.validation.constraints.NotEmpty.message}";
public abstract Class<?>[] groups() default { };
+
+ @OverridesAttribute(constraint = Size.class, name = "min")
+ public abstract int min() default 5;
}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -23,7 +23,7 @@
* @author Hardy Ferentschik
*/
public class Order {
- @NotNull
+ @NotNull(message = "Order number must be specified")
Integer orderNumber;
public Integer getOrderNumber() {
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -21,11 +21,14 @@
* @author Hardy Ferentschik
*/
public interface Person {
- @NotEmpty
+ @NotEmpty(groups = PersonValidation.class)
String getFirstName();
String getMiddleName();
@NotEmpty
String getLastName();
+
+ public interface PersonValidation {
+ }
}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -23,6 +23,7 @@
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.test.audit.annotations.SpecAssertion;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -39,12 +40,14 @@
@Classes(TestUtil.class)
public class PropertyDescriptorTest extends AbstractTest {
@Test
+ @SpecAssertion(section = "5.4", id = "a")
public void testIsNotCascaded() {
PropertyDescriptor descriptor = getPropertyDescriptor( Order.class,
"orderNumber" );
assertFalse( descriptor.isCascaded(), "Should not be cascaded" );
}
@Test
+ @SpecAssertion(section = "5.4", id = "a")
public void testIsCascaded() {
PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class,
"orderList" );
assertTrue( descriptor.isCascaded(), "Should be cascaded" );
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-22
09:36:49 UTC (rev 16846)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-22
10:57:54 UTC (rev 16847)
@@ -112,7 +112,6 @@
);
}
-
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String
property) {
Validator validator = getDefaultValidator();
return validator.getConstraintsForClass( clazz ).getConstraintsForProperty( property
);
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-22
09:36:49 UTC (rev 16846)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-22
10:57:54 UTC (rev 16847)
@@ -387,7 +387,7 @@
must contain the group A</text>
</assertion>
<assertion id="d">
- <text>If a @GroupSequence rede- fining the Default group for a class A
does not contain
+ <text>If a @GroupSequence redefining the Default group for a class A
does not contain
the group A, a GroupDefinitionException is raised when the class is
validated or
when its metadata is requested</text>
</assertion>
@@ -921,8 +921,7 @@
returned</text>
</assertion>
<assertion id="f">
- <text>The groups of a composing constraint are the groups of the
composed con-
- straint</text>
+ <text>The groups of a composing constraint are the groups of the
composed constraint</text>
</assertion>
</section>
<section id="6" title="Built-in Constraint definitions">
@@ -1106,7 +1105,7 @@
</section>
<section id="7.1.1.4" title="Constraint declaration">
<assertion id="a">
- <text>The name attribute is mandatory and repres- ents the name of the
element in the
+ <text>The name attribute is mandatory and represents the name of the
element in the
constraint declaration</text>
</assertion>
<assertion id="b">