Hibernate SVN: r16714 - in beanvalidation/trunk/validation-tck/src/main: resources and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-05 11:41:20 -0400 (Fri, 05 Jun 2009)
New Revision: 16714
Modified:
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:
Added explicit cast for Java 5
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-05 15:30:57 UTC (rev 16713)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-05 15:41:20 UTC (rev 16714)
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import java.lang.annotation.Annotation;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
@@ -41,7 +42,7 @@
public static <T> void assertCorrectConstraintType(ConstraintViolation<T> violation, Class<?> expectedConstraintType) {
assertEquals(
- violation.getConstraintDescriptor().getAnnotation().annotationType().getName(),
+ (( Annotation )violation.getConstraintDescriptor().getAnnotation()).annotationType().getName(),
expectedConstraintType.getName(),
"Wrong constraint type"
);
@@ -54,7 +55,7 @@
public static <T> void assertCorrectConstraintTypes(Set<ConstraintViolation<T>> violations, Class<?>[] expectedConsraintTypes) {
List<String> constraintTypes = new ArrayList<String>();
for ( ConstraintViolation<?> violation : violations ) {
- constraintTypes.add( violation.getConstraintDescriptor().getAnnotation().annotationType().getName() );
+ constraintTypes.add( (( Annotation )violation.getConstraintDescriptor().getAnnotation()).annotationType().getName() );
}
assertEquals( expectedConsraintTypes.length, constraintTypes.size(), "Wring number of constraint types." );
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-05 15:30:57 UTC (rev 16713)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-05 15:41:20 UTC (rev 16714)
@@ -92,7 +92,7 @@
</assertion>
<assertion id="f">
<text>The property type a composed constraint is placed on must be compatible with all
- constraints (composing and com- posed)</text>
+ constraints (composing and composed)</text>
</assertion>
<assertion id="g">
<text> If a composed constraint is marked as @ReportAsSingleViolation, and if any of its
@@ -116,7 +116,7 @@
</assertion>
<assertion id="k">
<text>A composing constraint can itself be a composed constraint. In this case,
- attribute values are overridden re- cursively according to the described
+ attribute values are overridden recursively according to the described
rules</text>
</assertion>
<assertion id="l">
15 years, 6 months
Hibernate SVN: r16713 - in core/branches/envers-hibernate-3.3/src: main/java/org/hibernate/envers/entities/mapper and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-06-05 11:30:57 -0400 (Fri, 05 Jun 2009)
New Revision: 16713
Added:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java
Log:
svn merge -r 16502:16710 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-06-05 15:27:59 UTC (rev 16712)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-06-05 15:30:57 UTC (rev 16713)
@@ -164,6 +164,19 @@
}
}
+ private boolean checkPropertiesAudited(Iterator<Property> properties, ClassAuditingData auditingData) {
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ String propertyName = property.getName();
+ PropertyAuditingData propertyAuditingData = auditingData.getPropertyAuditingData(propertyName);
+ if (propertyAuditingData == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
@SuppressWarnings({"unchecked"})
private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) {
Iterator<Join> joins = pc.getJoinIterator();
@@ -174,6 +187,11 @@
while (joins.hasNext()) {
Join join = joins.next();
+ // Checking if all of the join properties are audited
+ if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
+ continue;
+ }
+
// Determining the table name. If there is no entry in the dictionary, just constructing the table name
// as if it was an entity (by appending/prepending configured strings).
String originalTableName = join.getTable().getName();
@@ -210,8 +228,10 @@
Join join = joins.next();
Element joinElement = entitiesJoins.get(entityName).get(join);
- addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName,
- xmlMappingData, firstPass);
+ if (joinElement != null) {
+ addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName,
+ xmlMappingData, firstPass);
+ }
}
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java 2009-06-05 15:27:59 UTC (rev 16712)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java 2009-06-05 15:30:57 UTC (rev 16713)
@@ -78,13 +78,17 @@
}
private boolean isPrimitive(Setter setter, PropertyData propertyData, Class<?> cls) {
+ if (cls == null) {
+ throw new HibernateException("No field found for property: " + propertyData.getName());
+ }
+
if (setter instanceof DirectPropertyAccessor.DirectSetter) {
// In a direct setter, getMethod() returns null
// Trying to look up the field
try {
return cls.getDeclaredField(propertyData.getBeanName()).getType().isPrimitive();
} catch (NoSuchFieldException e) {
- throw new HibernateException(e);
+ return isPrimitive(setter, propertyData, cls.getSuperclass());
}
} else {
return setter.getMethod().getParameterTypes()[0].isPrimitive();
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2009-06-05 15:27:59 UTC (rev 16712)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2009-06-05 15:30:57 UTC (rev 16713)
@@ -243,7 +243,7 @@
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
CollectionEntry collectionEntry = getCollectionEntry(event);
- if (!collectionEntry.getLoadedPersister().isInverse()) {
+ if (collectionEntry != null && !collectionEntry.getLoadedPersister().isInverse()) {
onCollectionAction(event, null, collectionEntry.getSnapshot(), collectionEntry);
}
}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java (from rev 16710, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildNullAuditing.java 2009-06-05 15:30:57 UTC (rev 16713)
@@ -0,0 +1,94 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.envers.test.integration.inheritance.joined;
+
+import java.util.Arrays;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ChildNullAuditing extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ id1 = 1;
+
+ // Rev 1
+ em.getTransaction().begin();
+ ChildEntity ce = new ChildEntity(id1, "x", null);
+ em.persist(ce);
+ em.getTransaction().commit();
+
+ // Rev 2
+ em.getTransaction().begin();
+ ce = em.find(ChildEntity.class, id1);
+ ce.setData(null);
+ ce.setNumber(2l);
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(ChildEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfChildId1() {
+ ChildEntity ver1 = new ChildEntity(id1, "x", null);
+ ChildEntity ver2 = new ChildEntity(id1, null, 2l);
+
+ assert getAuditReader().find(ChildEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ChildEntity.class, id1, 2).equals(ver2);
+
+ assert getAuditReader().find(ParentEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(ParentEntity.class, id1, 2).equals(ver2);
+ }
+
+ @Test
+ public void testPolymorphicQuery() {
+ ChildEntity childVer1 = new ChildEntity(id1, "x", null);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ChildEntity.class, 1).getSingleResult()
+ .equals(childVer1);
+
+ assert getAuditReader().createQuery().forEntitiesAtRevision(ParentEntity.class, 1).getSingleResult()
+ .equals(childVer1);
+ }
+}
\ No newline at end of file
15 years, 6 months
Hibernate SVN: r16712 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-05 11:27:59 -0400 (Fri, 05 Jun 2009)
New Revision: 16712
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
Log:
Added exception when applying composite constraints
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-06-05 15:27:11 UTC (rev 16711)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-06-05 15:27:59 UTC (rev 16712)
@@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Set;
import javax.validation.Constraint;
+import javax.validation.ConstraintDefinitionException;
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintValidator;
import javax.validation.OverridesAttribute;
@@ -225,13 +226,13 @@
for ( Method m : annotation.annotationType().getMethods() ) {
if ( m.getAnnotation( OverridesAttribute.class ) != null ) {
addOverrideAttributes(
- overrideParameters, getMethodValue( annotation, m ), m.getAnnotation( OverridesAttribute.class )
+ overrideParameters, m, m.getAnnotation( OverridesAttribute.class )
);
}
else if ( m.getAnnotation( OverridesAttribute.List.class ) != null ) {
addOverrideAttributes(
overrideParameters,
- getMethodValue( annotation, m ),
+ m,
m.getAnnotation( OverridesAttribute.List.class ).value()
);
}
@@ -239,18 +240,42 @@
return overrideParameters;
}
- private void addOverrideAttributes(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters, Object value, OverridesAttribute... attributes) {
- for ( OverridesAttribute attribute : attributes ) {
- ClassIndexWrapper wrapper = new ClassIndexWrapper( attribute.constraint(), attribute.constraintIndex() );
+ private void addOverrideAttributes(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters, Method m, OverridesAttribute... attributes) {
+
+ Object value = getMethodValue( annotation, m );
+ for ( OverridesAttribute overridesAttribute : attributes ) {
+ ensureAttributeIsOverridable( m, overridesAttribute );
+
+ ClassIndexWrapper wrapper = new ClassIndexWrapper(
+ overridesAttribute.constraint(), overridesAttribute.constraintIndex()
+ );
Map<String, Object> map = overrideParameters.get( wrapper );
if ( map == null ) {
map = new HashMap<String, Object>();
overrideParameters.put( wrapper, map );
}
- map.put( attribute.name(), value );
+ map.put( overridesAttribute.name(), value );
}
}
+ private void ensureAttributeIsOverridable(Method m, OverridesAttribute overridesAttribute) {
+ try {
+ Class<?> returnTypeOfOverridenConstraint = overridesAttribute.constraint()
+ .getMethod( overridesAttribute.name() )
+ .getReturnType();
+ if ( !returnTypeOfOverridenConstraint.equals( m.getReturnType() ) ) {
+ String message = "The overiding type of a composite constraint must be identical to the overwridden one. Expected " + returnTypeOfOverridenConstraint
+ .getName() + " found " + m.getReturnType();
+ throw new ConstraintDefinitionException( message );
+ }
+ }
+ catch ( NoSuchMethodException nsme ) {
+ throw new ConstraintDefinitionException(
+ "Overriden constraint does not define an attribute with name " + overridesAttribute.name()
+ );
+ }
+ }
+
private void parseComposingConstraints(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters) {
for ( Annotation declaredAnnotation : annotation.annotationType().getDeclaredAnnotations() ) {
if ( constraintHelper.isConstraintAnnotation( declaredAnnotation )
@@ -316,6 +341,9 @@
);
}
+ /**
+ * A wrapper class to keep track for which compposing constraints (class and index) a given attribute override applies to.
+ */
private class ClassIndexWrapper {
final Class<?> clazz;
final int index;
15 years, 6 months
Hibernate SVN: r16711 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-05 11:27:11 -0400 (Fri, 05 Jun 2009)
New Revision: 16711
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeWithInvalidOverride.java
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java
Log:
Constraint composition
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-05 14:18:41 UTC (rev 16710)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-05 15:27:11 UTC (rev 16711)
@@ -17,9 +17,13 @@
*/
package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
+import javax.validation.BeanDescriptor;
+import javax.validation.ConstraintDefinitionException;
+import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
@@ -35,6 +39,7 @@
import org.jboss.testharness.impl.packaging.Classes;
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.hibernate.jsr303.tck.util.TestUtil;
@@ -53,10 +58,13 @@
public class ConstraintCompositionTest extends AbstractTest {
@Test
- @SpecAssertion(section = "2.3", id = "a")
- public void testComposedConstraintsAreRecursive() {
+ @SpecAssertions({
+ @SpecAssertion(section = "2.3", id = "a"),
+ @SpecAssertion(section = "2.3", id = "k")
+ })
+ public void testComposedConstraints() {
+
Validator validator = TestUtil.getDefaultValidator();
-
FrenchAddress address = getFrenchAddressWithoutZipCode();
Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
assertCorrectNumberOfViolations( constraintViolations, 1 );
@@ -72,6 +80,28 @@
}
@Test
+ @SpecAssertions({
+ @SpecAssertion(section = "2.3", id = "a"),
+ @SpecAssertion(section = "2.3", id = "k")
+ })
+ public void testComposedConstraintsAreRecursive() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ GermanAddress address = new GermanAddress();
+ address.setAddressline1( "Rathausstrasse 5" );
+ address.setAddressline2( "3ter Stock" );
+ address.setCity( "Karlsruhe" );
+ Set<ConstraintViolation<GermanAddress>> constraintViolations = validator.validate( address );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(),
+ GermanAddress.class,
+ null,
+ "zipCode"
+ );
+ }
+
+ @Test
@SpecAssertion(section = "2.3", id = "b")
public void testValidationOfMainAnnotationIsAlsoApplied() {
@@ -88,13 +118,17 @@
}
@Test
- @SpecAssertion(section = "2.3", id = "c")
+ @SpecAssertions({
+ @SpecAssertion(section = "2.3", id = "c"),
+ @SpecAssertion(section = "2.3", id = "i"),
+ @SpecAssertion(section = "2.3", id = "l"),
+ @SpecAssertion(section = "2.3", id = "m"),
+ @SpecAssertion(section = "2.3", id = "n")
+ })
public void testEachFailingConstraintCreatesConstraintViolation() {
Validator validator = TestUtil.getDefaultValidator();
-
FrenchAddress address = getFrenchAddressWithoutZipCode();
-
address.setZipCode( "abc" );
Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
assertCorrectNumberOfViolations( constraintViolations, 3 );
@@ -155,41 +189,59 @@
}
@Test
- public void testNestedComposition() {
+ @SpecAssertion(section = "2.3", id = "g")
+ public void testOnlySingleConstraintViolation() {
Validator validator = TestUtil.getDefaultValidator();
GermanAddress address = new GermanAddress();
address.setAddressline1( "Rathausstrasse 5" );
address.setAddressline2( "3ter Stock" );
address.setCity( "Karlsruhe" );
+ address.setZipCode( "abc" );
+ // actually three composing constraints fail, but due to @ReportAsSingleViolation only one will be reported.
Set<ConstraintViolation<GermanAddress>> constraintViolations = validator.validate( address );
assertCorrectNumberOfViolations( constraintViolations, 1 );
assertConstraintViolation(
constraintViolations.iterator().next(),
GermanAddress.class,
- null,
+ "abc",
"zipCode"
);
}
@Test
- public void testOnlySingleConstraintViolation() {
+ @SpecAssertion(section = "2.3", id = "h")
+ public void testAttributesDefinedOnComposingConstraints() {
+
Validator validator = TestUtil.getDefaultValidator();
+ BeanDescriptor descriptor = validator.getConstraintsForClass( FrenchAddress.class );
+ Set<ConstraintDescriptor<?>> constraintDescriptors = descriptor.getConstraintsForProperty( "zipCode" )
+ .getConstraintDescriptors();
+ for ( ConstraintDescriptor<?> constraintDescriptor : constraintDescriptors ) {
+ Annotation ann = constraintDescriptor.getAnnotation();
+ if ( Pattern.class.getName().equals( ann.annotationType().getName() ) ) {
+ String regexp = ( ( Pattern ) ann ).regexp();
+ if ( regexp.equals( "\\d*" ) || regexp.equals( "....." ) ) {
+ fail( "The regular expression should attributes are defined in the composing constraint." );
+ }
+ }
+ }
+ }
- GermanAddress address = new GermanAddress();
- address.setAddressline1( "Rathausstrasse 5" );
- address.setAddressline2( "3ter Stock" );
- address.setCity( "Karlsruhe" );
- address.setZipCode( "abc" );
- // actually three composing constraints fail, but due to @ReportAsSingleViolation only one will be reported.
- Set<ConstraintViolation<GermanAddress>> constraintViolations = validator.validate( address );
- assertCorrectNumberOfViolations( constraintViolations, 1 );
- assertConstraintViolation(
- constraintViolations.iterator().next(),
- GermanAddress.class,
- "abc",
- "zipCode"
- );
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "2.3", id = "j"),
+ @SpecAssertion(section = "2.3", id = "o")
+ })
+ public void testOverridenAttributesMustMatchInType() {
+ Validator validator = TestUtil.getDefaultValidator();
+ try {
+ validator.validate( new DummyEntityWithZipCode( "foobar" ) );
+ fail( "Wrong atttibute override in composite constraint. An Exception should have been thrown." );
+ }
+ catch ( ConstraintDefinitionException e ) {
+ // success
+ }
}
private FrenchAddress getFrenchAddressWithoutZipCode() {
@@ -199,4 +251,13 @@
address.setCity( "Bordeaux" );
return address;
}
+
+ class DummyEntityWithZipCode {
+ @FrenchZipcodeWithInvalidOverride
+ String zip;
+
+ DummyEntityWithZipCode(String zip) {
+ this.zip = zip;
+ }
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java 2009-06-05 14:18:41 UTC (rev 16710)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java 2009-06-05 15:27:11 UTC (rev 16711)
@@ -26,7 +26,6 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.OverridesAttribute;
-import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
@@ -50,11 +49,12 @@
@OverridesAttribute.List({
@OverridesAttribute(constraint = Size.class, name = "min"),
@OverridesAttribute(constraint = Size.class, name = "max")
- }) int size() default 5;
+ })
+ int size() default 5;
- @OverridesAttribute(constraint = Size.class,
- name = "message") String sizeMessage() default "A french zip code has a length of 5";
+ @OverridesAttribute(constraint = Size.class, name = "message")
+ String sizeMessage() default "A french zip code has a length of 5";
-
- @OverridesAttribute(constraint = Pattern.class, name = "regexp", constraintIndex = 2) String regex() default "\\d*";
+ @OverridesAttribute(constraint = Pattern.class, name = "regexp", constraintIndex = 2)
+ String regex() default "\\d*";
}
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeWithInvalidOverride.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeWithInvalidOverride.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeWithInvalidOverride.java 2009-06-05 15:27:11 UTC (rev 16711)
@@ -0,0 +1,57 @@
+// $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.constraints.constraintcomposition;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.OverridesAttribute;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@NotEmpty
+@Size
+// first pattern just duplicates the length of 5 characters, the second pattern is just to proof that parameters can be overridden.
+(a)Pattern.List({ @Pattern(regexp = "....."), @Pattern(regexp = "bar") })
+@Constraint(validatedBy = FrenchZipcodeConstraintValidator.class)
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface FrenchZipcodeWithInvalidOverride {
+ public abstract String message() default "Wrong zipcode";
+
+ public abstract Class<?>[] groups() default { };
+
+ @OverridesAttribute.List({
+ @OverridesAttribute(constraint = Size.class, name = "min"),
+ @OverridesAttribute(constraint = Size.class, name = "max")
+ }) public abstract String size() default "5";
+
+ @OverridesAttribute(constraint = Size.class, name = "message") public abstract String sizeMessage() default "A french zip code has a length of 5";
+
+ @OverridesAttribute(constraint = Pattern.class, name = "regexp", constraintIndex = 2) public abstract String regex() default "\\d*";
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeWithInvalidOverride.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java 2009-06-05 14:18:41 UTC (rev 16710)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcode.java 2009-06-05 15:27:11 UTC (rev 16711)
@@ -26,6 +26,8 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.ReportAsSingleViolation;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
/**
* Constraint used to test nested composing constraints.
@@ -33,7 +35,7 @@
* @author Hardy Ferentschik
*/
@FrenchZipcode
-@Constraint(validatedBy = GermanZipcodeConstraintValidator.class)
+@Constraint(validatedBy = GermanZipcode.GermanZipcodeConstraintValidator.class)
@Documented
@Target({ METHOD, FIELD, TYPE })
@Retention(RUNTIME)
@@ -42,4 +44,14 @@
public abstract String message() default "Falsche Postnummer.";
public abstract Class<?>[] groups() default { };
+
+ public class GermanZipcodeConstraintValidator implements ConstraintValidator<GermanZipcode, String> {
+
+ public void initialize(GermanZipcode parameters) {
+ }
+
+ public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+}
}
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java 2009-06-05 14:18:41 UTC (rev 16710)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/GermanZipcodeConstraintValidator.java 2009-06-05 15:27:11 UTC (rev 16711)
@@ -1,34 +0,0 @@
-// $Id: GermanZipcodeConstraintValidator.java 15829 2009-01-29 05:20:27Z epbernard $
-/*
-* 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.constraints.constraintcomposition;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- */
-public class GermanZipcodeConstraintValidator implements ConstraintValidator<GermanZipcode, String> {
-
- public void initialize(GermanZipcode parameters) {
- }
-
- public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
- return true;
- }
-}
\ No newline at end of file
15 years, 6 months
Hibernate SVN: r16710 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validation/engine/xml and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-05 10:18:41 -0400 (Fri, 05 Jun 2009)
New Revision: 16710
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/XmlMappingParser.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java
Log:
Made sure that groups are inherited in composite constraints
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-06-05 14:17:58 UTC (rev 16709)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-06-05 14:18:41 UTC (rev 16710)
@@ -115,11 +115,11 @@
}
public List<Member> getCascadedMembers() {
- return cascadedMembers;
+ return Collections.unmodifiableList( cascadedMembers );
}
public List<MetaConstraint<T, ? extends Annotation>> geMetaConstraintList() {
- return metaConstraintList;
+ return Collections.unmodifiableList( metaConstraintList );
}
public void addMetaConstraint(MetaConstraint<?, ? extends Annotation> metaConstraint) {
@@ -135,7 +135,7 @@
}
public List<Class<?>> getDefaultGroupSequence() {
- return defaultGroupSequence;
+ return Collections.unmodifiableList( defaultGroupSequence );
}
public void setDefaultGroupSequence(List<Class<?>> groupSequence) {
@@ -325,14 +325,10 @@
Class<?>[] groups = ReflectionHelper.getAnnotationParameter( annotation, "groups", Class[].class );
ConstraintDescriptorImpl constraintDescriptor;
if ( clazz.isInterface() ) {
- constraintDescriptor = new ConstraintDescriptorImpl(
- annotation, groups, constraintHelper, clazz
- );
+ constraintDescriptor = new ConstraintDescriptorImpl( annotation, constraintHelper, clazz );
}
else {
- constraintDescriptor = new ConstraintDescriptorImpl(
- annotation, groups, constraintHelper
- );
+ constraintDescriptor = new ConstraintDescriptorImpl( annotation, constraintHelper );
}
return constraintDescriptor;
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-06-05 14:17:58 UTC (rev 16709)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-06-05 14:18:41 UTC (rev 16710)
@@ -39,6 +39,7 @@
import org.slf4j.Logger;
import org.hibernate.validation.util.LoggerFactory;
+import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -50,7 +51,6 @@
*/
public class ConstraintDescriptorImpl<T extends Annotation> implements ConstraintDescriptor<T> {
private static final Logger log = LoggerFactory.make();
- private static final Class<?>[] DEFAULT_GROUP = new Class<?>[] { Default.class };
private static final int OVERRIDES_PARAMETER_DEFAULT_INDEX = -1;
/**
@@ -67,7 +67,7 @@
/**
* The groups for which to apply this constraint.
*/
- private final Set<Class<?>> groups;
+ private final Set<Class<?>> groups = new HashSet<Class<?>>();
/**
* The constraint parameters as map. The key is the paramter name and the value the
@@ -90,22 +90,14 @@
*/
private final ConstraintHelper constraintHelper;
- public ConstraintDescriptorImpl(T annotation, Class<?>[] groups, ConstraintHelper constraintHelper, Class<?> implicitGroup) {
- this( annotation, groups, constraintHelper );
+ public ConstraintDescriptorImpl(T annotation, ConstraintHelper constraintHelper, Class<?> implicitGroup) {
+ this( annotation, constraintHelper );
this.groups.add( implicitGroup );
}
- public ConstraintDescriptorImpl(T annotation, Class<?>[] groups, ConstraintHelper constraintHelper) {
- this( annotation, new HashSet<Class<?>>(), constraintHelper );
- if ( groups.length == 0 ) {
- groups = DEFAULT_GROUP;
- }
- this.groups.addAll( Arrays.asList( groups ) );
- }
- private ConstraintDescriptorImpl(T annotation, Set<Class<?>> groups, ConstraintHelper constraintHelper) {
+ public ConstraintDescriptorImpl(T annotation, ConstraintHelper constraintHelper) {
this.annotation = annotation;
- this.groups = groups;
this.attributes = getAnnotationParameters( annotation );
this.constraintHelper = constraintHelper;
@@ -113,6 +105,16 @@
ReportAsSingleViolation.class
);
+ Class<?>[] groupsFromAnnotation = ReflectionHelper.getAnnotationParameter(
+ annotation, "groups", Class[].class
+ );
+ if ( groupsFromAnnotation.length == 0 ) {
+ groups.add( Default.class );
+ }
+ else {
+ this.groups.addAll( Arrays.asList( groupsFromAnnotation ) );
+ }
+
findConstraintValidatorClasses();
Map<ClassIndexWrapper, Map<String, Object>> overrideParameters = parseOverrideParameters();
parseComposingConstraints( overrideParameters );
@@ -288,9 +290,12 @@
}
private <U extends Annotation> ConstraintDescriptorImpl<U> createComposingConstraintDescriptor(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters, int index, U constraintAnnotation, Class<U> annotationType) {
+ // use a annotation proxy
AnnotationDescriptor<U> annotationDescriptor = new AnnotationDescriptor<U>(
annotationType, getAnnotationParameters( constraintAnnotation )
);
+
+ // get the right override parameters
Map<String, Object> overrides = overrideParameters.get(
new ClassIndexWrapper(
annotationType, index
@@ -301,9 +306,13 @@
annotationDescriptor.setValue( entry.getKey(), entry.getValue() );
}
}
+
+ // groups get inherited from the parent
+ annotationDescriptor.setValue( "groups", groups.toArray( new Class<?>[] { } ) );
+
U annotationProxy = AnnotationFactory.create( annotationDescriptor );
return new ConstraintDescriptorImpl<U>(
- annotationProxy, groups, constraintHelper
+ annotationProxy, constraintHelper
);
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/XmlMappingParser.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/XmlMappingParser.java 2009-06-05 14:17:58 UTC (rev 16709)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/xml/XmlMappingParser.java 2009-06-05 14:18:41 UTC (rev 16710)
@@ -361,7 +361,7 @@
A annotation = AnnotationFactory.create( annotationDescriptor );
ConstraintDescriptorImpl<A> constraintDescriptor = new ConstraintDescriptorImpl<A>(
- annotation, new Class[] { }, constraintHelper
+ annotation, constraintHelper
);
MetaConstraint<T, A> metaConstraint;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java 2009-06-05 14:17:58 UTC (rev 16709)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java 2009-06-05 14:18:41 UTC (rev 16710)
@@ -55,13 +55,13 @@
AnnotationDescriptor<NotNull> descriptor = new AnnotationDescriptor<NotNull>( NotNull.class );
notNull = AnnotationFactory.create( descriptor );
notNullDescriptor = new ConstraintDescriptorImpl<NotNull>(
- notNull, new Class<?>[] { }, new ConstraintHelper()
+ notNull, new ConstraintHelper()
);
AnnotationDescriptor<Size> sizeAnnotationDescriptor = new AnnotationDescriptor<Size>( Size.class );
size = AnnotationFactory.create( sizeAnnotationDescriptor );
sizeDescriptor = new ConstraintDescriptorImpl<Size>(
- size, new Class<?>[] { }, new ConstraintHelper()
+ size, new ConstraintHelper()
);
}
@@ -167,7 +167,7 @@
ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(
- max, new Class<?>[] { }, new ConstraintHelper()
+ max, new ConstraintHelper()
);
interpolator = new ResourceBundleMessageInterpolator( new TestResourceBundle() );
15 years, 6 months
Hibernate SVN: r16709 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/util and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-05 10:17:58 -0400 (Fri, 05 Jun 2009)
New Revision: 16709
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/NotEmpty.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.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:
constraint composition tests
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-05 14:05:44 UTC (rev 16708)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-06-05 14:17:58 UTC (rev 16709)
@@ -17,18 +17,30 @@
*/
package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import javax.validation.groups.Default;
+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.assertTrue;
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.assertCorrectConstraintType;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintTypes;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
/**
@@ -41,26 +53,54 @@
public class ConstraintCompositionTest extends AbstractTest {
@Test
- public void testComposition() {
+ @SpecAssertion(section = "2.3", id = "a")
+ public void testComposedConstraintsAreRecursive() {
Validator validator = TestUtil.getDefaultValidator();
- FrenchAddress address = new FrenchAddress();
- address.setAddressline1( "10 rue des Treuils" );
- address.setAddressline2( "BP 12 " );
- address.setCity( "Bordeaux" );
+ FrenchAddress address = getFrenchAddressWithoutZipCode();
Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
assertCorrectNumberOfViolations( constraintViolations, 1 );
+ ConstraintViolation<FrenchAddress> constraintViolation = constraintViolations.iterator().next();
+ assertCorrectConstraintType( constraintViolation, NotNull.class );
+ assertEquals( constraintViolation.getMessage(), "may not be null", "Wrong error message" );
assertConstraintViolation(
- constraintViolations.iterator().next(),
+ constraintViolation,
FrenchAddress.class,
null,
"zipCode"
);
+ }
+ @Test
+ @SpecAssertion(section = "2.3", id = "b")
+ public void testValidationOfMainAnnotationIsAlsoApplied() {
+ Validator validator = TestUtil.getDefaultValidator();
+ FrenchAddress address = getFrenchAddressWithoutZipCode();
+ address.setZipCode( "00000" );
+ Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes(
+ constraintViolations, new Class<?>[] { FrenchZipcode.class }
+ );
+ ConstraintViolation<FrenchAddress> constraintViolation = constraintViolations.iterator().next();
+ assertEquals( constraintViolation.getMessage(), "00000 is a reserved code", "Wrong error message" );
+ }
+
+ @Test
+ @SpecAssertion(section = "2.3", id = "c")
+ public void testEachFailingConstraintCreatesConstraintViolation() {
+
+ Validator validator = TestUtil.getDefaultValidator();
+
+ FrenchAddress address = getFrenchAddressWithoutZipCode();
+
address.setZipCode( "abc" );
- constraintViolations = validator.validate( address );
+ Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
assertCorrectNumberOfViolations( constraintViolations, 3 );
+ assertCorrectConstraintTypes(
+ constraintViolations, new Class<?>[] { Pattern.class, Pattern.class, Size.class }
+ );
for ( ConstraintViolation<FrenchAddress> violation : constraintViolations ) {
assertConstraintViolation(
violation,
@@ -68,13 +108,14 @@
"abc",
"zipCode"
);
-
}
-
address.setZipCode( "123" );
constraintViolations = validator.validate( address );
assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintTypes(
+ constraintViolations, new Class<?>[] { Pattern.class, Size.class }
+ );
for ( ConstraintViolation<FrenchAddress> violation : constraintViolations ) {
assertConstraintViolation(
violation,
@@ -91,6 +132,29 @@
}
@Test
+ @SpecAssertions({
+ @SpecAssertion(section = "2.3", id = "d"),
+ @SpecAssertion(section = "2.3", id = "e")
+ })
+ public void testGroupsDefinedOnMainAnnotationAreInherited() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ FrenchAddress address = getFrenchAddressWithoutZipCode();
+ Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ ConstraintViolation<FrenchAddress> constraintViolation = constraintViolations.iterator().next();
+ assertCorrectConstraintType( constraintViolation, NotNull.class );
+ NotNull notNull = ( NotNull ) constraintViolation.getConstraintDescriptor().getAnnotation();
+ List<Class<?>> groups = Arrays.asList( notNull.groups() );
+ assertTrue( groups.size() == 2, "There should be two groups" );
+ assertTrue( groups.contains( Default.class ), "The default group should be in the list." );
+ assertTrue(
+ groups.contains( FrenchAddress.FullAddressCheck.class ),
+ "The FrenchAddress.FullAddressCheck group should be inherited."
+ );
+ }
+
+ @Test
public void testNestedComposition() {
Validator validator = TestUtil.getDefaultValidator();
@@ -127,4 +191,12 @@
"zipCode"
);
}
+
+ private FrenchAddress getFrenchAddressWithoutZipCode() {
+ FrenchAddress address = new FrenchAddress();
+ address.setAddressline1( "10 rue des Treuils" );
+ address.setAddressline2( "BP 12 " );
+ address.setCity( "Bordeaux" );
+ return address;
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java 2009-06-05 14:05:44 UTC (rev 16708)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchAddress.java 2009-06-05 14:17:58 UTC (rev 16709)
@@ -17,13 +17,18 @@
*/
package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+import javax.validation.groups.Default;
+
/**
* @author Hardy Ferentschik
*/
public class FrenchAddress extends Address {
- @FrenchZipcode
+ @FrenchZipcode(groups = { Default.class, FullAddressCheck.class })
public String getZipCode() {
return super.getZipCode();
}
+
+ public interface FullAddressCheck {
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java 2009-06-05 14:05:44 UTC (rev 16708)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcode.java 2009-06-05 14:17:58 UTC (rev 16709)
@@ -34,7 +34,7 @@
/**
* @author Hardy Ferentschik
*/
-@NotNull
+@NotEmpty
@Size
// first pattern just duplicates the length of 5 characters, the second pattern is just to proof that parameters can be overridden.
@Pattern.List({ @Pattern(regexp = "....."), @Pattern(regexp = "bar") })
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java 2009-06-05 14:05:44 UTC (rev 16708)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/FrenchZipcodeConstraintValidator.java 2009-06-05 14:17:58 UTC (rev 16709)
@@ -28,7 +28,17 @@
public void initialize(FrenchZipcode parameters) {
}
- public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
- return true;
+ public boolean isValid(String zip, ConstraintValidatorContext constraintValidatorContext) {
+ if ( zip == null ) {
+ return true;
+ }
+ if ( "00000".equals( zip ) ) {
+ constraintValidatorContext.disableDefaultError();
+ constraintValidatorContext.addError( "00000 is a reserved code" );
+ return false;
+ }
+ else {
+ return true;
+ }
}
}
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/NotEmpty.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/NotEmpty.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/NotEmpty.java 2009-06-05 14:17:58 UTC (rev 16709)
@@ -0,0 +1,60 @@
+// $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.constraints.constraintcomposition;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Documented
+@NotNull(message = "may not be null", groups = NotEmpty.DummyGroup.class)
+@Size(min = 1)
+@Constraint(validatedBy = NotEmpty.NotEmptyValidator.class)
+@Target({ TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface NotEmpty {
+ String message() default "{constraint.notEmpty}";
+
+ Class<?>[] groups() default { };
+
+ public class NotEmptyValidator implements ConstraintValidator<NotEmpty, String> {
+
+ public void initialize(NotEmpty parameters) {
+ }
+
+ public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
+ return true;
+ }
+ }
+
+ public interface DummyGroup {
+
+ }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/NotEmpty.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
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-05 14:05:44 UTC (rev 16708)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-06-05 14:17:58 UTC (rev 16709)
@@ -39,10 +39,34 @@
return Validation.buildDefaultValidatorFactory().getValidator();
}
+ public static <T> void assertCorrectConstraintType(ConstraintViolation<T> violation, Class<?> expectedConstraintType) {
+ assertEquals(
+ violation.getConstraintDescriptor().getAnnotation().annotationType().getName(),
+ expectedConstraintType.getName(),
+ "Wrong constraint type"
+ );
+ }
+
public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations, int expectedViolations) {
assertEquals( violations.size(), expectedViolations, "Wrong number of constraint violations" );
}
+ public static <T> void assertCorrectConstraintTypes(Set<ConstraintViolation<T>> violations, Class<?>[] expectedConsraintTypes) {
+ List<String> constraintTypes = new ArrayList<String>();
+ for ( ConstraintViolation<?> violation : violations ) {
+ constraintTypes.add( violation.getConstraintDescriptor().getAnnotation().annotationType().getName() );
+ }
+
+ assertEquals( expectedConsraintTypes.length, constraintTypes.size(), "Wring number of constraint types." );
+
+ for ( Class<?> expectedConstraintType : expectedConsraintTypes ) {
+ assertTrue(
+ constraintTypes.contains(expectedConstraintType.getName()),
+ "The constraint type " + expectedConstraintType.getName() + " should have been violated."
+ );
+ }
+ }
+
public static <T> void assertInvalidPropertyPaths(Set<ConstraintViolation<T>> violations, String[] propertyPaths) {
List<String> propertyPathsOfViolations = new ArrayList<String>();
for ( ConstraintViolation<?> violation : violations ) {
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-05 14:05:44 UTC (rev 16708)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-05 14:17:58 UTC (rev 16709)
@@ -88,7 +88,7 @@
annotations</text>
</assertion>
<assertion id="e">
- <text>Any groups definition on a composing an- notation is ignored</text>
+ <text>Any groups definition on a composing annotation is ignored</text>
</assertion>
<assertion id="f">
<text>The property type a composed constraint is placed on must be compatible with all
15 years, 6 months
Hibernate SVN: r16708 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/id/enhanced.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-05 10:05:44 -0400 (Fri, 05 Jun 2009)
New Revision: 16708
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
Log:
HHH-3880 - org.hibernate.id.enhanced.TableStructure missing "as" keyword in select statment column renames; required for PostgreSQL
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2009-06-05 14:05:24 UTC (rev 16707)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2009-06-05 14:05:44 UTC (rev 16708)
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.id.enhanced;
@@ -68,7 +67,7 @@
this.incrementSize = incrementSize;
this.valueColumnName = valueColumnName;
- selectQuery = "select " + valueColumnName + " id_val" +
+ selectQuery = "select " + valueColumnName + " as id_val" +
" from " + dialect.appendLockHint( LockMode.UPGRADE, tableName ) +
dialect.getForUpdateString();
15 years, 6 months
Hibernate SVN: r16707 - core/branches/Branch_3_2/src/org/hibernate/id/enhanced.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-05 10:05:24 -0400 (Fri, 05 Jun 2009)
New Revision: 16707
Modified:
core/branches/Branch_3_2/src/org/hibernate/id/enhanced/TableStructure.java
Log:
HHH-3880 - org.hibernate.id.enhanced.TableStructure missing "as" keyword in select statment column renames; required for PostgreSQL
Modified: core/branches/Branch_3_2/src/org/hibernate/id/enhanced/TableStructure.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/id/enhanced/TableStructure.java 2009-06-05 14:04:57 UTC (rev 16706)
+++ core/branches/Branch_3_2/src/org/hibernate/id/enhanced/TableStructure.java 2009-06-05 14:05:24 UTC (rev 16707)
@@ -42,7 +42,7 @@
this.incrementSize = incrementSize;
this.valueColumnName = valueColumnName;
- selectQuery = "select " + valueColumnName + " id_val" +
+ selectQuery = "select " + valueColumnName + " as id_val" +
" from " + dialect.appendLockHint( LockMode.UPGRADE, tableName ) +
dialect.getForUpdateString();
15 years, 6 months
Hibernate SVN: r16706 - core/trunk/core/src/main/java/org/hibernate/id/enhanced.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-05 10:04:57 -0400 (Fri, 05 Jun 2009)
New Revision: 16706
Modified:
core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
Log:
HHH-3880 - org.hibernate.id.enhanced.TableStructure missing "as" keyword in select statment column renames; required for PostgreSQL
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2009-06-05 13:53:08 UTC (rev 16705)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2009-06-05 14:04:57 UTC (rev 16706)
@@ -68,7 +68,7 @@
this.incrementSize = incrementSize;
this.valueColumnName = valueColumnName;
- selectQuery = "select " + valueColumnName + " id_val" +
+ selectQuery = "select " + valueColumnName + " as id_val" +
" from " + dialect.appendLockHint( LockMode.UPGRADE, tableName ) +
dialect.getForUpdateString();
15 years, 6 months
Hibernate SVN: r16705 - core/branches/Branch_3_2.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-05 09:53:08 -0400 (Fri, 05 Jun 2009)
New Revision: 16705
Modified:
core/branches/Branch_3_2/build.xml
Log:
added source attribute to the javacdoc task
Modified: core/branches/Branch_3_2/build.xml
===================================================================
--- core/branches/Branch_3_2/build.xml 2009-06-05 13:51:04 UTC (rev 16704)
+++ core/branches/Branch_3_2/build.xml 2009-06-05 13:53:08 UTC (rev 16705)
@@ -700,6 +700,7 @@
<target name="javadoc" description="Compile the Javadoc API documentation to dist dir" depends="splash,antlr">
<mkdir dir="${dir.out.doc}/api"/>
<javadoc classpathref="path.lib"
+ source="${javac.source}"
destdir="${dir.out.doc}/api"
use="true"
protected="true"
15 years, 6 months